Conditions | 12 |
Paths | 12 |
Total Lines | 33 |
Code Lines | 18 |
Lines | 0 |
Ratio | 0 % |
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 |
||
65 | public function matchItem(ItemInterface $item) |
||
66 | { |
||
67 | $admin = $item->getExtra('admin'); |
||
68 | |||
69 | $request = $this->request; |
||
70 | if (null !== $this->requestStack) { |
||
71 | $request = $this->requestStack->getMasterRequest(); |
||
72 | } |
||
73 | |||
74 | if ($admin instanceof AdminInterface |
||
75 | && $admin->hasRoute('list') && $admin->hasAccess('list') |
||
76 | && $request |
||
77 | ) { |
||
78 | $requestCode = $request->get('_sonata_admin'); |
||
79 | |||
80 | if ($admin->getCode() === $requestCode) { |
||
81 | return true; |
||
82 | } |
||
83 | |||
84 | foreach ($admin->getChildren() as $child) { |
||
85 | if ($child->getBaseCodeRoute() === $requestCode) { |
||
86 | return true; |
||
87 | } |
||
88 | } |
||
89 | } |
||
90 | |||
91 | $route = $item->getExtra('route'); |
||
92 | if ($route && $request && $route == $request->get('_route')) { |
||
93 | return true; |
||
94 | } |
||
95 | |||
96 | return null; |
||
97 | } |
||
98 | } |
||
99 |
If you suppress an error, we recommend checking for the error condition explicitly: