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 |
||
11 | class LegacyDriver implements Driver |
||
12 | { |
||
13 | |||
14 | /** @var \Buttress\Concrete\Client\Connection\Connection */ |
||
15 | private $connection; |
||
16 | |||
17 | /** @var \Buttress\Concrete\Service\Package\PackageItemFactory */ |
||
18 | private $factory; |
||
19 | |||
20 | public function __construct(Connection $connection, PackageItemFactory $factory) |
||
25 | |||
26 | /** |
||
27 | * @param \Buttress\Concrete\Service\Package\PackageItem $package |
||
28 | * @return Package|null |
||
29 | */ |
||
30 | private function getPackage(PackageItem $package) |
||
35 | |||
36 | /** |
||
37 | * Install a package |
||
38 | * |
||
39 | * @param \Buttress\Concrete\Service\Package\PackageItem $item |
||
40 | * @return \Buttress\Concrete\Service\Result |
||
41 | */ |
||
42 | public function install(PackageItem $item) |
||
69 | |||
70 | /** |
||
71 | * Uninstall a package |
||
72 | * |
||
73 | * @param PackageItem $item |
||
74 | * @return \Buttress\Concrete\Service\Result |
||
75 | */ |
||
76 | public function uninstall(PackageItem $item) |
||
94 | |||
95 | /** |
||
96 | * Test a package for install |
||
97 | * |
||
98 | * @param PackageItem $package |
||
99 | * @return \Buttress\Concrete\Service\Result |
||
100 | */ |
||
101 | public function test(PackageItem $package) |
||
116 | |||
117 | /** |
||
118 | * Show information about a package |
||
119 | * |
||
120 | * @param PackageItem $package |
||
121 | * @return \Buttress\Concrete\Service\Result |
||
122 | */ |
||
123 | View Code Duplication | public function show(PackageItem $package, CLImate $cli) |
|
133 | |||
134 | /** |
||
135 | * Get a list of package item objects |
||
136 | * @return PackageItem[] |
||
137 | */ |
||
138 | public function all() |
||
150 | } |
||
151 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..