MethodsAllowedConstraint::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * This source file is proprietary and part of Rebilly.
4
 *
5
 * (c) Rebilly SRL
6
 *     Rebilly Ltd.
7
 *     Rebilly Inc.
8
 *
9
 * @see https://www.rebilly.com
10
 */
11
12
namespace Rebilly\OpenAPI\PhpUnit;
13
14
use PHPUnit\Framework\Constraint\Constraint;
15
16
/**
17
 * Constraint that asserts that the HTTP method matches the expected allowed methods.
18
 */
19
final class MethodsAllowedConstraint extends Constraint
20
{
21
    private $allowedMethods;
22
23 8
    public function __construct(array $allowedMethods)
24
    {
25 8
        $this->allowedMethods = array_map('mb_strtoupper', $allowedMethods);
26
    }
27
28 2
    public function toString(): string
29
    {
30 2
        return 'matches an allowed methods (' . implode(', ', $this->allowedMethods) . ')';
31
    }
32
33 8
    protected function matches($other): bool
34
    {
35 8
        if (is_string($other)) {
36 6
            return in_array(mb_strtoupper($other), $this->allowedMethods, true);
37
        }
38
39 2
        return empty(array_diff($this->allowedMethods, array_map('mb_strtoupper', $other)));
40
    }
41
}
42