Completed
Push — master ( f451ed...7bd00e )
by Marco
02:07
created

Method::assert()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 5
nc 3
nop 1
1
<?php
2
3
namespace MJanssen\Assert;
4
5
use InvalidArgumentException;
6
7
class Method
8
{
9
    const ALLOWED_METHODS = ['get', 'put', 'post', 'delete', 'options', 'head', 'patch', 'purge', 'options', 'trace', 'connect'];
10
11
    public static function assert(array $methods)
12
    {
13
        $methods = array_map('strtolower', $methods);
14
15
        foreach ($methods as $method) {
16
            if (!in_array($method, self::ALLOWED_METHODS)) {
17
                throw new InvalidArgumentException('Method "' . $method . '" is not valid, only the following methods are allowed: ' . join(', ', self::ALLOWED_METHODS));
18
            }
19
        }
20
    }
21
}