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 |
||
28 | class Issue extends Model |
||
29 | { |
||
30 | /** |
||
31 | * Номер выпуска |
||
32 | */ |
||
33 | const FIELD_NAME = 'name'; |
||
34 | |||
35 | /** |
||
36 | * Год выпуска |
||
37 | */ |
||
38 | const FIELD_YEAR = 'year'; |
||
39 | |||
40 | /** |
||
41 | * Ссылка на карточку выпуска |
||
42 | */ |
||
43 | const FIELD_URL = 'url'; |
||
44 | |||
45 | /** |
||
46 | * Ссылка на обложку выпуска |
||
47 | */ |
||
48 | const FIELD_THUMB = 'thumb'; |
||
49 | |||
50 | /** |
||
51 | * Конструктор модели пользователя |
||
52 | * |
||
53 | * @param Client $client Инстанс клиента |
||
54 | * @param array $fields Поля для выборки |
||
55 | * |
||
56 | * @throws Exception |
||
57 | */ |
||
58 | public function __construct(Client $client, array $fields = array()) |
||
62 | |||
63 | /** |
||
64 | * Получение данных для запроса через API |
||
65 | * |
||
66 | * @param string $method Http-метод запроса |
||
67 | * @param array $params Параметры для формирования урла |
||
68 | * |
||
69 | * @return array |
||
70 | * |
||
71 | * @throws Exception |
||
72 | */ |
||
73 | View Code Duplication | public function getUrl($method, array $params = array()) |
|
86 | } |
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.