MethodNotAllowedException   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 37
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getAllow() 0 3 1
A jsonSerialize() 0 6 1
1
<?php
2
/**
3
 * @author Todd Burry <[email protected]>
4
 * @copyright 2009-2014 Vanilla Forums Inc.
5
 * @license MIT
6
 */
7
8
namespace Garden\Exception;
9
10
/**
11
 * An exception that represents a 405 method not allowed exception.
12
 */
13
class MethodNotAllowedException extends ClientException {
14
15
    /**
16
     * Initialize the {@link MethodNotAllowedException}.
17
     *
18
     * @param string $method The http method that's not allowed.
19
     * @param array|string $allow An array http methods that are allowed.
20
     */
21 7
    public function __construct($method, $allow = []) {
22 7
        $allow = (array)$allow;
23 7
        $message = sprintf('%s not allowed.', strtoupper($method));
24 7
        parent::__construct($message, 405, ['HTTP_ALLOW' => strtoupper(implode(', ', $allow))]);
25 7
    }
26
27
    /**
28
     * Get the allowed http methods.
29
     *
30
     * @return array Returns an array of allowed methods.
31
     */
32 7
    public function getAllow() {
33 7
        return array_map('trim', explode(',', $this->context['HTTP_ALLOW']));
34
    }
35
36
    /**
37
     * Specify data which should be serialized to JSON.
38
     *
39
     * @link http://php.net/manual/en/jsonserializable.jsonserialize.php
40
     * @return mixed data which can be serialized by <b>json_encode</b>,
41
     * which is a value of any type other than a resource.
42
     */
43 7
    public function jsonSerialize() {
44 7
        $result = parent::jsonSerialize();
45 7
        $result['allow'] = $this->getAllow();
46
        
47 7
        return $result;
48
    }
49
}
50