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.
Completed
Push — master ( 66c291...444f0e )
by Bruno
03:49
created

StepDecoratingScenarioTester   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 92
Duplicated Lines 15.22 %

Coupling/Cohesion

Components 1
Dependencies 9

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 9
dl 14
loc 92
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A setUp() 0 3 1
A tearDown() 0 3 1
A test() 0 15 2
A decorateScenarioSteps() 7 16 2
A scanMeaningfulTags() 0 7 1
B decorateBackgroundSteps() 7 30 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
4
namespace Ciandt\Behat\PlaceholdersExtension\Tester;
5
6
use Behat\Behat\Tester\ScenarioTester;
7
use Behat\Gherkin\Node\BackgroundNode;
8
use Behat\Gherkin\Node\FeatureNode;
9
use Behat\Gherkin\Node\ScenarioInterface;
10
use Behat\Gherkin\Node\ScenarioNode;
11
use Behat\Testwork\Environment\Environment;
12
use Behat\Testwork\Tester\Result\TestResult;
13
use Behat\Testwork\Tester\Setup\SuccessfulSetup;
14
use Behat\Testwork\Tester\Setup\SuccessfulTeardown;
15
use Ciandt\Behat\PlaceholdersExtension\PlaceholderContainer\PlaceholderContainerStepNode;
16
use Ciandt\Behat\PlaceholdersExtension\Utils\PlaceholderUtils;
17
18
/**
19
 * Description of StepDecoratingScenarioTester
20
 *
21
 * @author bwowk
22
 */
23
class StepDecoratingScenarioTester implements ScenarioTester{
24
    
25
    private $baseTester;
26
    private $configKey;
27
    private $sectionKey;
28
    private $variant;
29
    
30
    public function __construct(ScenarioTester $baseTester) {
31
        $this->baseTester = $baseTester;
32
    }
33
34
    public function setUp(Environment $env, FeatureNode $feature, ScenarioInterface $scenario, $skip) {
35
        return new SuccessfulSetup();
36
    }
37
38
    public function tearDown(Environment $env, FeatureNode $feature, ScenarioInterface $scenario, $skip, TestResult $result) {
39
        return new SuccessfulTeardown();
40
    }
41
42
    public function test(Environment $env, FeatureNode $feature, ScenarioInterface $scenario, $skip) {
43
        $scenarioTags = $scenario->getTags();
44
        $featureTags = $feature->getTags();
45
        $tags = array_merge($scenarioTags,$featureTags);
46
        // If there's no config tag, proceed with undecorated steps
47
        if (!PlaceholderUtils::getConfigTag($tags)){
48
            return $this->baseTester->test($env, $feature, $scenario, $skip);
49
        }
50
        // detect config and variant tags
51
        $this->scanMeaningfulTags($tags);
52
        
53
        $decoratedFeature = $this->decorateBackgroundSteps($feature);
54
        $decoratedScenario = $this->decorateScenarioSteps($scenario);
55
        return $this->baseTester->test($env, $decoratedFeature, $decoratedScenario, $skip);
56
    }
57
    
58
    private function decorateScenarioSteps(ScenarioInterface $undecoratedScenario){
59
        $decoratedSteps = array();
60 View Code Duplication
        foreach ($undecoratedScenario->getSteps() as $step){
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
61
            $decoratedSteps[] = new PlaceholderContainerStepNode(
62
                    $step,
63
                    $this->configKey,
64
                    $this->sectionKey,
65
                    $this->variant);
66
        }
67
        return new ScenarioNode(
68
                $undecoratedScenario->getTitle(),
69
                $undecoratedScenario->getTags(),
70
                $decoratedSteps,
71
                $undecoratedScenario->getKeyword(),
72
                $undecoratedScenario->getLine());
73
    }
74
    
75
    private function scanMeaningfulTags($tags){
76
        $configTag = PlaceholderUtils::getConfigTag($tags);
77
        $this->configKey = PlaceholderUtils::getConfigKey($configTag);
78
        $this->sectionKey = PlaceholderUtils::getSectionKey($configTag);
79
        // At this point, variant tags should have been splitted between sepparate scenarios
80
        $this->variant = PlaceholderUtils::getVariant($tags);
81
    }
82
    
83
    private function decorateBackgroundSteps(FeatureNode $feature){
84
        if (!$feature->hasBackground()) {
85
            return $feature;
86
        }
87
        $undecoratedBackground = $feature->getBackground();
88
        $decoratedSteps = array();
89 View Code Duplication
        foreach ($undecoratedBackground->getSteps() as $step){
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
90
            $decoratedSteps[] = new PlaceholderContainerStepNode(
91
                    $step,
92
                    $this->configKey,
93
                    $this->sectionKey,
94
                    $this->variant);
95
        }
96
        $decoratedBackground = new BackgroundNode(
97
                $undecoratedBackground->getTitle(),
98
                $decoratedSteps,
99
                $undecoratedBackground->getKeyword(),
100
                $undecoratedBackground->getLine());
101
        
102
        return new FeatureNode(
103
            $feature->getTitle(),
104
            $feature->getDescription(),
105
            $feature->getTags(),
106
            $decoratedBackground,
107
            $feature->getScenarios(),
108
            $feature->getKeyword(),
109
            $feature->getLanguage(),
110
            $feature->getFile(),
111
            $feature->getLine());
112
    }
113
114
}
115