PathsFilter   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 86.67%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 0
loc 52
ccs 13
cts 15
cp 0.8667
rs 10
c 0
b 0
f 0

3 Methods

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