Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php namespace Modules\Menu\Providers; |
||
15 | class MenuServiceProvider extends ServiceProvider |
||
16 | { |
||
17 | /** |
||
18 | * Indicates if loading of the provider is deferred. |
||
19 | * |
||
20 | * @var bool |
||
21 | */ |
||
22 | protected $defer = false; |
||
23 | |||
24 | /** |
||
25 | * Register the service provider. |
||
26 | * |
||
27 | * @return void |
||
28 | */ |
||
29 | public function register() |
||
33 | |||
34 | /** |
||
35 | * Register all online menus on the Pingpong/Menu package |
||
36 | */ |
||
37 | public function boot() |
||
41 | |||
42 | /** |
||
43 | * Get the services provided by the provider. |
||
44 | * |
||
45 | * @return array |
||
46 | */ |
||
47 | public function provides() |
||
51 | |||
52 | /** |
||
53 | * Register class binding |
||
54 | */ |
||
55 | private function registerBindings() |
||
83 | |||
84 | /** |
||
85 | * Add a menu item to the menu |
||
86 | * @param Menuitem $item |
||
87 | * @param Builder $menu |
||
88 | */ |
||
89 | public function addItemToMenu(Menuitem $item, Builder $menu) |
||
103 | |||
104 | /** |
||
105 | * Add children to menu under the give name |
||
106 | * |
||
107 | * @param string $name |
||
108 | * @param object $children |
||
109 | * @param Builder|MenuItem $menu |
||
110 | */ |
||
111 | private function addChildrenToMenu($name, $children, $menu, $attribs = []) |
||
119 | |||
120 | /** |
||
121 | * Add children to the given menu recursively |
||
122 | * @param Menuitem $child |
||
123 | * @param PingpongMenuItem $sub |
||
124 | */ |
||
125 | View Code Duplication | private function addSubItemToMenu(Menuitem $child, PingpongMenuItem $sub) |
|
134 | |||
135 | /** |
||
136 | * Check if the given menu item has children |
||
137 | * |
||
138 | * @param object $item |
||
139 | * @return bool |
||
140 | */ |
||
141 | private function hasChildren($item) |
||
145 | |||
146 | /** |
||
147 | * Register the active menus |
||
148 | */ |
||
149 | private function registerMenus() |
||
165 | } |
||
166 |
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: