Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
InvalidExtensionException
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
1 / 1
 forExtension
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
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 extension is not permitted.
15 *
16 * @package App\Modules\Documents\Domain\Exception
17 */
18final class InvalidExtensionException extends InvalidArgumentException
19{
20    /**
21     * Creates exception for an unpermitted file extension.
22     *
23     * @param string        $extension Rejected file extension.
24     * @param array<string> $allowed   List of permitted extensions.
25     * @return self New instance.
26     */
27    public static function forExtension(string $extension, array $allowed): self
28    {
29        $allowedList = implode(', ', array_slice($allowed, 0, 15));
30        if (count($allowed) > 15) {
31            $allowedList .= '...';
32        }
33
34        return new self("File extension '.{$extension}' is not allowed. Permitted: {$allowedList}");
35    }
36}