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