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 |
||
14 | class LegacyDriver implements Driver |
||
15 | { |
||
16 | |||
17 | /** @var \Buttress\Concrete\Client\Connection\Connection */ |
||
18 | private $connection; |
||
19 | |||
20 | /** @var \Buttress\Concrete\Service\Package\PackageItemFactory */ |
||
21 | private $factory; |
||
22 | |||
23 | public function __construct(Connection $connection, PackageItemFactory $factory) |
||
28 | |||
29 | /** |
||
30 | * @param \Buttress\Concrete\Service\Package\PackageItem $item |
||
31 | * @return Package|null |
||
32 | */ |
||
33 | private function getPackage(PackageItem $item) |
||
40 | |||
41 | /** |
||
42 | * Install a package |
||
43 | * |
||
44 | * @param \Buttress\Concrete\Service\Package\PackageItem $item |
||
45 | * @return \Buttress\Concrete\Service\Result |
||
46 | */ |
||
47 | public function install(PackageItem $item) |
||
78 | |||
79 | /** |
||
80 | * Uninstall a package |
||
81 | * |
||
82 | * @param PackageItem $item |
||
83 | * @return \Buttress\Concrete\Service\Result |
||
84 | */ |
||
85 | public function uninstall(PackageItem $item) |
||
110 | |||
111 | /** |
||
112 | * Test a package for install |
||
113 | * |
||
114 | * @param PackageItem $package |
||
115 | * @return \Buttress\Concrete\Service\Result |
||
116 | */ |
||
117 | public function test(PackageItem $package) |
||
132 | |||
133 | /** |
||
134 | * Show information about a package |
||
135 | * |
||
136 | * @param PackageItem $package |
||
137 | * @return \Buttress\Concrete\Service\Result |
||
138 | */ |
||
139 | View Code Duplication | public function show(PackageItem $package, CLImate $cli) |
|
149 | |||
150 | /** |
||
151 | * Get a list of package item objects |
||
152 | * @return PackageItem[] |
||
153 | * @throws \Buttress\Concrete\Exception\RuntimeException |
||
154 | */ |
||
155 | public function all() |
||
167 | } |
||
168 |
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: