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

PatternMatcher   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
c 1
b 0
f 1
lcom 1
cbo 2
dl 0
loc 30
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A doMatch() 0 8 2
A getDefaultTemplate() 0 7 1
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