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

Completed
Pull Request — master (#73)
by Jérémiah
07:13
created

AuthorizationExpressionProvider::getFunctions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 68
Code Lines 38

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 39
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 68
ccs 39
cts 40
cp 0.975
rs 9.2447
c 0
b 0
f 0
cc 1
eloc 38
nc 1
nop 0
crap 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/*
4
 * This file is part of the OverblogGraphQLBundle package.
5
 *
6
 * (c) Overblog <http://github.com/overblog/>
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 Overblog\GraphQLBundle\ExpressionLanguage;
13
14
use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface;
15
16
class AuthorizationExpressionProvider implements ExpressionFunctionProviderInterface
17
{
18 27
    public function getFunctions()
19
    {
20
        return [
21 27
            new ExpressionFunction(
22 27
                'hasRole',
23
                function ($role) {
24 2
                    return sprintf('$container->get(\'security.authorization_checker\')->isGranted(%s)', $role);
25
                }
26 27
            ),
27
28 27
            new ExpressionFunction(
29 27
                'hasAnyRole',
30
                function ($roles) {
31 1
                    $code = sprintf('array_reduce(%s, function ($isGranted, $role) use ($container) { return $isGranted || $container->get(\'security.authorization_checker\')->isGranted($role); }, false)', $roles);
32
33 1
                    return $code;
34
                }
35 27
            ),
36
37 27
            new ExpressionFunction(
38 27
                'isAnonymous',
39
                function () {
40 1
                    return '$container->get(\'security.authorization_checker\')->isGranted(\'IS_AUTHENTICATED_ANONYMOUSLY\')';
41
                }
42 27
            ),
43
44 27
            new ExpressionFunction(
45 27
                'isRememberMe',
46
                function () {
47 1
                    return '$container->get(\'security.authorization_checker\')->isGranted(\'IS_AUTHENTICATED_REMEMBERED\')';
48
                }
49 27
            ),
50
51 27
            new ExpressionFunction(
52 27
                'isFullyAuthenticated',
53
                function () {
54 2
                    return '$container->get(\'security.authorization_checker\')->isGranted(\'IS_AUTHENTICATED_FULLY\')';
55 27
                },
56
                function () {
0 ignored issues
show
Unused Code introduced by
The call to ExpressionFunction::__construct() has too many arguments starting with function () { }.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
57
                }
58 27
            ),
59
60 27
            new ExpressionFunction(
61 27
                'isAuthenticated',
62
                function () {
63 1
                    return '$container->get(\'security.authorization_checker\')->isGranted(\'IS_AUTHENTICATED_REMEMBERED\') || $container->get(\'security.authorization_checker\')->isGranted(\'IS_AUTHENTICATED_FULLY\')';
64
                }
65 27
            ),
66
67 27
            new ExpressionFunction(
68 27
                'hasPermission',
69
                function ($object, $permission) {
70 1
                    $code = sprintf('$container->get(\'security.authorization_checker\')->isGranted(%s, %s)', $permission, $object);
71
72 1
                    return $code;
73
                }
74 27
            ),
75
76 27
            new ExpressionFunction(
77 27
                'hasAnyPermission',
78 1
                function ($object, $permissions) {
79 1
                    $code = sprintf('array_reduce(%s, function ($isGranted, $permission) use ($container, $object) { return $isGranted || $container->get(\'security.authorization_checker\')->isGranted($permission, %s); }, false)', $permissions, $object);
80
81 1
                    return $code;
82
                }
83 27
            ),
84 27
        ];
85
    }
86
}
87