MethodNotAllowedException   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 6
c 3
b 0
f 0
dl 0
loc 24
ccs 6
cts 6
cp 1
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getAllowedMethods() 0 3 1
A __construct() 0 6 1
1
<?php declare(strict_types=1);
2
3
/*
4
 * This file is part of Flight Routing.
5
 *
6
 * PHP version 8.0 and above required
7
 *
8
 * @author    Divine Niiquaye Ibok <[email protected]>
9
 * @copyright 2019 Divine Niiquaye Ibok (https://divinenii.com/)
10
 * @license   https://opensource.org/licenses/BSD-3-Clause License
11
 *
12
 * For the full copyright and license information, please view the LICENSE
13
 * file that was distributed with this source code.
14
 */
15
16
namespace Flight\Routing\Exceptions;
17
18
use Flight\Routing\Interfaces\ExceptionInterface;
19
20
/**
21
 * HTTP 405 exception.
22
 */
23
class MethodNotAllowedException extends \RuntimeException implements ExceptionInterface
24
{
25
    /** @var array<int,string> */
26
    private array $methods;
27
28
    /**
29
     * @param array<int,string> $methods
30
     */
31 7
    public function __construct(array $methods, string $path, string $method)
32
    {
33 7
        $this->methods = \array_map('strtoupper', $methods);
34 7
        $message = 'Route with "%s" path requires request method(s) [%s], "%s" is invalid.';
35
36 7
        parent::__construct(\sprintf($message, $path, \implode(',', $methods), $method), 405);
37
    }
38
39
    /**
40
     * Gets allowed methods.
41
     *
42
     * @return array<int,string>
43
     */
44 1
    public function getAllowedMethods(): array
45
    {
46 1
        return $this->methods;
47
    }
48
}
49