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

PathsFilter   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 84.62%

Importance

Changes 4
Bugs 0 Features 1
Metric Value
c 4
b 0
f 1
dl 0
loc 48
wmc 6
lcom 1
cbo 2
ccs 11
cts 13
cp 0.8462
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A isFeatureMatch() 0 14 4
A isScenarioMatch() 0 4 1
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