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 |
||
21 | class AnemicNetworkPost implements NetworkPost |
||
22 | { |
||
23 | const POST_TYPE_QUESTION = 'question'; |
||
24 | const POST_TYPE_ANSWER = 'answer'; |
||
25 | |||
26 | private $id; |
||
27 | private $postType; |
||
28 | private $score; |
||
29 | private $title; |
||
30 | |||
31 | public static function fromProperties($id, $postType, $score, $title) |
||
35 | |||
36 | public static function fromJson($data) |
||
45 | |||
46 | private function __construct($id = null, $postType = null, $score = null, $title = null) |
||
53 | |||
54 | public function getId() |
||
58 | |||
59 | public function setId($id) |
||
65 | |||
66 | public function getPostType() |
||
70 | |||
71 | View Code Duplication | public function setPostType($postType) |
|
79 | |||
80 | public function getScore() |
||
84 | |||
85 | public function setScore($score) |
||
91 | |||
92 | public function getTitle() |
||
96 | |||
97 | public function setTitle($title) |
||
103 | } |
||
104 |
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@return
annotation as described here.