Completed
Pull Request — master (#23)
by Erin
03:28
created

PatternMatcher::getDefaultTemplate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 7
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
namespace Peridot\Leo\Matcher;
3
4
use Peridot\Leo\Matcher\Template\ArrayTemplate;
5
use Peridot\Leo\Matcher\Template\TemplateInterface;
6
7
/**
8
 * PatternMatcher determines if an actual string value matches a regular expression.
9
 *
10
 * @package Peridot\Leo\Matcher
11
 */
12
class PatternMatcher extends AbstractMatcher
13
{
14
    /**
15
     * Match the actual value against a regular expression
16
     *
17
     * @param $actual
18
     * @return mixed
19
     */
20
    protected function doMatch($actual)
21
    {
22
        if (!is_string($actual)) {
23
            throw new \InvalidArgumentException("PatternMatcher expects a string");
24
        }
25
26
        return (bool) preg_match($this->expected, $actual);
27
    }
28
29
    /**
30
     * {@inheritdoc}
31
     *
32
     * @return TemplateInterface
33
     */
34
    public function getDefaultTemplate()
35
    {
36
        return new ArrayTemplate([
37
            'default' => 'Expected {{actual}} to match {{expected}}',
38
            'negated' => 'Expected {{actual}} not to match {{expected}}'
39
        ]);
40
    }
41
}
42