MethodCondition   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 46.15%

Importance

Changes 0
Metric Value
eloc 13
c 0
b 0
f 0
dl 0
loc 28
ccs 6
cts 13
cp 0.4615
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A ensureIsValidMatcher() 0 4 2
A __toString() 0 8 1
1
<?php
2
/**
3
 * This file is part of Phiremock.
4
 *
5
 * Phiremock is free software: you can redistribute it and/or modify
6
 * it under the terms of the GNU Lesser General Public License as published by
7
 * the Free Software Foundation, either version 3 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * Phiremock is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with Phiremock.  If not, see <http://www.gnu.org/licenses/>.
17
 */
18
19
namespace Mcustiel\Phiremock\Domain\Condition\Conditions;
20
21
use Mcustiel\Phiremock\Domain\Condition\Condition;
22
use Mcustiel\Phiremock\Domain\Condition\Matchers\Matcher;
23
use Mcustiel\Phiremock\Domain\Condition\MatchersEnum;
24
25
class MethodCondition extends Condition
26
{
27
    private const VALID_MATCHERS = [
28
        MatchersEnum::SAME_STRING,
29
        MatchersEnum::MATCHES,
30
    ];
31
32 18
    public function __construct(Matcher $matcher)
33
    {
34 18
        $this->ensureIsValidMatcher($matcher->getName());
35 18
        parent::__construct($matcher);
36 18
    }
37
38
    public function __toString()
39
    {
40
        $value = $this->getValue()->asString();
41
42
        return sprintf(
43
            '%s => BINARY CONTENTS (%s bytes)',
44
            $this->getMatcher()->getName(),
45
            \strlen($value)
46
        );
47
    }
48
49 18
    private function ensureIsValidMatcher(string $matcherName): void
50
    {
51 18
        if (!\in_array($matcherName, self::VALID_MATCHERS, true)) {
52
            throw new \InvalidArgumentException(sprintf('%s is not an allowed condition matcher for http methods.', $matcherName));
53
        }
54 18
    }
55
}
56