Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Passed
Pull Request — master (#265)
by Jérémiah
14:57
created

getAuthorizationCheckerIsGrantedWithExpectation()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 23
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 23
rs 8.7972
c 0
b 0
f 0
cc 4
eloc 14
nc 4
nop 3
1
<?php
2
3
namespace Overblog\GraphQLBundle\Tests\ExpressionLanguage;
4
5
use Overblog\GraphQLBundle\ExpressionLanguage\ExpressionLanguage;
6
use Overblog\GraphQLBundle\Tests\DIContainerMockTrait;
7
use PHPUnit\Framework\TestCase as BaseTestCase;
8
use Symfony\Component\ExpressionLanguage\ExpressionFunction;
9
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
10
11
abstract class TestCase extends BaseTestCase
12
{
13
    use DIContainerMockTrait;
14
15
    /** @var ExpressionLanguage */
16
    protected $expressionLanguage;
17
18
    public function setUp()
19
    {
20
        $this->expressionLanguage = new ExpressionLanguage();
21
        $container = $this->getDIContainerMock();
22
        $this->expressionLanguage->setContainer($container);
23
        foreach ($this->getFunctions() as $function) {
24
            $this->expressionLanguage->addFunction($function);
25
        }
26
    }
27
28
    /**
29
     * @return ExpressionFunction[]
30
     */
31
    abstract protected function getFunctions();
32
33
    protected function assertExpressionCompile($expression, $with, array $expressionValues = [], $expects = null, $return = true, $assertMethod = 'assertTrue')
34
    {
35
        // container var is needed by eval
36
        $container = $this->getDIContainerMock(['security.authorization_checker' => $this->getAuthorizationCheckerIsGrantedWithExpectation($with, $expects, $return)]);
0 ignored issues
show
Unused Code introduced by
$container is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
37
        extract($expressionValues);
38
39
        $code = $this->expressionLanguage->compile($expression, array_keys($expressionValues));
40
41
        $this->$assertMethod(eval('return '.$code.';'));
0 ignored issues
show
Coding Style introduced by
It is generally not recommended to use eval unless absolutely required.

On one hand, eval might be exploited by malicious users if they somehow manage to inject dynamic content. On the other hand, with the emergence of faster PHP runtimes like the HHVM, eval prevents some optimization that they perform.

Loading history...
42
    }
43
44
    private function getAuthorizationCheckerIsGrantedWithExpectation($with, $expects = null, $return = true)
45
    {
46
        if (null === $expects) {
47
            $expects = $this->once();
48
        }
49
        $authChecker = $this->getAuthorizationCheckerMock();
50
51
        if ($return instanceof \PHPUnit_Framework_MockObject_Stub_Return) {
0 ignored issues
show
Bug introduced by
The class PHPUnit_Framework_MockObject_Stub_Return does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
52
            $returnValue = $return;
53
        } else {
54
            $returnValue = $this->returnValue($return);
55
        }
56
57
        $methodExpectation = $authChecker
58
            ->expects($expects)
59
            ->method('isGranted');
60
61
        call_user_func_array([$methodExpectation, 'with'], is_array($with) ? $with : [$with]);
62
63
        $methodExpectation->will($returnValue);
64
65
        return $authChecker;
66
    }
67
68
    private function getAuthorizationCheckerMock()
69
    {
70
        $AuthorizationChecker = $this->getMockBuilder(AuthorizationCheckerInterface::class)
71
            ->disableOriginalConstructor()
72
            ->setMethods(['isGranted'])
73
            ->getMock()
74
        ;
75
76
        return $AuthorizationChecker;
77
    }
78
}
79