| Conditions | 14 |
| Paths | 27 |
| Total Lines | 94 |
| Code Lines | 77 |
| Lines | 56 |
| Ratio | 59.57 % |
| 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 |
||
| 30 | public function adminExtensionsMenu(FactoryInterface $factory, array $options) |
||
| 31 | { |
||
| 32 | $this->setTranslator($this->container->get('translator')); |
||
| 33 | $permissionApi = $this->container->get('zikula_permissions_module.api.permission'); |
||
| 34 | $extension = $options['extension']; |
||
| 35 | $menu = $factory->createItem('adminActions'); |
||
| 36 | $menu->setChildrenAttribute('class', 'list-inline'); |
||
| 37 | |||
| 38 | if (!$permissionApi->hasPermission('ZikulaExtensionsModule::', $extension->getName() . '::' . $extension->getId(), ACCESS_ADMIN)) { |
||
| 39 | return $menu; |
||
| 40 | } |
||
| 41 | |||
| 42 | $csrfToken = $this->container->get('zikula_core.common.csrf_token_handler')->generate(true); |
||
| 43 | |||
| 44 | switch ($extension->getState()) { |
||
| 45 | case ExtensionApi::STATE_ACTIVE: |
||
| 46 | if ($extension->getName() == 'ZikulaPageLockModule' || !\ZikulaKernel::isCoreModule($extension->getName())) { |
||
| 47 | $menu->addChild($this->__f('Deactivate %s', ['%s' => $extension->getDisplayname()]), [ |
||
| 48 | 'route' => 'zikulaextensionsmodule_module_deactivate', |
||
| 49 | 'routeParameters' => ['id' => $extension->getId(), 'csrftoken' => $csrfToken], |
||
| 50 | ])->setAttribute('icon', 'fa fa-minus-circle') |
||
| 51 | ->setLinkAttribute('class', 'text-danger'); |
||
| 52 | // or set style text-color #0c00 |
||
| 53 | } |
||
| 54 | View Code Duplication | if (\PluginUtil::hasModulePlugins($extension->getName())) { |
|
|
|
|||
| 55 | $menu->addChild($this->__f('Plugins for %s', ['%s' => $extension->getDisplayname()]), [ |
||
| 56 | 'route' => 'zikulaextensionsmodule_admin_viewplugins', |
||
| 57 | 'routeParameters' => ['bymodule' => $extension->getName(), |
||
| 58 | 'csrftoken' => $csrfToken], |
||
| 59 | ])->setAttribute('icon', 'fa fa-plug') |
||
| 60 | ->setLinkAttribute('style', 'color:black'); |
||
| 61 | } |
||
| 62 | break; |
||
| 63 | View Code Duplication | case ExtensionApi::STATE_INACTIVE: |
|
| 64 | $menu->addChild($this->__f('Activate %s', ['%s' => $extension->getDisplayname()]), [ |
||
| 65 | 'route' => 'zikulaextensionsmodule_module_activate', |
||
| 66 | 'routeParameters' => ['id' => $extension->getId(), 'csrftoken' => $csrfToken], |
||
| 67 | ])->setAttribute('icon', 'fa fa-plus-square') |
||
| 68 | ->setLinkAttribute('class', 'text-success'); |
||
| 69 | $menu->addChild($this->__f('Uninstall %s', ['%s' => $extension->getDisplayname()]), [ |
||
| 70 | 'route' => 'zikulaextensionsmodule_module_uninstall', |
||
| 71 | 'routeParameters' => ['id' => $extension->getId()], |
||
| 72 | ])->setAttribute('icon', 'fa fa-trash-o') |
||
| 73 | ->setLinkAttribute('style', 'color:#c00'); |
||
| 74 | break; |
||
| 75 | case ExtensionApi::STATE_MISSING: |
||
| 76 | // Nothing to do. |
||
| 77 | break; |
||
| 78 | View Code Duplication | case ExtensionApi::STATE_UPGRADED: |
|
| 79 | $menu->addChild($this->__f('Upgrade %s', ['%s' => $extension->getDisplayname()]), [ |
||
| 80 | 'route' => 'zikulaextensionsmodule_module_upgrade', |
||
| 81 | 'routeParameters' => ['id' => $extension->getId(), 'csrftoken' => $csrfToken], |
||
| 82 | ])->setAttribute('icon', 'fa fa-refresh') |
||
| 83 | ->setLinkAttribute('style', 'color:#00c'); |
||
| 84 | break; |
||
| 85 | case ExtensionApi::STATE_INVALID: |
||
| 86 | // nothing to do. |
||
| 87 | // do not allow deletion of invalid modules if previously installed (#1278) |
||
| 88 | break; |
||
| 89 | View Code Duplication | case ExtensionApi::STATE_NOTALLOWED: |
|
| 90 | $menu->addChild($this->__f('Remove %s', ['%s' => $extension->getDisplayname()]), [ |
||
| 91 | 'route' => 'zikulaextensionsmodule_module_uninstall', |
||
| 92 | 'routeParameters' => ['id' => $extension->getId()], |
||
| 93 | ])->setAttribute('icon', 'fa fa-trash-o') |
||
| 94 | ->setLinkAttribute('style', 'color:#c00'); |
||
| 95 | break; |
||
| 96 | case ExtensionApi::STATE_UNINITIALISED: |
||
| 97 | View Code Duplication | default: |
|
| 98 | if ($extension->getState() < 10) { |
||
| 99 | $menu->addChild($this->__f('Install %s', ['%s' => $extension->getDisplayname()]), [ |
||
| 100 | 'route' => 'zikulaextensionsmodule_module_install', |
||
| 101 | 'routeParameters' => ['id' => $extension->getId()], |
||
| 102 | ])->setAttribute('icon', 'fa fa-cog') |
||
| 103 | ->setLinkAttribute('class', 'text-success'); |
||
| 104 | } else { |
||
| 105 | $menu->addChild($this->__f('Core compatibility information: %s', ['%s' => $extension->getDisplayname()]), [ |
||
| 106 | 'route' => 'zikulaextensionsmodule_module_compatibility', |
||
| 107 | 'routeParameters' => ['id' => $extension->getId()], |
||
| 108 | ])->setAttribute('icon', 'fa fa-info-circle') |
||
| 109 | ->setLinkAttribute('style', 'color:black'); |
||
| 110 | } |
||
| 111 | break; |
||
| 112 | } |
||
| 113 | |||
| 114 | View Code Duplication | if ($extension->getState() != ExtensionApi::STATE_INVALID) { |
|
| 115 | $menu->addChild($this->__f('Edit %s', ['%s' => $extension->getDisplayname()]), [ |
||
| 116 | 'route' => 'zikulaextensionsmodule_module_modify', |
||
| 117 | 'routeParameters' => ['id' => $extension->getId()], |
||
| 118 | ])->setAttribute('icon', 'fa fa-wrench') |
||
| 119 | ->setLinkAttribute('style', 'color:black'); |
||
| 120 | } |
||
| 121 | |||
| 122 | return $menu; |
||
| 123 | } |
||
| 124 | } |
||
| 125 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.