Completed
Push — master ( a3ba2f...57d762 )
by Erin
02:00
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
use Peridot\Leo\Matcher\Template\TemplateInterface;
6
7
/**
8
 * AbstractMatcher serves as the base for most Matchers.
9
 *
10
 * @package Peridot\Leo\Matcher
11
 */
12
abstract class AbstractMatcher implements MatcherInterface
13
{
14
    use MatcherTrait;
15
16
    /**
17
     * @param mixed $expected
18
     */
19
    public function __construct($expected)
20
    {
21
        $this->expected = $expected;
22
    }
23
24
    /**
25
     * {@inheritdoc}
26
     *
27
     * @param  mixed $actual
28
     * @return Match
29
     */
30
    public function match($actual = '')
31
    {
32
        $isMatch = $this->doMatch($actual);
33
        $isNegated = $this->isNegated();
34
35
        return new Match($isMatch xor $isNegated, $this->expected, $actual, $isNegated);
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     *
41
     * @return TemplateInterface
42
     */
43
    public function getTemplate()
44
    {
45
        if (!isset($this->template)) {
46
            return $this->getDefaultTemplate();
47
        }
48
49
        return $this->template;
50
    }
51
52
    /**
53
     * The actual matching algorithm for the matcher. This is called by ->match()
54
     * to create a Match result.
55
     *
56
     * @param  mixed $actual
57
     * @return bool
58
     */
59
    abstract protected function doMatch($actual);
60
61
    /**
62
     * @var mixed
63
     */
64
    protected $expected;
65
}
66