| Conditions | 11 |
| Paths | 46 |
| Total Lines | 43 |
| Code Lines | 23 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 60 | protected function voteOnAttribute($attribute, $subject, TokenInterface $token): bool |
||
| 61 | { |
||
| 62 | $request = $this->requestStack->getCurrentRequest(); |
||
| 63 | if (!$request) { |
||
| 64 | return true; |
||
| 65 | } |
||
| 66 | |||
| 67 | $pagesGenerator = $this->getComponentPages($subject); |
||
| 68 | $pages = iterator_to_array($pagesGenerator); |
||
| 69 | |||
| 70 | // Check if accessible via any route |
||
| 71 | $routes = $this->getComponentRoutesFromPages($pages); |
||
| 72 | $routeCount = 0; |
||
| 73 | foreach ($routes as $route) { |
||
| 74 | ++$routeCount; |
||
| 75 | if ($this->isRouteReachableResource($route, $request)) { |
||
| 76 | return true; |
||
| 77 | } |
||
| 78 | } |
||
| 79 | |||
| 80 | // check if accessible via any page data |
||
| 81 | |||
| 82 | // 1. as a page data property |
||
| 83 | $pageData = $this->pageDataProvider->findPageDataComponentMetadata($subject); |
||
| 84 | $pageDataCount = 0; |
||
| 85 | foreach ($pageData as $pageDatum) { |
||
| 86 | foreach ($pageDatum->getPageDataResources() as $pageDataResource) { |
||
| 87 | ++$pageDataCount; |
||
| 88 | if ($this->isPageDataReachableResource($pageDataResource, $request)) { |
||
| 89 | return true; |
||
| 90 | } |
||
| 91 | } |
||
| 92 | } |
||
| 93 | |||
| 94 | // 2. as a component in the page template being used by page data |
||
| 95 | $pageDataByPagesComponentUsedIn = $this->pageDataProvider->findPageDataResourcesByPages($pages); |
||
| 96 | foreach ($pageDataByPagesComponentUsedIn as $pageData) { |
||
| 97 | if ($this->isPageDataReachableResource($pageData, $request)) { |
||
| 98 | return true; |
||
| 99 | } |
||
| 100 | } |
||
| 101 | |||
| 102 | return !$routeCount && !$pageDataCount && !\count($pageDataByPagesComponentUsedIn); |
||
| 103 | } |
||
| 169 |