MethodNotAllowedException::buildMessage()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 10
c 0
b 0
f 0
ccs 0
cts 8
cp 0
rs 9.4285
cc 2
eloc 5
nc 2
nop 1
crap 6
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
}