We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
Conditions | 8 |
Paths | 1 |
Total Lines | 78 |
Code Lines | 50 |
Lines | 0 |
Ratio | 0 % |
Tests | 11 |
CRAP Score | 36.1943 |
Changes | 2 | ||
Bugs | 1 | Features | 2 |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
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 |