| Conditions | 18 |
| Paths | 885 |
| Total Lines | 109 |
| Code Lines | 85 |
| Lines | 56 |
| Ratio | 51.38 % |
| 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 |
||
| 47 | public function menu(FactoryInterface $factory, array $options) |
||
| 48 | { |
||
| 49 | $menu = $factory->createItem('itemActions'); |
||
| 50 | if (!isset($options['entity']) || !isset($options['area']) || !isset($options['context'])) { |
||
| 51 | return $menu; |
||
| 52 | } |
||
| 53 | |||
| 54 | $this->setTranslator($this->container->get('translator')); |
||
| 55 | |||
| 56 | $entity = $options['entity']; |
||
| 57 | $area = $options['area']; |
||
| 58 | $context = $options['context']; |
||
| 59 | |||
| 60 | $permissionApi = $this->container->get('zikula_permissions_module.api.permission'); |
||
| 61 | $currentUserApi = $this->container->get('zikula_users_module.current_user'); |
||
| 62 | $menu->setChildrenAttribute('class', 'list-inline'); |
||
| 63 | |||
| 64 | |||
| 65 | $currentLegacyControllerType = $area != '' ? $area : 'user'; |
||
| 66 | $currentFunc = $context; |
||
| 67 | |||
| 68 | if ($entity instanceof RouteEntity) { |
||
| 69 | $component = 'ZikulaRoutesModule:Route:'; |
||
| 70 | $instance = $entity['id'] . '::'; |
||
| 71 | |||
| 72 | if ($currentLegacyControllerType == 'admin') { |
||
| 73 | if (in_array($currentFunc, ['index', 'view'])) { |
||
| 74 | $menu->addChild($this->__('Preview'), [ |
||
| 75 | 'route' => 'zikularoutesmodule_route_display', |
||
| 76 | 'routeParameters' => ['id' => $entity['id']] |
||
| 77 | ])->setAttribute('icon', 'fa fa-search-plus'); |
||
| 78 | $menu[$this->__('Preview')]->setLinkAttribute('target', '_blank'); |
||
| 79 | $menu[$this->__('Preview')]->setLinkAttribute('title', $this->__('Open preview page')); |
||
| 80 | $menu->addChild($this->__('Details'), [ |
||
| 81 | 'route' => 'zikularoutesmodule_route_admindisplay', |
||
| 82 | 'routeParameters' => ['id' => $entity['id']] |
||
| 83 | ])->setAttribute('icon', 'fa fa-eye'); |
||
| 84 | $menu[$this->__('Details')]->setLinkAttribute('title', str_replace('"', '', $entity->getTitleFromDisplayPattern())); |
||
| 85 | } |
||
| 86 | View Code Duplication | if (in_array($currentFunc, ['index', 'view', 'display'])) { |
|
| 87 | if ($permissionApi->hasPermission($component, $instance, ACCESS_EDIT)) { |
||
| 88 | $menu->addChild($this->__('Edit'), [ |
||
| 89 | 'route' => 'zikularoutesmodule_route_adminedit', |
||
| 90 | 'routeParameters' => ['id' => $entity['id']] |
||
| 91 | ])->setAttribute('icon', 'fa fa-pencil-square-o'); |
||
| 92 | $menu[$this->__('Edit')]->setLinkAttribute('title', $this->__('Edit this route')); |
||
| 93 | $menu->addChild($this->__('Reuse'), [ |
||
| 94 | 'route' => 'zikularoutesmodule_route_adminedit', |
||
| 95 | 'routeParameters' => ['astemplate' => $entity['id']] |
||
| 96 | ])->setAttribute('icon', 'fa fa-files-o'); |
||
| 97 | $menu[$this->__('Reuse')]->setLinkAttribute('title', $this->__('Reuse for new route')); |
||
| 98 | } |
||
| 99 | if ($permissionApi->hasPermission($component, $instance, ACCESS_DELETE)) { |
||
| 100 | $menu->addChild($this->__('Delete'), [ |
||
| 101 | 'route' => 'zikularoutesmodule_route_admindelete', |
||
| 102 | 'routeParameters' => ['id' => $entity['id']] |
||
| 103 | ])->setAttribute('icon', 'fa fa-trash-o'); |
||
| 104 | $menu[$this->__('Delete')]->setLinkAttribute('title', $this->__('Delete this route')); |
||
| 105 | } |
||
| 106 | } |
||
| 107 | View Code Duplication | if ($currentFunc == 'display') { |
|
| 108 | $title = $this->__('Back to overview'); |
||
| 109 | $menu->addChild($title, [ |
||
| 110 | 'route' => 'zikularoutesmodule_route_adminview' |
||
| 111 | ])->setAttribute('icon', 'fa fa-reply'); |
||
| 112 | $menu[$title]->setLinkAttribute('title', $title); |
||
| 113 | } |
||
| 114 | } |
||
| 115 | if ($currentLegacyControllerType == 'user') { |
||
| 116 | if (in_array($currentFunc, ['index', 'view'])) { |
||
| 117 | $menu->addChild($this->__('Details'), [ |
||
| 118 | 'route' => 'zikularoutesmodule_route_display', |
||
| 119 | 'routeParameters' => ['id' => $entity['id']] |
||
| 120 | ])->setAttribute('icon', 'fa fa-eye'); |
||
| 121 | $menu[$this->__('Details')]->setLinkAttribute('title', str_replace('"', '', $entity->getTitleFromDisplayPattern())); |
||
| 122 | } |
||
| 123 | View Code Duplication | if (in_array($currentFunc, ['index', 'view', 'display'])) { |
|
| 124 | if ($permissionApi->hasPermission($component, $instance, ACCESS_EDIT)) { |
||
| 125 | $menu->addChild($this->__('Edit'), [ |
||
| 126 | 'route' => 'zikularoutesmodule_route_edit', |
||
| 127 | 'routeParameters' => ['id' => $entity['id']] |
||
| 128 | ])->setAttribute('icon', 'fa fa-pencil-square-o'); |
||
| 129 | $menu[$this->__('Edit')]->setLinkAttribute('title', $this->__('Edit this route')); |
||
| 130 | $menu->addChild($this->__('Reuse'), [ |
||
| 131 | 'route' => 'zikularoutesmodule_route_edit', |
||
| 132 | 'routeParameters' => ['astemplate' => $entity['id']] |
||
| 133 | ])->setAttribute('icon', 'fa fa-files-o'); |
||
| 134 | $menu[$this->__('Reuse')]->setLinkAttribute('title', $this->__('Reuse for new route')); |
||
| 135 | } |
||
| 136 | if ($permissionApi->hasPermission($component, $instance, ACCESS_DELETE)) { |
||
| 137 | $menu->addChild($this->__('Delete'), [ |
||
| 138 | 'route' => 'zikularoutesmodule_route_delete', |
||
| 139 | 'routeParameters' => ['id' => $entity['id']] |
||
| 140 | ])->setAttribute('icon', 'fa fa-trash-o'); |
||
| 141 | $menu[$this->__('Delete')]->setLinkAttribute('title', $this->__('Delete this route')); |
||
| 142 | } |
||
| 143 | } |
||
| 144 | View Code Duplication | if ($currentFunc == 'display') { |
|
| 145 | $title = $this->__('Back to overview'); |
||
| 146 | $menu->addChild($title, [ |
||
| 147 | 'route' => 'zikularoutesmodule_route_view' |
||
| 148 | ])->setAttribute('icon', 'fa fa-reply'); |
||
| 149 | $menu[$title]->setLinkAttribute('title', $title); |
||
| 150 | } |
||
| 151 | } |
||
| 152 | } |
||
| 153 | |||
| 154 | return $menu; |
||
| 155 | } |
||
| 156 | } |
||
| 157 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..