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 |
||
10 | class JsonapiObject implements ObjectInterface { |
||
|
|||
11 | use AtMemberManager; |
||
12 | |||
13 | /** @var string */ |
||
14 | protected $version; |
||
15 | /** @var MetaObject */ |
||
16 | protected $meta; |
||
17 | |||
18 | /** |
||
19 | * @param string $version one of the Document::JSONAPI_VERSION_* constants, optional, defaults to Document::JSONAPI_VERSION_LATEST |
||
20 | */ |
||
21 | public function __construct($version=Document::JSONAPI_VERSION_LATEST) { |
||
26 | |||
27 | /** |
||
28 | * human api |
||
29 | */ |
||
30 | |||
31 | /** |
||
32 | * @param string $key |
||
33 | * @param mixed $value |
||
34 | */ |
||
35 | public function addMeta($key, $value) { |
||
42 | |||
43 | /** |
||
44 | * spec api |
||
45 | */ |
||
46 | |||
47 | /** |
||
48 | * @param string $version |
||
49 | */ |
||
50 | public function setVersion($version) { |
||
53 | |||
54 | /** |
||
55 | * @param MetaObject $metaObject |
||
56 | */ |
||
57 | public function setMetaObject(MetaObject $metaObject) { |
||
60 | |||
61 | /** |
||
62 | * ObjectInterface |
||
63 | */ |
||
64 | |||
65 | /** |
||
66 | * @inheritDoc |
||
67 | */ |
||
68 | View Code Duplication | public function isEmpty() { |
|
81 | |||
82 | /** |
||
83 | * @inheritDoc |
||
84 | */ |
||
85 | View Code Duplication | public function toArray() { |
|
97 | } |
||
98 |