Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
5 / 5 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
| CommentAttachmentException | |
100.00% |
4 / 4 |
|
100.00% |
4 / 4 |
4 | |
100.00% |
1 / 1 |
| forDisallowedExtension | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| forExceededSize | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| forStorageFailure | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| forNotFound | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | /** @license For full copyright and license information, please see the LICENSE.md file. */ |
| 6 | |
| 7 | namespace App\Modules\Comments\Domain\Exception; |
| 8 | |
| 9 | defined('AMMONLY_APP') || exit('Direct script access is forbidden.'); |
| 10 | |
| 11 | use DomainException; |
| 12 | |
| 13 | /** |
| 14 | * Exception thrown when file attachment validation or storage fails. |
| 15 | * |
| 16 | * @package App\Modules\Comments\Domain\Exception |
| 17 | */ |
| 18 | final class CommentAttachmentException extends DomainException |
| 19 | { |
| 20 | public static function forDisallowedExtension(string $ext): self |
| 21 | { |
| 22 | return new self(sprintf('File extension "%s" is not permitted for security reasons.', $ext)); |
| 23 | } |
| 24 | |
| 25 | public static function forExceededSize(int $size, int $maxMb): self |
| 26 | { |
| 27 | return new self(sprintf('File size (%d bytes) exceeds maximum permitted size of %d MB.', $size, $maxMb)); |
| 28 | } |
| 29 | |
| 30 | public static function forStorageFailure(string $reason): self |
| 31 | { |
| 32 | return new self(sprintf('Failed to securely store attachment: %s', $reason)); |
| 33 | } |
| 34 | |
| 35 | public static function forNotFound(string $tokenOrId): self |
| 36 | { |
| 37 | return new self(sprintf('Attachment "%s" was not found.', $tokenOrId)); |
| 38 | } |
| 39 | } |