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.
Passed
Pull Request — master (#24)
by Vincent
05:11
created

ScenarioStateHookableScenarioTester::test()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 4
1
<?php
2
3
/*
4
 * This file is part of the ScenarioStateBehatExtension project.
5
 *
6
 * (c) Rodrigue Villetard <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Gorghoa\ScenarioStateBehatExtension\Hook\Tester;
13
14
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
15
use Behat\Behat\Hook\Tester\HookableScenarioTester;
16
use Behat\Behat\Tester\ScenarioTester;
17
use Behat\Gherkin\Node\FeatureNode;
18
use Behat\Gherkin\Node\ScenarioInterface as Scenario;
19
use Behat\Testwork\Environment\Environment;
20
use Behat\Testwork\Hook\Tester\Setup\HookedSetup;
21
use Behat\Testwork\Tester\Result\TestResult;
22
use Gorghoa\ScenarioStateBehatExtension\Hook\Dispatcher\ScenarioStateHookDispatcher;
23
24
/**
25
 * @author Vincent Chalamon <[email protected]>
26
 */
27
final class ScenarioStateHookableScenarioTester implements ScenarioTester
28
{
29
    /**
30
     * @var HookableScenarioTester
31
     */
32
    private $decoratedService;
33
34
    /**
35
     * @var ScenarioTester
36
     */
37
    private $baseTester;
38
39
    /**
40
     * @var ScenarioStateHookDispatcher
41
     */
42
    private $dispatcher;
43
44
    /**
45
     * @param HookableScenarioTester      $decoratedService
46
     * @param ScenarioTester              $baseTester
47
     * @param ScenarioStateHookDispatcher $dispatcher
48
     */
49
    public function __construct(HookableScenarioTester $decoratedService, ScenarioTester $baseTester, ScenarioStateHookDispatcher $dispatcher)
50
    {
51
        $this->decoratedService = $decoratedService;
52
        $this->baseTester = $baseTester;
53
        $this->dispatcher = $dispatcher;
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59
    public function setUp(Environment $env, FeatureNode $feature, Scenario $scenario, $skip)
60
    {
61
        $setup = $this->decoratedService->setUp($env, $feature, $scenario, true);
62
63
        if ($skip) {
64
            return $setup;
65
        }
66
67
        $scope = new BeforeScenarioScope($env, $feature, $scenario);
68
        $hookCallResults = $this->dispatcher->dispatchScopeHooks($scope);
69
70
        return new HookedSetup($setup, $hookCallResults);
0 ignored issues
show
Bug introduced by
It seems like $hookCallResults defined by $this->dispatcher->dispatchScopeHooks($scope) on line 68 can be null; however, Behat\Testwork\Hook\Test...kedSetup::__construct() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
71
    }
72
73
    /**
74
     * {@inheritdoc}
75
     */
76
    public function test(Environment $env, FeatureNode $feature, Scenario $scenario, $skip)
77
    {
78
        return $this->decoratedService->test($env, $feature, $scenario, $skip);
79
    }
80
81
    /**
82
     * {@inheritdoc}
83
     */
84
    public function tearDown(Environment $env, FeatureNode $feature, Scenario $scenario, $skip, TestResult $result)
85
    {
86
        return $this->decoratedService->tearDown($env, $feature, $scenario, $skip, $result);
87
    }
88
}
89