Completed
Pull Request — master (#112)
by Christophe
02:50
created

PathsFilter::isFeatureMatch()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 4

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 14
ccs 8
cts 8
cp 1
rs 9.2
cc 4
eloc 7
nc 4
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 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 1
    public function __construct(array $paths)
31
    {
32 1
        $this->filterPaths = array_map('realpath', $paths);
33 1
    }
34
35
    /**
36
     * Checks if Feature matches specified filter.
37
     *
38
     * @param FeatureNode $feature Feature instance
39
     *
40
     * @return Boolean
41
     */
42 1
    public function isFeatureMatch(FeatureNode $feature)
43
    {
44 1
        foreach ($this->filterPaths as $path) {
45 1
            if (!$path) {
46 1
                continue;
47
            }
48
49 1
            if (0 === strpos($feature->getFile(), $path)) {
50 1
                return true;
51
            }
52 1
        }
53
54 1
        return false;
55
    }
56
57
    /**
58
     * Checks if scenario or outline matches specified filter.
59
     *
60
     * @param ScenarioInterface $scenario Scenario or Outline node instance
61
     *
62
     * @return false This filter is designed to work only with features
63
     */
64
    public function isScenarioMatch(ScenarioInterface $scenario)
65
    {
66
        return false;
67
    }
68
}
69