PathsFilter::isFeatureMatch()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 5
cts 5
cp 1
rs 9.9332
c 0
b 0
f 0
cc 3
nc 3
nop 1
crap 3
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 features by their paths.
18
 *
19
 * @author Konstantin Kudryashov <[email protected]>
20
 */
21
class PathsFilter extends SimpleFilter
22
{
23
    protected $filterPaths = array();
24
25
    /**
26
     * Initializes filter.
27
     *
28
     * @param string[] $paths List of approved paths
29
     */
30 3
    public function __construct(array $paths)
31
    {
32 3
        $this->filterPaths = array_map(
33
            function ($realpath) {
34 3
                return rtrim($realpath, DIRECTORY_SEPARATOR) .
35 3
                    (is_dir($realpath) ? DIRECTORY_SEPARATOR : '');
36 3
            },
37 3
            array_filter(
38 3
                array_map('realpath', $paths)
39
            )
40
        );
41 3
    }
42
43
    /**
44
     * Checks if Feature matches specified filter.
45
     *
46
     * @param FeatureNode $feature Feature instance
47
     *
48
     * @return Boolean
49
     */
50 3
    public function isFeatureMatch(FeatureNode $feature)
51
    {
52 3
        foreach ($this->filterPaths as $path) {
53 3
            if (0 === strpos(realpath($feature->getFile()), $path)) {
54 2
                return true;
55
            }
56
        }
57
58 3
        return false;
59
    }
60
61
    /**
62
     * Checks if scenario or outline matches specified filter.
63
     *
64
     * @param ScenarioInterface $scenario Scenario or Outline node instance
65
     *
66
     * @return false This filter is designed to work only with features
67
     */
68
    public function isScenarioMatch(ScenarioInterface $scenario)
69
    {
70
        return false;
71
    }
72
}
73