SubStringMatcher   A
last analyzed

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
dl 0
loc 30
rs 10
c 1
b 0
f 1
wmc 3
lcom 1
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A doMatch() 0 8 2
A getDefaultTemplate() 0 7 1
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
 * SubStringMatcher determines if an actual string contains the expected sub string.
10
 *
11
 * @package Peridot\Leo\Matcher
12
 */
13
class SubStringMatcher extends AbstractMatcher
14
{
15
    /**
16
     * Match that actual value has the expected sub string.
17
     *
18
     * @param  string $actual
19
     * @return mixed
20
     */
21
    protected function doMatch($actual)
22
    {
23
        if (!is_string($actual)) {
24
            throw new \InvalidArgumentException('SubStringMatcher requires string value');
25
        }
26
27
        return strpos($actual, $this->expected) !== false;
28
    }
29
30
    /**
31
     * {@inheritdoc}
32
     *
33
     * @return TemplateInterface
34
     */
35
    public function getDefaultTemplate()
36
    {
37
        return new ArrayTemplate([
38
            'default' => 'Expected {{actual}} to contain {{expected}}',
39
            'negated' => 'Expected {{actual}} to not contain {{expected}}',
40
        ]);
41
    }
42
}
43