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 |
||
16 | abstract class AbstractResource implements ResourceInterface |
||
17 | { |
||
18 | use LinksTrait; |
||
19 | use MetaTrait; |
||
20 | |||
21 | /** |
||
22 | * The resource type. |
||
23 | * |
||
24 | * @var string |
||
25 | */ |
||
26 | protected $type; |
||
27 | |||
28 | /** |
||
29 | * {@inheritdoc} |
||
30 | */ |
||
31 | public function getType() |
||
35 | |||
36 | /** |
||
37 | * {@inheritdoc} |
||
38 | */ |
||
39 | public function getAttributes(array $fields = null) |
||
43 | |||
44 | /** |
||
45 | * {@inheritdoc} |
||
46 | * |
||
47 | * @throws \LogicException |
||
48 | */ |
||
49 | public function getRelationship($name) |
||
63 | |||
64 | /** |
||
65 | * Get the method name for the given relationship. |
||
66 | * |
||
67 | * snake_case and kebab-case are converted into camelCase. |
||
68 | * |
||
69 | * @param string $name |
||
70 | * |
||
71 | * @return string |
||
72 | */ |
||
73 | private function getRelationshipMethodName($name) |
||
85 | } |
||
86 |
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.