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 |
||
20 | class Command extends BaseCommand |
||
21 | { |
||
22 | const CONFIG_FILE = 'config.yml'; |
||
23 | |||
24 | /** |
||
25 | * @var Filesystem |
||
26 | */ |
||
27 | protected $fs; |
||
28 | /** |
||
29 | * @var string |
||
30 | */ |
||
31 | protected $path; |
||
32 | /** |
||
33 | * @var Builder |
||
34 | */ |
||
35 | protected $builder; |
||
36 | /** |
||
37 | * @var ProgressBar |
||
38 | */ |
||
39 | protected $progressBar = null; |
||
40 | |||
41 | /** |
||
42 | * {@inheritdoc} |
||
43 | */ |
||
44 | protected function initialize(InputInterface $input, OutputInterface $output) |
||
72 | |||
73 | /** |
||
74 | * {@inheritdoc} |
||
75 | */ |
||
76 | protected function interact(InputInterface $input, OutputInterface $output) |
||
80 | |||
81 | /** |
||
82 | * Return the working directory. |
||
83 | * |
||
84 | * @return string |
||
85 | */ |
||
86 | public function getPath() |
||
90 | |||
91 | /** |
||
92 | * Create or return a Builder instance. |
||
93 | * |
||
94 | * @param OutputInterface $output |
||
95 | * @param array $config |
||
96 | * @param array $options |
||
97 | * |
||
98 | * @return Builder |
||
99 | */ |
||
100 | public function getBuilder( |
||
122 | |||
123 | /** |
||
124 | * Create the Progress bar. |
||
125 | * |
||
126 | * @param OutputInterface $output |
||
127 | * @param int $start |
||
128 | * @param int $max |
||
129 | * |
||
130 | * @return ProgressBar |
||
131 | */ |
||
132 | protected function createProgressBar(OutputInterface $output, $start, $max) |
||
146 | |||
147 | /** |
||
148 | * Return Progress Bar. |
||
149 | * |
||
150 | * @return ProgressBar |
||
151 | */ |
||
152 | protected function getProgressBar() |
||
156 | |||
157 | /** |
||
158 | * Print the Progress Bar. |
||
159 | * |
||
160 | * @param OutputInterface $output |
||
161 | * @param int $itemsCount |
||
162 | * @param int $itemsMax |
||
163 | * @param string $message |
||
164 | */ |
||
165 | protected function printProgressBar(OutputInterface $output, $itemsCount, $itemsMax, $message) |
||
176 | |||
177 | /** |
||
178 | * Custom message callback function. |
||
179 | * |
||
180 | * @param OutputInterface $output |
||
181 | */ |
||
182 | public function messageCallback(OutputInterface $output) |
||
213 | } |
||
214 |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.