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 |
||
22 | View Code Duplication | class AppAlbum extends Album |
|
|
|||
23 | { |
||
24 | /** |
||
25 | * Application field. Corresponds to the file type of application. |
||
26 | * In the thml form field should also be called. |
||
27 | * Can have the values according with the selected type of: |
||
28 | * FileSetter::INSERTED_DATA_ID |
||
29 | * FileSetter::INSERTED_DATA_URL |
||
30 | * |
||
31 | * @var array application(array of 'mediafile id' or 'mediafile url'). |
||
32 | */ |
||
33 | public $application; |
||
34 | |||
35 | /** |
||
36 | * {@inheritdoc} |
||
37 | */ |
||
38 | public function rules() |
||
52 | |||
53 | /** |
||
54 | * @inheritdoc |
||
55 | */ |
||
56 | public function behaviors() |
||
69 | |||
70 | /** |
||
71 | * Get album's application files. |
||
72 | * |
||
73 | * @return ActiveRecord[] |
||
74 | */ |
||
75 | public function getAppFiles() |
||
79 | } |
||
80 |
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.