Completed
Push — master ( 1d5edb...a1155a )
by Veaceslav
04:30
created

MethodsAllowedConstraint   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
c 1
b 0
f 1
lcom 1
cbo 1
dl 0
loc 37
ccs 9
cts 9
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A matches() 0 8 2
A toString() 0 4 1
1
<?php
2
/**
3
 * This file is part of Rebilly.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 *
8
 * @see http://rebilly.com
9
 */
10
11
namespace Rebilly\OpenAPI\PhpUnit;
12
13
use PHPUnit_Framework_Constraint as Constraint;
14
15
/**
16
 * Constraint that asserts that the HTTP method matches the expected allowed methods.
17
 */
18
final class MethodsAllowedConstraint extends Constraint
19
{
20
    /**
21
     * @var array
22
     */
23
    private $allowedMethods;
24
25
    /**
26
     * @param array $allowedMethods
27
     */
28 3
    public function __construct(array $allowedMethods)
29
    {
30 3
        parent::__construct();
31
32 3
        $this->allowedMethods = array_map('strtoupper', $allowedMethods);
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38 3
    protected function matches($other)
39
    {
40 3
        if (is_string($other)) {
41 2
            return in_array(strtoupper($other), $this->allowedMethods);
42
        } else {
43 1
            return empty(array_diff($this->allowedMethods, array_map('strtoupper', $other)));
44
        }
45
    }
46
47
    /**
48
     * {@inheritdoc}
49
     */
50 1
    public function toString()
51
    {
52 1
        return 'matches an allowed methods (' . implode(', ', $this->allowedMethods) . ')';
53
    }
54
}
55