RoleFilter   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 77.78%

Importance

Changes 0
Metric Value
wmc 3
c 0
b 0
f 0
lcom 1
cbo 2
dl 0
loc 43
ccs 7
cts 9
cp 0.7778
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A isFeatureMatch() 0 4 1
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 actors role.
18
 *
19
 * @author Konstantin Kudryashov <[email protected]>
20
 */
21
class RoleFilter extends SimpleFilter
22
{
23
    protected $pattern;
24
25
    /**
26
     * Initializes filter.
27
     *
28
     * @param string $role Approved role wildcard
29
     */
30 2
    public function __construct($role)
31
    {
32 2
        $this->pattern = '/as an? ' . strtr(preg_quote($role, '/'), array(
33 2
            '\*' => '.*',
34
            '\?' => '.',
35
            '\[' => '[',
36
            '\]' => ']'
37 2
        )) . '[$\n]/i';
38 2
    }
39
40
    /**
41
     * Checks if Feature matches specified filter.
42
     *
43
     * @param FeatureNode $feature Feature instance
44
     *
45
     * @return Boolean
46
     */
47 2
    public function isFeatureMatch(FeatureNode $feature)
48
    {
49 2
        return 1 === preg_match($this->pattern, $feature->getDescription());
50
    }
51
52
    /**
53
     * Checks if scenario or outline matches specified filter.
54
     *
55
     * @param ScenarioInterface $scenario Scenario or Outline node instance
56
     *
57
     * @return false This filter is designed to work only with features
58
     */
59
    public function isScenarioMatch(ScenarioInterface $scenario)
60
    {
61
        return false;
62
    }
63
}
64