Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
FileSizeExceededException
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 forSize
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5/** @license For full copyright and license information, please see the LICENSE.md file. */
6
7namespace App\Modules\Documents\Domain\Exception;
8
9defined('AMMONLY_APP') || exit('Direct script access is forbidden.');
10
11use InvalidArgumentException;
12
13/**
14 * Exception thrown when an uploaded file exceeds the configured maximum file size.
15 *
16 * @package App\Modules\Documents\Domain\Exception
17 */
18final class FileSizeExceededException extends InvalidArgumentException
19{
20    /**
21     * Creates exception for an oversized file.
22     *
23     * @param int $fileSizeBytes Actual file size in bytes.
24     * @param int $maxSizeMb     Configured maximum file size in megabytes.
25     * @return self New instance.
26     */
27    public static function forSize(int $fileSizeBytes, int $maxSizeMb): self
28    {
29        $fileSizeMb = round($fileSizeBytes / 1048576, 2);
30
31        return new self("File size ({$fileSizeMb} MB) exceeds maximum allowed size ({$maxSizeMb} MB).");
32    }
33}