UrlCondition::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
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 UrlCondition extends Condition
26
{
27
    private const VALID_MATCHERS = [
28
        MatchersEnum::SAME_STRING,
29
        MatchersEnum::MATCHES,
30
        MatchersEnum::CONTAINS,
31
        MatchersEnum::EQUAL_TO,
32
    ];
33
34 6
    public function __construct(Matcher $matcher)
35
    {
36 6
        $this->ensureIsValidMatcher($matcher->getName());
37 6
        parent::__construct($matcher);
38 6
    }
39
40 6
    private function ensureIsValidMatcher(string $matcherName): void
41
    {
42 6
        if (!\in_array($matcherName, self::VALID_MATCHERS, true)) {
43
            throw new \InvalidArgumentException(sprintf('%s is not an allowed condition matcher for urls.', $matcherName));
44
        }
45 6
    }
46
}
47