Passed
Branch php72 (a3eac9)
by Joni
03:37
created

StringPrepMatchingRule::compare()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 1
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Sop\X501\MatchingRule;
6
7
use Sop\X501\StringPrep\StringPreparer;
8
9
/**
10
 * Base class for matching rules employing string preparement semantics.
11
 */
12
abstract class StringPrepMatchingRule extends MatchingRule
13
{
14
    /**
15
     * String preparer.
16
     *
17
     * @var StringPreparer
18
     */
19
    protected $_prep;
20
21
    /**
22
     * Constructor.
23
     *
24
     * @param StringPreparer $preparer
25
     */
26 34
    public function __construct(StringPreparer $preparer)
27
    {
28 34
        $this->_prep = $preparer;
29 34
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34 34
    public function compare($assertion, $value): ?bool
35
    {
36 34
        $assertion = $this->_prep->prepare($assertion);
37 34
        $value = $this->_prep->prepare($value);
38 34
        return 0 == strcmp($assertion, $value);
39
    }
40
}
41