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 SelfLinkTrait; |
||
| 20 | use MetaTrait; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * The resource type. |
||
| 24 | * |
||
| 25 | * @var string |
||
| 26 | */ |
||
| 27 | protected $type; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * {@inheritdoc} |
||
| 31 | */ |
||
| 32 | public function getType() |
||
| 36 | |||
| 37 | /** |
||
| 38 | * {@inheritdoc} |
||
| 39 | */ |
||
| 40 | public function getAttributes(array $fields = null) |
||
| 44 | |||
| 45 | /** |
||
| 46 | * {@inheritdoc} |
||
| 47 | * |
||
| 48 | * @throws \LogicException |
||
| 49 | */ |
||
| 50 | public function getRelationship($name) |
||
| 64 | |||
| 65 | /** |
||
| 66 | * Get the method name for the given relationship. |
||
| 67 | * |
||
| 68 | * snake_case and kebab-case are converted into camelCase. |
||
| 69 | * |
||
| 70 | * @param string $name |
||
| 71 | * |
||
| 72 | * @return string |
||
| 73 | */ |
||
| 74 | private function getRelationshipMethodName($name) |
||
| 86 | } |
||
| 87 |
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.