MethodNotAllowedException   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 29
c 0
b 0
f 0
wmc 3
lcom 0
cbo 0
ccs 0
cts 12
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A buildMessage() 0 10 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
}