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

StringPrepMatchingRule   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
eloc 6
dl 0
loc 27
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A compare() 0 5 1
A __construct() 0 3 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