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
Push — master ( 4f5669...8f549c )
by Jérémiah
07:08
created

AuthorizationExpressionProvider::getFunctions()   C

Complexity

Conditions 8
Paths 1

Size

Total Lines 78
Code Lines 50

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 36.1943

Importance

Changes 2
Bugs 1 Features 2
Metric Value
c 2
b 1
f 2
dl 0
loc 78
ccs 11
cts 46
cp 0.2391
rs 6.102
cc 8
eloc 50
nc 1
nop 0
crap 36.1943

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\ExpressionFunction;
15
use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface;
16
17
class AuthorizationExpressionProvider implements ExpressionFunctionProviderInterface
18
{
19 24
    public function getFunctions()
20
    {
21
        return [
22
            new ExpressionFunction('hasRole', function ($role) {
23
                return sprintf('$authChecker->isGranted(%s)', $role);
24
            }, function (array $variables, $role) {
25
                return $variables['container']->get('security.authorization_checker')->isGranted($role);
26 24
            }),
27
28
            new ExpressionFunction('hasAnyRole', function (array $roles) {
29
                $compiler = 'false';
30
                foreach ($roles as $role) {
31
                    $compiler .= ' || ';
32
                    $compiler .= sprintf('$authChecker->isGranted(%s)', $role);
33
                }
34
35
                return $compiler;
36
            }, function (array $variables, array $roles) {
37
                foreach ($roles as $role) {
38
                    if ($variables['container']->get('security.authorization_checker')->isGranted($role)) {
39
                        return true;
40
                    }
41
                }
42
43
                return false;
44 24
            }),
45
46
            new ExpressionFunction('isAnonymous', function () {
47
                return '$authChecker->isGranted("IS_AUTHENTICATED_ANONYMOUSLY")';
48
            }, function (array $variables) {
49
                return $variables['container']->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_ANONYMOUSLY');
50 24
            }),
51
52
            new ExpressionFunction('isRememberMe', function () {
53
                return '$authChecker->isGranted("IS_AUTHENTICATED_REMEMBERED")';
54
            }, function (array $variables) {
55
                return $variables['container']->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_REMEMBERED');
56 24
            }),
57
58
            new ExpressionFunction('isFullyAuthenticated', function () {
59
                return sprintf('$authChecker->isGranted("IS_AUTHENTICATED_FULLY")');
60
            }, function (array $variables) {
61
                return $variables['container']->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_FULLY');
62 24
            }),
63
64
            new ExpressionFunction('isAuthenticated', function () {
65
                return '$authChecker->isGranted("IS_AUTHENTICATED_REMEMBERED") ||  $authChecker->isGranted("IS_AUTHENTICATED_FULLY")';
66
            }, function (array $variables) {
67
                return
68
                    $variables['container']->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_REMEMBERED')
69
                    || $variables['container']->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_FULLY');
70 24
            }),
71
72
            new ExpressionFunction('hasPermission', function ($object, $permission) {
73
                return sprintf('$authChecker->isGranted(%s, $object)', $permission);
74
            }, function (array $variables, $object, $permission) {
75
                return $variables['container']->get('security.authorization_checker')->isGranted($permission, $object);
76 24
            }),
77
78
            new ExpressionFunction('hasAnyPermission', function ($object, array $permissions) {
79
                $compiler = 'false';
80
                foreach ($permissions as $permission) {
81
                    $compiler .= ' || ';
82
                    $compiler .= sprintf('$authChecker->isGranted("%s", $object)', $permission);
83
                }
84
85
                return $compiler;
86 24
            }, function (array $variables, $object, array $permissions) {
87
                foreach ($permissions as $permission) {
88
                    if ($variables['container']->get('security.authorization_checker')->isGranted($permission, $object)) {
89
                        return true;
90
                    }
91
                }
92
93
                return false;
94 24
            }),
95 24
        ];
96
    }
97
}
98