PatternMatcher::getDefaultTemplate()   A
last analyzed

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