MethodsAllowedConstraint   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 23
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A toString() 0 4 1
A matches() 0 8 2
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