| Conditions | 10 |
| Paths | 34 |
| Total Lines | 67 |
| 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 |
||
| 48 | public function menu(FactoryInterface $factory, array $options) |
||
| 49 | { |
||
| 50 | $menu = $factory->createItem('itemActions'); |
||
| 51 | if (!isset($options['entity']) || !isset($options['area']) || !isset($options['context'])) { |
||
| 52 | return $menu; |
||
| 53 | } |
||
| 54 | |||
| 55 | $this->setTranslator($this->container->get('translator.default')); |
||
| 56 | |||
| 57 | $entity = $options['entity']; |
||
| 58 | $routeArea = $options['area']; |
||
| 59 | $context = $options['context']; |
||
| 60 | |||
| 61 | $permissionApi = $this->container->get('zikula_permissions_module.api.permission'); |
||
| 62 | $currentUserApi = $this->container->get('zikula_users_module.current_user'); |
||
| 63 | $menu->setChildrenAttribute('class', 'list-inline'); |
||
| 64 | |||
| 65 | if ($entity instanceof RouteEntity) { |
||
| 66 | $component = 'ZikulaRoutesModule:Route:'; |
||
| 67 | $instance = $entity['id'] . '::'; |
||
| 68 | $routePrefix = 'zikularoutesmodule_route_'; |
||
| 69 | |||
| 70 | if ($routeArea == 'admin') { |
||
| 71 | $menu->addChild($this->__('Preview'), [ |
||
| 72 | 'route' => $routePrefix . 'display', |
||
| 73 | 'routeParameters' => ['id' => $entity['id']] |
||
| 74 | ])->setAttribute('icon', 'fa fa-search-plus'); |
||
| 75 | $menu[$this->__('Preview')]->setLinkAttribute('target', '_blank'); |
||
| 76 | $menu[$this->__('Preview')]->setLinkAttribute('title', $this->__('Open preview page')); |
||
| 77 | } |
||
| 78 | if ($context != 'display') { |
||
| 79 | $menu->addChild($this->__('Details'), [ |
||
| 80 | 'route' => $routePrefix . $routeArea . 'display', |
||
| 81 | 'routeParameters' => ['id' => $entity['id']] |
||
| 82 | ])->setAttribute('icon', 'fa fa-eye'); |
||
| 83 | $menu[$this->__('Details')]->setLinkAttribute('title', str_replace('"', '', $entity->getTitleFromDisplayPattern())); |
||
| 84 | } |
||
| 85 | if ($permissionApi->hasPermission($component, $instance, ACCESS_EDIT)) { |
||
| 86 | $menu->addChild($this->__('Edit'), [ |
||
| 87 | 'route' => $routePrefix . $routeArea . 'edit', |
||
| 88 | 'routeParameters' => ['id' => $entity['id']] |
||
| 89 | ])->setAttribute('icon', 'fa fa-pencil-square-o'); |
||
| 90 | $menu[$this->__('Edit')]->setLinkAttribute('title', $this->__('Edit this route')); |
||
| 91 | $menu->addChild($this->__('Reuse'), [ |
||
| 92 | 'route' => $routePrefix . $routeArea . 'edit', |
||
| 93 | 'routeParameters' => ['astemplate' => $entity['id']] |
||
| 94 | ])->setAttribute('icon', 'fa fa-files-o'); |
||
| 95 | $menu[$this->__('Reuse')]->setLinkAttribute('title', $this->__('Reuse for new route')); |
||
| 96 | } |
||
| 97 | if ($permissionApi->hasPermission($component, $instance, ACCESS_DELETE)) { |
||
| 98 | $menu->addChild($this->__('Delete'), [ |
||
| 99 | 'route' => $routePrefix . $routeArea . 'delete', |
||
| 100 | 'routeParameters' => ['id' => $entity['id']] |
||
| 101 | ])->setAttribute('icon', 'fa fa-trash-o'); |
||
| 102 | $menu[$this->__('Delete')]->setLinkAttribute('title', $this->__('Delete this route')); |
||
| 103 | } |
||
| 104 | if ($context == 'display') { |
||
| 105 | $title = $this->__('Back to overview'); |
||
| 106 | $menu->addChild($title, [ |
||
| 107 | 'route' => $routePrefix . $routeArea . 'view' |
||
| 108 | ])->setAttribute('icon', 'fa fa-reply'); |
||
| 109 | $menu[$title]->setLinkAttribute('title', $title); |
||
| 110 | } |
||
| 111 | } |
||
| 112 | |||
| 113 | return $menu; |
||
| 114 | } |
||
| 115 | } |
||
| 116 |
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..