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) |
||
| 81 | |||
| 82 | /** |
||
| 83 | * Uninstall a package |
||
| 84 | * |
||
| 85 | * @param PackageItem $item |
||
| 86 | * @return \Buttress\Concrete\Service\Result |
||
| 87 | */ |
||
| 88 | public function uninstall(PackageItem $item) |
||
| 113 | |||
| 114 | /** |
||
| 115 | * Test a package for install |
||
| 116 | * |
||
| 117 | * @param PackageItem $package |
||
| 118 | * @return \Buttress\Concrete\Service\Result |
||
| 119 | */ |
||
| 120 | public function test(PackageItem $package) |
||
| 135 | |||
| 136 | /** |
||
| 137 | * Show information about a package |
||
| 138 | * |
||
| 139 | * @param PackageItem $package |
||
| 140 | * @return \Buttress\Concrete\Service\Result |
||
| 141 | */ |
||
| 142 | View Code Duplication | public function show(PackageItem $package, CLImate $cli) |
|
| 152 | |||
| 153 | /** |
||
| 154 | * Get a list of package item objects |
||
| 155 | * @return PackageItem[] |
||
| 156 | * @throws \Buttress\Concrete\Exception\RuntimeException |
||
| 157 | */ |
||
| 158 | public function all() |
||
| 170 | } |
||
| 171 |
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: