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 |
||
23 | class Context |
||
24 | { |
||
25 | /** |
||
26 | * @var \Aimeos\MShop\Context\Item\Iface |
||
27 | */ |
||
28 | private static $context; |
||
29 | |||
30 | /** |
||
31 | * @var \Illuminate\Contracts\Config\Repository |
||
32 | */ |
||
33 | private $config; |
||
34 | |||
35 | /** |
||
36 | * @var \Aimeos\MShop\Locale\Item\Iface |
||
37 | */ |
||
38 | private $locale; |
||
39 | |||
40 | /** |
||
41 | * @var \Illuminate\Session\Store |
||
42 | */ |
||
43 | private $session; |
||
44 | |||
45 | |||
46 | /** |
||
47 | * Initializes the object |
||
48 | * |
||
49 | * @param \Illuminate\Contracts\Config\Repository $config Configuration object |
||
50 | * @param \Illuminate\Session\Store $session Laravel session object |
||
51 | */ |
||
52 | public function __construct( \Illuminate\Contracts\Config\Repository $config, \Illuminate\Session\Store $session ) |
||
57 | |||
58 | |||
59 | /** |
||
60 | * Returns the current context |
||
61 | * |
||
62 | * @param boolean $locale True to add locale object to context, false if not |
||
63 | * @return \Aimeos\MShop\Context\Item\Iface Context object |
||
64 | */ |
||
65 | public function get( $locale = true ) |
||
110 | |||
111 | |||
112 | /** |
||
113 | * Adds the user ID and name if available |
||
114 | * |
||
115 | * @param \Aimeos\MShop\Context\Item\Iface $context Context object |
||
116 | */ |
||
117 | protected function addUser( \Aimeos\MShop\Context\Item\Iface $context ) |
||
133 | |||
134 | |||
135 | /** |
||
136 | * Creates a new configuration object. |
||
137 | * |
||
138 | * @return \Aimeos\MW\Config\Iface Configuration object |
||
139 | */ |
||
140 | protected function getConfig() |
||
153 | |||
154 | |||
155 | /** |
||
156 | * Returns the locale item for the current request |
||
157 | * |
||
158 | * @param \Aimeos\MShop\Context\Item\Iface $context Context object |
||
159 | * @return \Aimeos\MShop\Locale\Item\Iface Locale item object |
||
160 | */ |
||
161 | protected function getLocale( \Aimeos\MShop\Context\Item\Iface $context ) |
||
185 | } |
||
186 |
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: