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 |
||
24 | View Code Duplication | class ArticleCollection extends Collection |
|
|
|||
25 | { |
||
26 | /** |
||
27 | * Идентификатор выпуска |
||
28 | * |
||
29 | * @var int |
||
30 | */ |
||
31 | private $issueId = null; |
||
32 | |||
33 | /** |
||
34 | * BookCollection constructor. |
||
35 | * @param $issueId |
||
36 | * @param Client $client |
||
37 | * @param array $fields |
||
38 | * @param int $limit |
||
39 | * @param int $offset |
||
40 | * @throws Exception |
||
41 | */ |
||
42 | public function __construct($issueId, Client $client, array $fields = array(), $limit = 10, $offset = 0) |
||
48 | |||
49 | /** |
||
50 | * Получение данных для запроса через API |
||
51 | * |
||
52 | * @param string $method Http-метод запроса |
||
53 | * @param array $params Параметры для формирования урла |
||
54 | * |
||
55 | * @return array |
||
56 | * |
||
57 | * @throws Exception |
||
58 | */ |
||
59 | public function getUrl($method, array $params = array()) |
||
72 | } |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.