MethodNotAllowedException::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 0
cts 4
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 2
crap 2
1
<?php declare(strict_types = 1);
2
3
namespace Venta\Routing\Exception;
4
5
use RuntimeException;
6
7
/**
8
 * Class MethodNotAllowedException
9
 *
10
 * @package Venta\Routing\Exception
11
 */
12
class MethodNotAllowedException extends RuntimeException
13
{
14
    /**
15
     * {@inheritdoc}
16
     *
17
     * @param array $allowedMethods
18
     */
19
    public function __construct(array $allowedMethods, \Exception $previous = null)
20
    {
21
        parent::__construct($this->buildMessage($allowedMethods), 0, $previous);
22
    }
23
24
    /**
25
     * Builds error message
26
     *
27
     * @param  array $allowedMethods
28
     * @return string
29
     */
30
    protected function buildMessage(array $allowedMethods): string
31
    {
32
        $ending = 'Allowed method is: %s';
33
34
        if (count($allowedMethods) > 1) {
35
            $ending = 'Allowed methods are: %s';
36
        }
37
38
        return sprintf('Method is not allowed. ' . $ending, implode(', ', $allowedMethods));
39
    }
40
}