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 |
||
7 | trait Errors |
||
8 | { |
||
9 | View Code Duplication | public function hasError(ViewErrorBag $errors, $locale = null): bool |
|
21 | |||
22 | View Code Duplication | public function getErrors(ViewErrorBag $errors, $locale = null): array |
|
34 | |||
35 | abstract public function name(string $name = null); |
||
38 | } |
||
39 |
For interface and abstract methods, it is impossible to infer the return type from the immediate code. In these cases, it is generally advisible to explicitly annotate these methods with a
@return
doc comment to communicate to implementors of these methods what they are expected to return.