Conditions | 10 |
Paths | 48 |
Total Lines | 49 |
Code Lines | 25 |
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 |
||
74 | public function generateMenuUrl(AdminInterface $admin, $name, array $parameters = array(), $absolute = UrlGeneratorInterface::ABSOLUTE_PATH) |
||
75 | { |
||
76 | // if the admin is a child we automatically append the parent's id |
||
77 | if ($admin->isChild() && $admin->hasRequest()) { |
||
78 | // twig template does not accept variable hash key ... so cannot use admin.idparameter ... |
||
79 | // switch value |
||
80 | if (isset($parameters['id'])) { |
||
81 | $parameters[$admin->getIdParameter()] = $parameters['id']; |
||
82 | unset($parameters['id']); |
||
83 | } |
||
84 | |||
85 | for ($parentAdmin = $admin->getParent(); null !== $parentAdmin; $parentAdmin = $parentAdmin->getParent()) { |
||
86 | $parameters[$parentAdmin->getIdParameter()] = $admin->getRequest()->attributes->get($parentAdmin->getIdParameter()); |
||
87 | } |
||
88 | } |
||
89 | |||
90 | // if the admin is linked to a parent FieldDescription (ie, embedded widget) |
||
91 | if ($admin->hasParentFieldDescription()) { |
||
92 | // merge link parameter if any provided by the parent field |
||
93 | $parameters = array_merge($parameters, $admin->getParentFieldDescription()->getOption('link_parameters', array())); |
||
94 | |||
95 | $parameters['uniqid'] = $admin->getUniqid(); |
||
96 | $parameters['code'] = $admin->getCode(); |
||
97 | $parameters['pcode'] = $admin->getParentFieldDescription()->getAdmin()->getCode(); |
||
98 | $parameters['puniqid'] = $admin->getParentFieldDescription()->getAdmin()->getUniqid(); |
||
99 | } |
||
100 | |||
101 | if ($name == 'update' || substr($name, -7) == '|update') { |
||
102 | $parameters['uniqid'] = $admin->getUniqid(); |
||
103 | $parameters['code'] = $admin->getCode(); |
||
104 | } |
||
105 | |||
106 | // allows to define persistent parameters |
||
107 | if ($admin->hasRequest()) { |
||
108 | $parameters = array_merge($admin->getPersistentParameters(), $parameters); |
||
109 | } |
||
110 | |||
111 | $code = $this->getCode($admin, $name); |
||
112 | |||
113 | if (!array_key_exists($code, $this->caches)) { |
||
114 | throw new \RuntimeException(sprintf('unable to find the route `%s`', $code)); |
||
115 | } |
||
116 | |||
117 | return array( |
||
118 | 'route' => $this->caches[$code], |
||
119 | 'routeParameters' => $parameters, |
||
120 | 'routeAbsolute' => $absolute, |
||
121 | ); |
||
122 | } |
||
123 | |||
175 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: