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 | 74 |
Code Lines | 45 |
Lines | 0 |
Ratio | 0 % |
Tests | 45 |
CRAP Score | 1 |
Changes | 4 | ||
Bugs | 2 | 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 | 24 | new ExpressionFunction( |
|
23 | 24 | 'hasRole', |
|
24 | function ($role) { |
||
25 | 2 | return sprintf('$container->get(\'security.authorization_checker\')->isGranted(%s)', $role); |
|
26 | 24 | }, |
|
27 | function () {} |
||
28 | 24 | ), |
|
29 | |||
30 | 24 | new ExpressionFunction( |
|
31 | 24 | 'hasAnyRole', |
|
32 | function ($roles) { |
||
33 | 1 | $code = sprintf('array_reduce(%s, function ($isGranted, $role) use ($container) { return $isGranted || $container->get(\'security.authorization_checker\')->isGranted($role); }, false)', $roles); |
|
34 | |||
35 | 1 | return $code; |
|
36 | 24 | }, |
|
37 | function () {} |
||
38 | 24 | ), |
|
39 | |||
40 | 24 | new ExpressionFunction( |
|
41 | 24 | 'isAnonymous', |
|
42 | function () { |
||
43 | 1 | return '$container->get(\'security.authorization_checker\')->isGranted(\'IS_AUTHENTICATED_ANONYMOUSLY\')'; |
|
44 | 24 | }, |
|
45 | function () {} |
||
46 | 24 | ), |
|
47 | |||
48 | 24 | new ExpressionFunction( |
|
49 | 24 | 'isRememberMe', |
|
50 | function () { |
||
51 | 1 | return '$container->get(\'security.authorization_checker\')->isGranted(\'IS_AUTHENTICATED_REMEMBERED\')'; |
|
52 | 24 | }, |
|
53 | function () {} |
||
54 | 24 | ), |
|
55 | |||
56 | 24 | new ExpressionFunction( |
|
57 | 24 | 'isFullyAuthenticated', |
|
58 | function () { |
||
59 | 2 | return '$container->get(\'security.authorization_checker\')->isGranted(\'IS_AUTHENTICATED_FULLY\')'; |
|
60 | 24 | }, |
|
61 | function () {} |
||
62 | 24 | ), |
|
63 | |||
64 | 24 | new ExpressionFunction( |
|
65 | 24 | 'isAuthenticated', |
|
66 | function () { |
||
67 | 1 | return '$container->get(\'security.authorization_checker\')->isGranted(\'IS_AUTHENTICATED_REMEMBERED\') || $container->get(\'security.authorization_checker\')->isGranted(\'IS_AUTHENTICATED_FULLY\')'; |
|
68 | 24 | }, |
|
69 | function () {} |
||
70 | 24 | ), |
|
71 | |||
72 | 24 | new ExpressionFunction( |
|
73 | 24 | 'hasPermission', |
|
74 | function ($object, $permission) { |
||
75 | 1 | $code = sprintf('$container->get(\'security.authorization_checker\')->isGranted(%s, %s)', $permission, $object); |
|
76 | |||
77 | 1 | return $code; |
|
78 | 24 | }, |
|
79 | function () {} |
||
80 | 24 | ), |
|
81 | |||
82 | 24 | new ExpressionFunction( |
|
83 | 24 | 'hasAnyPermission', |
|
84 | function ($object, $permissions) { |
||
85 | 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); |
|
86 | |||
87 | 1 | return $code; |
|
88 | 24 | }, |
|
89 | function () {} |
||
90 | 24 | ), |
|
91 | 24 | ]; |
|
92 | } |
||
93 | } |
||
94 |