Completed
Push — master ( f7da4c...5d8de1 )
by Veaceslav
12:21 queued 10:22
created

MethodsAllowedConstraint::toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 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