FeatureWalker   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 8
eloc 19
c 2
b 0
f 0
dl 0
loc 41
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getScenarios() 0 8 2
A getScenarioByName() 0 5 3
A __construct() 0 5 1
A getFeatures() 0 8 2
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