Completed
Push — scrutinizer-quality ( c3b7e2 )
by Erin
02:15
created

AbstractMatcher::setAssertion()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Peridot\Leo\Matcher;
4
5
/**
6
 * AbstractMatcher serves as the base for most Matchers.
7
 *
8
 * @package Peridot\Leo\Matcher
9
 */
10
abstract class AbstractMatcher implements MatcherInterface
11
{
12
    use MatcherTrait;
13
14
    /**
15
     * @param mixed $expected
16
     */
17
    public function __construct($expected)
18
    {
19
        $this->expected = $expected;
20
    }
21
22
    /**
23
     * {@inheritdoc}
24
     *
25
     * @param  mixed $actual
26
     * @return Match
27
     */
28
    public function match($actual = '')
29
    {
30
        $isMatch = $this->doMatch($actual);
31
        $isNegated = $this->isNegated();
32
33
        return new Match($isMatch xor $isNegated, $this->expected, $actual, $isNegated);
34
    }
35
36
    /**
37
     * The actual matching algorithm for the matcher. This is called by ->match()
38
     * to create a Match result.
39
     *
40
     * @param  mixed $actual
41
     * @return bool
42
     */
43
    abstract protected function doMatch($actual);
44
45
    /**
46
     * @var mixed
47
     */
48
    protected $expected;
49
}
50