| Conditions | 10 |
| Paths | 17 |
| Total Lines | 88 |
| Code Lines | 52 |
| 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 |
||
| 52 | public function editAction( |
||
| 53 | RequestStack $requestStack, |
||
| 54 | PermissionApiInterface $permissionApi, |
||
| 55 | HookCollectorInterface $collector, |
||
| 56 | HookDispatcherInterface $dispatcher, |
||
| 57 | HookUiHelper $hookUiHelper, |
||
| 58 | string $moduleName |
||
| 59 | ): array { |
||
| 60 | $templateParameters = []; |
||
| 61 | // get module's name and assign it to template |
||
| 62 | $templateParameters['currentmodule'] = $moduleName; |
||
| 63 | |||
| 64 | // check if user has admin permission on this module |
||
| 65 | if (!$permissionApi->hasPermission($moduleName . '::', '::', ACCESS_ADMIN)) { |
||
| 66 | throw new AccessDeniedException(); |
||
| 67 | } |
||
| 68 | |||
| 69 | // find out the capabilities of the module |
||
| 70 | $isProvider = $collector->isCapable($moduleName, HookCollectorInterface::HOOK_PROVIDER); |
||
| 71 | $templateParameters['isProvider'] = $isProvider; |
||
| 72 | |||
| 73 | $isSubscriber = $collector->isCapable($moduleName, HookCollectorInterface::HOOK_SUBSCRIBER); |
||
| 74 | $templateParameters['isSubscriber'] = $isSubscriber; |
||
| 75 | |||
| 76 | $isSubscriberSelfCapable = $collector->isCapable($moduleName, HookCollectorInterface::HOOK_SUBSCRIBE_OWN); |
||
| 77 | $templateParameters['isSubscriberSelfCapable'] = $isSubscriberSelfCapable; |
||
| 78 | $templateParameters['providerAreas'] = []; |
||
| 79 | |||
| 80 | $providers = $collector->getProviders(); |
||
| 81 | $subscribers = $collector->getSubscribers(); |
||
| 82 | |||
| 83 | // get areas of module and bundle titles also |
||
| 84 | if ($isProvider) { |
||
| 85 | $providerAreas = $collector->getProviderAreasByOwner($moduleName); |
||
| 86 | $templateParameters['providerAreas'] = $providerAreas; |
||
| 87 | |||
| 88 | $providerAreasToTitles = []; |
||
| 89 | foreach ($providerAreas as $providerArea) { |
||
| 90 | if (isset($providers[$providerArea])) { |
||
| 91 | $providerAreasToTitles[$providerArea] = $providers[$providerArea]->getTitle(); |
||
| 92 | } |
||
| 93 | } |
||
| 94 | $templateParameters['providerAreasToTitles'] = $providerAreasToTitles; |
||
| 95 | } |
||
| 96 | $templateParameters['subscriberAreas'] = []; |
||
| 97 | $templateParameters['hookSubscribers'] = []; |
||
| 98 | |||
| 99 | if ($isSubscriber) { |
||
| 100 | $subscriberAreas = $collector->getSubscriberAreasByOwner($moduleName); |
||
| 101 | $templateParameters['subscriberAreas'] = $subscriberAreas; |
||
| 102 | |||
| 103 | $areasInfo = $hookUiHelper->prepareSubscriberAreasForSubscriber($subscriberAreas, $subscribers); |
||
| 104 | $templateParameters['subscriberAreasToTitles'] = $areasInfo['titles']; |
||
| 105 | $templateParameters['subscriberAreasToCategories'] = $areasInfo['categories']; |
||
| 106 | $templateParameters['subscriberAreasAndCategories'] = $areasInfo['categoryGroups']; |
||
| 107 | } |
||
| 108 | |||
| 109 | // get available subscribers that can attach to provider |
||
| 110 | if ($isProvider && !empty($providerAreas)) { |
||
| 111 | [$hookSubscribers, $amountOfAvailableSubscriberAreas] = $hookUiHelper->prepareAvailableSubscriberAreasForProvider($moduleName, $subscribers); |
||
| 112 | $templateParameters['hookSubscribers'] = $hookSubscribers; |
||
| 113 | $templateParameters['amountOfAvailableSubscriberAreas'] = $amountOfAvailableSubscriberAreas; |
||
| 114 | } else { |
||
| 115 | $templateParameters['amountOfAvailableSubscriberAreas'] = 0; |
||
| 116 | } |
||
| 117 | |||
| 118 | // get providers that are already attached to the subscriber |
||
| 119 | // and providers that can attach to the subscriber |
||
| 120 | if ($isSubscriber && !empty($subscriberAreas)) { |
||
| 121 | // get current sorting |
||
| 122 | [$currentSorting, $currentSortingTitles, $amountOfAttachedProviderAreas] = $hookUiHelper->prepareAttachedProvidersForSubscriber($subscriberAreas, $providers); |
||
| 123 | $templateParameters['areasSorting'] = $currentSorting; |
||
| 124 | $templateParameters['areasSortingTitles'] = $currentSortingTitles; |
||
| 125 | $templateParameters['amountOfAttachedProviderAreas'] = $amountOfAttachedProviderAreas; |
||
| 126 | |||
| 127 | [$hookProviders, $amountOfAvailableProviderAreas] = $hookUiHelper->prepareAvailableProviderAreasForSubscriber($moduleName, $providers, $isSubscriberSelfCapable); |
||
| 128 | $templateParameters['hookProviders'] = $hookProviders; |
||
| 129 | $templateParameters['amountOfAvailableProviderAreas'] = $amountOfAvailableProviderAreas; |
||
| 130 | } else { |
||
| 131 | $templateParameters['hookProviders'] = []; |
||
| 132 | } |
||
| 133 | $templateParameters['hookDispatcher'] = $dispatcher; |
||
| 134 | $request = $requestStack->getCurrentRequest(); |
||
| 135 | $request->attributes->set('_zkModule', $moduleName); |
||
| 136 | $request->attributes->set('_zkType', 'admin'); |
||
| 137 | $request->attributes->set('_zkFunc', 'Hooks'); |
||
| 138 | |||
| 139 | return $templateParameters; |
||
| 140 | } |
||
| 274 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.