FeatureWalker::getScenarioByName()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 4
nc 3
nop 1
1
<?php
2
3
namespace Knp\FriendlyContexts\Node;
4
5
use Behat\Gherkin\Gherkin;
6
7
class FeatureWalker
8
{
9
    protected $gherkin;
10
    protected $paths;
11
    protected $loaded;
12
    protected $features = [];
13
14
    public function __construct(Gherkin $gherkin, $paths)
15
    {
16
        $this->gherkin = $gherkin;
17
        $this->paths   = $paths;
18
        $this->loaded  = false;
19
    }
20
21
    public function getScenarioByName($name)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
22
    {
23
        foreach ($this->getScenarios() as $scenario) {
24
            if ($name === $scenario->getTitle()) {
25
                return $scenario;
26
            }
27
        }
28
    }
29
30
    public function getScenarios()
31
    {
32
        $scenarios = [];
33
        foreach ($this->getFeatures() as $feature) {
34
            $scenarios = array_merge($scenarios, $feature->getScenarios());
35
        }
36
37
        return $scenarios;
38
    }
39
40
    public function getFeatures()
41
    {
42
        if (!$this->loaded) {
43
            $this->features = $this->gherkin->load($this->paths);
44
            $this->loaded = true;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
45
        }
46
47
        return $this->features;
48
    }
49
}
50