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; |
||
| 16 | class MenuServiceProvider extends ServiceProvider |
||
| 17 | { |
||
| 18 | /** |
||
| 19 | * Indicates if loading of the provider is deferred. |
||
| 20 | * |
||
| 21 | * @var bool |
||
| 22 | */ |
||
| 23 | protected $defer = false; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * Register the service provider. |
||
| 27 | * |
||
| 28 | * @return void |
||
| 29 | */ |
||
| 30 | public function register() |
||
| 34 | |||
| 35 | /** |
||
| 36 | * Register all online menus on the Pingpong/Menu package |
||
| 37 | */ |
||
| 38 | public function boot() |
||
| 42 | |||
| 43 | /** |
||
| 44 | * Get the services provided by the provider. |
||
| 45 | * |
||
| 46 | * @return array |
||
| 47 | */ |
||
| 48 | public function provides() |
||
| 52 | |||
| 53 | /** |
||
| 54 | * Register class binding |
||
| 55 | */ |
||
| 56 | private function registerBindings() |
||
| 84 | |||
| 85 | /** |
||
| 86 | * Add a menu item to the menu |
||
| 87 | * @param Menuitem $item |
||
| 88 | * @param Builder $menu |
||
| 89 | */ |
||
| 90 | public function addItemToMenu(Menuitem $item, Builder $menu) |
||
| 104 | |||
| 105 | /** |
||
| 106 | * Add children to menu under the give name |
||
| 107 | * |
||
| 108 | * @param string $name |
||
| 109 | * @param object $children |
||
| 110 | * @param Builder|MenuItem $menu |
||
| 111 | */ |
||
| 112 | private function addChildrenToMenu($name, $children, $menu, $attribs = []) |
||
| 120 | |||
| 121 | /** |
||
| 122 | * Add children to the given menu recursively |
||
| 123 | * @param Menuitem $child |
||
| 124 | * @param PingpongMenuItem $sub |
||
| 125 | */ |
||
| 126 | private function addSubItemToMenu(Menuitem $child, PingpongMenuItem $sub) |
||
| 135 | |||
| 136 | /** |
||
| 137 | * Check if the given menu item has children |
||
| 138 | * |
||
| 139 | * @param object $item |
||
| 140 | * @return bool |
||
| 141 | */ |
||
| 142 | private function hasChildren($item) |
||
| 146 | |||
| 147 | /** |
||
| 148 | * Register the active menus |
||
| 149 | */ |
||
| 150 | private function registerMenus() |
||
| 166 | |||
| 167 | /** |
||
| 168 | * Get link target |
||
| 169 | * |
||
| 170 | * @param $item |
||
| 171 | * @return mixed |
||
| 172 | */ |
||
| 173 | private function getTarget($item) |
||
| 211 | |||
| 212 | /** |
||
| 213 | * Get parent item |
||
| 214 | * |
||
| 215 | * @param $item |
||
| 216 | * @return mixed |
||
| 217 | */ |
||
| 218 | /*private function getParentItem($item){ |
||
| 219 | // \Debugbar::info($item->parent_id); |
||
| 220 | //Menuitem::where('id','=',$item->parent_id); |
||
| 221 | |||
| 222 | return $target; |
||
| 223 | }*/ |
||
| 224 | } |
||
| 225 |
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: