FeatureWalker::getFeatures()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 8
rs 10
cc 2
nc 2
nop 0
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)
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;
45
        }
46
47
        return $this->features;
48
    }
49
}
50