GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

ScenarioBranchingFileLoader   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 90
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 10
c 2
b 0
f 0
lcom 1
cbo 7
dl 0
loc 90
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A parseFeature() 0 7 2
A branchFeatureVariants() 0 20 2
A getBranchedScenario() 0 15 2
B branchScenarioVariants() 0 27 4
1
<?php
2
3
namespace Ciandt\Behat\PlaceholdersExtension\Gherkin;
4
5
use Behat\Gherkin\Cache\CacheInterface;
6
use Behat\Gherkin\Loader\GherkinFileLoader;
7
use Behat\Gherkin\Node\FeatureNode;
8
use Behat\Gherkin\Node\OutlineNode;
9
use Behat\Gherkin\Node\ScenarioInterface;
10
use Behat\Gherkin\Node\ScenarioNode;
11
use Behat\Gherkin\Parser;
12
use Ciandt\Behat\PlaceholdersExtension\Utils\PlaceholderUtils;
13
use phpDocumentor\Reflection\Types\Boolean;
14
15
/**
16
 * Gherkin *.feature files loader.
17
 * Modified to branch Scenarios per variant.
18
 *
19
 * @author Bruno Wowk <[email protected]>
20
 */
21
class ScenarioBranchingFileLoader extends GherkinFileLoader
22
{
23
   
24
    /**
25
     * Parses feature at provided absolute path.
26
     *
27
     * @param string $path Feature path
28
     *
29
     * @return FeatureNode
30
     */
31
    protected function parseFeature($path)
32
    {
33
        $filename = $this->findRelativePath($path);
34
        $content = file_get_contents($path);
35
        $feature = $this->parser->parse($content, $filename);
36
        return null === $feature? $feature : $this->branchFeatureVariants($feature);
37
    }
38
    
39
    /**
40
     * Branches Scenarios/Outlines with variant tags for each variant.
41
     *
42
     * @param FeatureNode $feature Parsed feature
43
     *
44
     * @return FeatureNode
45
     */
46
    private function branchFeatureVariants(FeatureNode $feature)
47
    {
48
        $scenarios = array();
49
        
50
        foreach ($feature->getScenarios() as $scenario) {
51
            $scenarios = array_merge($scenarios, $this->getBranchedScenario($scenario, $feature));
52
        }
53
54
        return new FeatureNode(
55
            $feature->getTitle(),
56
            $feature->getDescription(),
57
            $feature->getTags(),
58
            $feature->getBackground(),
59
            $scenarios,
60
            $feature->getKeyword(),
61
            $feature->getLanguage(),
62
            $feature->getFile(),
63
            $feature->getLine()
64
        );
65
    }
66
    
67
    private function getBranchedScenario(ScenarioInterface $scenarioLike, FeatureNode $feature)
68
    {
69
        $scenarioTags = $scenarioLike->getTags();
70
        $featureTags = $feature->getTags();
71
        $tags = array_merge($scenarioTags, $featureTags);
72
        
73
        $variants = PlaceholderUtils::filterVariantTags($tags, false);
74
        
75
        if (count($variants) <= 1) {
76
            return array($scenarioLike);
77
        } else {
78
            return $this->branchScenarioVariants($scenarioLike, $variants);
79
        }
80
        
81
    }
82
    
83
    private function branchScenarioVariants(ScenarioInterface $scenarioLike, $variants)
84
    {
85
        $scenarios = array();
86
        $nonVariantTags = PlaceholderUtils::filterVariantTags($scenarioLike->getTags(), true);
87
        foreach ($variants as $variant) {
88
            $tags = array_merge($nonVariantTags, array($variant));
89
            if ($scenarioLike instanceof ScenarioNode) {
90
                $scenarios[] = new ScenarioNode(
91
                    $scenarioLike->getTitle(),
92
                    $tags,
93
                    $scenarioLike->getSteps(),
94
                    $scenarioLike->getKeyword(),
95
                    $scenarioLike->getLine()
96
                );
97
            } elseif ($scenarioLike instanceof OutlineNode) {
98
                $scenarios[] = new OutlineNode(
99
                    $scenarioLike->getTitle(),
100
                    $tags,
101
                    $scenarioLike->getSteps(),
102
                    $scenarioLike->getExampleTable(),
103
                    $scenarioLike->getKeyword(),
104
                    $scenarioLike->getLine()
105
                );
106
            }
107
        }
108
        return $scenarios;
109
    }
110
}
111