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 |
||
30 | class V2UnitContainer extends \EntityContainer { |
||
31 | /** |
||
32 | * @var V2UnitModel $model |
||
33 | */ |
||
34 | protected $model; |
||
35 | |||
36 | protected static $exceptionClass = 'EntityException'; |
||
37 | protected static $modelClass = 'V2Unit\V2UnitModel'; |
||
38 | |||
39 | /** |
||
40 | * Name of table for this entity |
||
41 | * |
||
42 | * @var string $tableName |
||
43 | */ |
||
44 | protected $tableName = 'unit'; |
||
45 | /** |
||
46 | * Name of key field field in this table |
||
47 | * |
||
48 | * @var string $idField |
||
49 | */ |
||
50 | protected $idField = 'unit_id'; |
||
51 | /** |
||
52 | * Property list |
||
53 | * |
||
54 | * @var array $properties |
||
55 | */ |
||
56 | protected $properties = array( |
||
57 | 'dbId' => array( |
||
58 | P_DB_FIELD => 'unit_id', |
||
59 | ), |
||
60 | 'playerOwnerId' => array( |
||
61 | P_DB_FIELD => 'unit_player_id', |
||
62 | ), |
||
63 | 'locationType' => array( |
||
64 | P_DB_FIELD => 'unit_location_type', |
||
65 | ), |
||
66 | 'locationId' => array( |
||
67 | P_DB_FIELD => 'unit_location_id', |
||
68 | ), |
||
69 | 'type' => array( |
||
70 | P_DB_FIELD => 'unit_type', |
||
71 | ), |
||
72 | 'snId' => array( |
||
73 | P_DB_FIELD => 'unit_snid', |
||
74 | ), |
||
75 | // Order is important! |
||
76 | // TODO - split dbLevel to level and count |
||
77 | 'level' => array( |
||
78 | P_DB_FIELD => 'unit_level', |
||
79 | ), |
||
80 | 'count' => array(), |
||
81 | // TODO - move to child class |
||
82 | 'timeStart' => array( |
||
83 | P_DB_FIELD => 'unit_time_start', |
||
84 | ), |
||
85 | 'timeFinish' => array( |
||
86 | P_DB_FIELD => 'unit_time_finish', |
||
87 | ), |
||
88 | // Do we need it? Or internal no info/getters/setters should be ignored? |
||
89 | 'unitInfo' => array(), |
||
90 | 'isStackable' => array(), |
||
91 | 'locationDefaultType' => array(), |
||
92 | 'bonusType' => array(), |
||
93 | ); |
||
94 | |||
95 | /** |
||
96 | * BuddyContainer constructor. |
||
97 | * |
||
98 | * @param GlobalContainer $gc |
||
99 | */ |
||
100 | public function __construct($gc) { |
||
164 | |||
165 | public function isEmpty() { |
||
181 | |||
182 | } |
||
183 |
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.