Completed
Push — refactor ( 0ce6e5 )
by Marco
01:39
created

Methods   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 0
dl 0
loc 33
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 3
A toArray() 0 4 1
1
<?php
2
3
namespace MJanssen\Route;
4
5
use InvalidArgumentException;
6
7
class Methods
8
{
9
    const ALLOWED_METHODS = ['GET', 'PUT', 'POST', 'DELETE', 'OPTIONS', 'HEAD', 'PATCH', 'PURGE', 'OPTIONS', 'TRACE', 'CONNECT'];
10
11
    /**
12
     * @var array
13
     */
14
    private $methods = [];
15
16
    /**
17
     * @param array $methods
18
     */
19
    public function __construct(array $methods)
20
    {
21
        $methods = array_map('strtoupper', $methods);
22
23
        foreach ($methods as $method) {
24
            if (!in_array($method, self::ALLOWED_METHODS)) {
25
                throw new InvalidArgumentException('Method "' . $method . '" is not valid, only the following methods are allowed: ' . join(', ', self::ALLOWED_METHODS));
26
            }
27
        }
28
29
        $this->methods = $methods;
30
    }
31
32
    /**
33
     * @return array
34
     */
35
    public function toArray()
36
    {
37
        return $this->methods;
38
    }
39
}