We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
Conditions | 1 |
Paths | 1 |
Total Lines | 82 |
Code Lines | 45 |
Lines | 0 |
Ratio | 0 % |
Tests | 45 |
CRAP Score | 1.0046 |
Changes | 0 |
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 | 25 | public function getFunctions() |
|
20 | { |
||
21 | return [ |
||
22 | 25 | new ExpressionFunction( |
|
23 | 25 | 'hasRole', |
|
24 | function ($role) { |
||
25 | 2 | return sprintf('$container->get(\'security.authorization_checker\')->isGranted(%s)', $role); |
|
26 | 25 | }, |
|
27 | function () { |
||
28 | } |
||
29 | 25 | ), |
|
30 | |||
31 | 25 | new ExpressionFunction( |
|
32 | 25 | 'hasAnyRole', |
|
33 | function ($roles) { |
||
34 | 1 | $code = sprintf('array_reduce(%s, function ($isGranted, $role) use ($container) { return $isGranted || $container->get(\'security.authorization_checker\')->isGranted($role); }, false)', $roles); |
|
35 | |||
36 | 1 | return $code; |
|
37 | 25 | }, |
|
38 | function () { |
||
39 | } |
||
40 | 25 | ), |
|
41 | |||
42 | 25 | new ExpressionFunction( |
|
43 | 25 | 'isAnonymous', |
|
44 | function () { |
||
45 | 1 | return '$container->get(\'security.authorization_checker\')->isGranted(\'IS_AUTHENTICATED_ANONYMOUSLY\')'; |
|
46 | 25 | }, |
|
47 | function () { |
||
48 | } |
||
49 | 25 | ), |
|
50 | |||
51 | 25 | new ExpressionFunction( |
|
52 | 25 | 'isRememberMe', |
|
53 | function () { |
||
54 | 1 | return '$container->get(\'security.authorization_checker\')->isGranted(\'IS_AUTHENTICATED_REMEMBERED\')'; |
|
55 | 25 | }, |
|
56 | function () { |
||
57 | } |
||
58 | 25 | ), |
|
59 | |||
60 | 25 | new ExpressionFunction( |
|
61 | 25 | 'isFullyAuthenticated', |
|
62 | function () { |
||
63 | 2 | return '$container->get(\'security.authorization_checker\')->isGranted(\'IS_AUTHENTICATED_FULLY\')'; |
|
64 | 25 | }, |
|
65 | function () { |
||
66 | } |
||
67 | 25 | ), |
|
68 | |||
69 | 25 | new ExpressionFunction( |
|
70 | 25 | 'isAuthenticated', |
|
71 | function () { |
||
72 | 1 | return '$container->get(\'security.authorization_checker\')->isGranted(\'IS_AUTHENTICATED_REMEMBERED\') || $container->get(\'security.authorization_checker\')->isGranted(\'IS_AUTHENTICATED_FULLY\')'; |
|
73 | 25 | }, |
|
74 | function () { |
||
75 | } |
||
76 | 25 | ), |
|
77 | |||
78 | 25 | new ExpressionFunction( |
|
79 | 25 | 'hasPermission', |
|
80 | function ($object, $permission) { |
||
81 | 1 | $code = sprintf('$container->get(\'security.authorization_checker\')->isGranted(%s, %s)', $permission, $object); |
|
82 | |||
83 | 1 | return $code; |
|
84 | 25 | }, |
|
85 | function () { |
||
86 | } |
||
87 | 25 | ), |
|
88 | |||
89 | 25 | new ExpressionFunction( |
|
90 | 25 | 'hasAnyPermission', |
|
91 | function ($object, $permissions) { |
||
92 | 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); |
|
93 | |||
94 | 1 | return $code; |
|
95 | 25 | }, |
|
96 | function () { |
||
97 | } |
||
98 | 25 | ), |
|
99 | 25 | ]; |
|
100 | } |
||
101 | } |
||
102 |