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 | 66 |
Code Lines | 37 |
Lines | 0 |
Ratio | 0 % |
Tests | 38 |
CRAP Score | 1 |
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 |
||
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 | } |
||
56 | 27 | ), |
|
57 | |||
58 | 27 | new ExpressionFunction( |
|
59 | 27 | 'isAuthenticated', |
|
60 | function () { |
||
61 | 1 | return '$container->get(\'security.authorization_checker\')->isGranted(\'IS_AUTHENTICATED_REMEMBERED\') || $container->get(\'security.authorization_checker\')->isGranted(\'IS_AUTHENTICATED_FULLY\')'; |
|
62 | } |
||
63 | 27 | ), |
|
64 | |||
65 | 27 | new ExpressionFunction( |
|
66 | 27 | 'hasPermission', |
|
67 | function ($object, $permission) { |
||
68 | 1 | $code = sprintf('$container->get(\'security.authorization_checker\')->isGranted(%s, %s)', $permission, $object); |
|
69 | |||
70 | 1 | return $code; |
|
71 | } |
||
72 | 27 | ), |
|
73 | |||
74 | 27 | new ExpressionFunction( |
|
75 | 27 | 'hasAnyPermission', |
|
76 | 1 | function ($object, $permissions) { |
|
77 | 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); |
|
78 | |||
79 | 1 | return $code; |
|
80 | } |
||
81 | 27 | ), |
|
82 | 27 | ]; |
|
83 | } |
||
84 | } |
||
85 |