NameFilter::isScenarioMatch()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 6
cts 6
cp 1
rs 9.9332
c 0
b 0
f 0
cc 4
nc 3
nop 1
crap 4
1
<?php
2
3
/*
4
 * This file is part of the Behat Gherkin.
5
 * (c) Konstantin Kudryashov <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Behat\Gherkin\Filter;
12
13
use Behat\Gherkin\Node\FeatureNode;
14
use Behat\Gherkin\Node\ScenarioInterface;
15
16
/**
17
 * Filters scenarios by feature/scenario name.
18
 *
19
 * @author Konstantin Kudryashov <[email protected]>
20
 */
21
class NameFilter extends SimpleFilter
22
{
23
    protected $filterString;
24
25
    /**
26
     * Initializes filter.
27
     *
28
     * @param string $filterString Name filter string
29
     */
30 3
    public function __construct($filterString)
31
    {
32 3
        $this->filterString = trim($filterString);
33 3
    }
34
35
    /**
36
     * Checks if Feature matches specified filter.
37
     *
38
     * @param FeatureNode $feature Feature instance
39
     *
40
     * @return Boolean
41
     */
42 2
    public function isFeatureMatch(FeatureNode $feature)
43
    {
44 2
        if ('/' === $this->filterString[0]) {
45 1
            return 1 === preg_match($this->filterString, $feature->getTitle());
46
        }
47
48 2
        return false !== mb_strpos($feature->getTitle(), $this->filterString, 0, 'utf8');
49
    }
50
51
    /**
52
     * Checks if scenario or outline matches specified filter.
53
     *
54
     * @param ScenarioInterface $scenario Scenario or Outline node instance
55
     *
56
     * @return Boolean
57
     */
58 2
    public function isScenarioMatch(ScenarioInterface $scenario)
59
    {
60 2
        if ('/' === $this->filterString[0] && 1 === preg_match($this->filterString, $scenario->getTitle())) {
61 1
            return true;
62 2
        } elseif (false !== mb_strpos($scenario->getTitle(), $this->filterString, 0, 'utf8')) {
63 2
            return true;
64
        }
65
66 2
        return false;
67
    }
68
}
69