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 |
||
5 | class Module extends CompressableExternalModule |
||
6 | { |
||
7 | /** |
||
8 | * Идентификатор модуля |
||
9 | * @var string |
||
10 | */ |
||
11 | protected $id = 'activerecord'; |
||
12 | |||
13 | /** Database table prefix */ |
||
14 | public $prefix; |
||
15 | |||
16 | /** Database name */ |
||
17 | public $name; |
||
18 | |||
19 | /** Login */ |
||
20 | public $login = 'root'; |
||
21 | |||
22 | /** Password */ |
||
23 | public $pwd; |
||
24 | |||
25 | /** Host */ |
||
26 | public $host = '127.0.0.1'; |
||
27 | |||
28 | /** @var string Port number */ |
||
29 | public $port = ''; |
||
30 | |||
31 | /* Array of additional relations to set */ |
||
32 | public $relations = array(); |
||
33 | |||
34 | /** @see \samson\core\CompressableExternalModule::beforeCompress() */ |
||
35 | public function beforeCompress(& $obj = null, array & $code = null) |
||
39 | |||
40 | /** @see \samson\core\CompressableExternalModule::afterCompress() */ |
||
41 | public function afterCompress(& $obj = null, array & $code = null) |
||
64 | |||
65 | /** @see \samson\core\ExternalModule::prepare() */ |
||
66 | public function prepare() |
||
98 | |||
99 | //[PHPCOMPRESSOR(remove,start)] |
||
100 | public function relations() |
||
104 | //[PHPCOMPRESSOR(remove,end)] |
||
105 | |||
106 | /** @see \samson\core\ExternalModule::init() */ |
||
107 | public function init(array $params = array()) |
||
121 | } |
||
122 |
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.