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 |
||
32 | class OroCRMSalesBundleInstaller implements |
||
33 | Installation, |
||
34 | ExtendExtensionAwareInterface, |
||
35 | NoteExtensionAwareInterface, |
||
36 | ActivityExtensionAwareInterface, |
||
37 | AttachmentExtensionAwareInterface, |
||
38 | ActivityListExtensionAwareInterface |
||
39 | { |
||
40 | /** |
||
41 | * @var ExtendExtension |
||
42 | */ |
||
43 | protected $extendExtension; |
||
44 | |||
45 | /** |
||
46 | * @var NoteExtension |
||
47 | */ |
||
48 | protected $noteExtension; |
||
49 | |||
50 | /** |
||
51 | * @var ActivityExtension |
||
52 | */ |
||
53 | protected $activityExtension; |
||
54 | |||
55 | /** |
||
56 | * @var AttachmentExtension |
||
57 | */ |
||
58 | protected $attachmentExtension; |
||
59 | |||
60 | /** @var ActivityListExtension */ |
||
61 | protected $activityListExtension; |
||
62 | |||
63 | /** |
||
64 | * {@inheritdoc} |
||
65 | */ |
||
66 | public function setActivityListExtension(ActivityListExtension $activityListExtension) |
||
67 | { |
||
68 | $this->activityListExtension = $activityListExtension; |
||
69 | } |
||
70 | |||
71 | /** |
||
72 | * {@inheritdoc} |
||
73 | */ |
||
74 | public function setExtendExtension(ExtendExtension $extendExtension) |
||
75 | { |
||
76 | $this->extendExtension = $extendExtension; |
||
77 | } |
||
78 | |||
79 | /** |
||
80 | * {@inheritdoc} |
||
81 | */ |
||
82 | public function setNoteExtension(NoteExtension $noteExtension) |
||
83 | { |
||
84 | $this->noteExtension = $noteExtension; |
||
85 | } |
||
86 | |||
87 | /** |
||
88 | * {@inheritdoc} |
||
89 | */ |
||
90 | public function setActivityExtension(ActivityExtension $activityExtension) |
||
91 | { |
||
92 | $this->activityExtension = $activityExtension; |
||
93 | } |
||
94 | |||
95 | /** |
||
96 | * {@inheritdoc} |
||
97 | */ |
||
98 | public function setAttachmentExtension(AttachmentExtension $attachmentExtension) |
||
99 | { |
||
100 | $this->attachmentExtension = $attachmentExtension; |
||
101 | } |
||
102 | |||
103 | /** |
||
104 | * {@inheritdoc} |
||
105 | */ |
||
106 | public function getMigrationVersion() |
||
107 | { |
||
108 | return 'v1_22'; |
||
109 | } |
||
110 | |||
111 | /** |
||
112 | * {@inheritdoc} |
||
113 | */ |
||
114 | public function up(Schema $schema, QueryBag $queries) |
||
115 | { |
||
116 | /** Tables generation **/ |
||
117 | $this->createOrocrmSalesOpportunityTable($schema); |
||
118 | $this->createOrocrmSalesLeadStatusTable($schema); |
||
119 | $this->createOrocrmSalesFunnelTable($schema); |
||
120 | $this->createOrocrmSalesOpportStatusTable($schema); |
||
121 | $this->createOrocrmSalesOpportCloseRsnTable($schema); |
||
122 | $this->createOrocrmSalesLeadTable($schema); |
||
123 | $this->createOrocrmSalesB2bCustomerTable($schema); |
||
124 | |||
125 | /** Tables update */ |
||
126 | $this->addOroEmailMailboxProcessorColumns($schema); |
||
127 | |||
128 | /** Foreign keys generation **/ |
||
129 | $this->addOrocrmSalesOpportunityForeignKeys($schema); |
||
130 | $this->addOrocrmSalesFunnelForeignKeys($schema); |
||
131 | $this->addOrocrmSalesLeadForeignKeys($schema); |
||
132 | $this->addOrocrmSalesB2bCustomerForeignKeys($schema); |
||
133 | $this->addOroEmailMailboxProcessorForeignKeys($schema); |
||
134 | |||
135 | /** Apply extensions */ |
||
136 | SalesNoteMigration::addNoteAssociations($schema, $this->noteExtension); |
||
137 | $this->activityExtension->addActivityAssociation($schema, 'oro_email', 'orocrm_sales_lead'); |
||
138 | $this->activityExtension->addActivityAssociation($schema, 'oro_email', 'orocrm_sales_opportunity'); |
||
139 | $this->activityExtension->addActivityAssociation($schema, 'oro_email', 'orocrm_sales_b2bcustomer'); |
||
140 | $this->activityExtension->addActivityAssociation($schema, 'orocrm_call', 'orocrm_sales_lead'); |
||
141 | $this->activityExtension->addActivityAssociation($schema, 'orocrm_call', 'orocrm_sales_opportunity'); |
||
142 | $this->activityExtension->addActivityAssociation($schema, 'orocrm_call', 'orocrm_sales_b2bcustomer'); |
||
143 | $this->activityExtension->addActivityAssociation($schema, 'orocrm_task', 'orocrm_sales_lead'); |
||
144 | $this->activityExtension->addActivityAssociation($schema, 'orocrm_task', 'orocrm_sales_opportunity'); |
||
145 | $this->activityExtension->addActivityAssociation($schema, 'orocrm_task', 'orocrm_sales_b2bcustomer'); |
||
146 | $this->activityExtension->addActivityAssociation($schema, 'oro_calendar_event', 'orocrm_sales_lead'); |
||
147 | $this->activityExtension->addActivityAssociation($schema, 'oro_calendar_event', 'orocrm_sales_opportunity'); |
||
148 | $this->activityExtension->addActivityAssociation($schema, 'oro_calendar_event', 'orocrm_sales_b2bcustomer'); |
||
149 | OpportunityAttachment::addOpportunityAttachment($schema, $this->attachmentExtension); |
||
150 | InheritanceActivityTargets::addInheritanceTargets($schema, $this->activityListExtension); |
||
151 | |||
152 | SalesOrganizations::addOrganization($schema); |
||
153 | AddOpportunityStatus::addStatusField($schema, $this->extendExtension, $queries); |
||
154 | } |
||
155 | |||
156 | /** |
||
157 | * Create orocrm_sales_opportunity table |
||
158 | * |
||
159 | * @param Schema $schema |
||
160 | */ |
||
161 | protected function createOrocrmSalesOpportunityTable(Schema $schema) |
||
162 | { |
||
163 | $table = $schema->createTable('orocrm_sales_opportunity'); |
||
164 | $table->addColumn('id', 'integer', ['autoincrement' => true]); |
||
165 | $table->addColumn('contact_id', 'integer', ['notnull' => false]); |
||
166 | $table->addColumn('close_reason_name', 'string', ['notnull' => false, 'length' => 32]); |
||
167 | $table->addColumn('user_owner_id', 'integer', ['notnull' => false]); |
||
168 | $table->addColumn('customer_id', 'integer', ['notnull' => false]); |
||
169 | $table->addColumn('data_channel_id', 'integer', ['notnull' => false]); |
||
170 | $table->addColumn('lead_id', 'integer', ['notnull' => false]); |
||
171 | $table->addColumn('workflow_item_id', 'integer', ['notnull' => false]); |
||
172 | $table->addColumn('workflow_step_id', 'integer', ['notnull' => false]); |
||
173 | $table->addColumn('name', 'string', ['length' => 255]); |
||
174 | $table->addColumn('close_date', 'date', ['notnull' => false]); |
||
175 | $table->addColumn( |
||
176 | 'probability', |
||
177 | 'percent', |
||
178 | ['notnull' => false, 'precision' => 0, 'comment' => '(DC2Type:percent)'] |
||
179 | ); |
||
180 | $table->addColumn( |
||
181 | 'budget_amount', |
||
182 | 'money', |
||
183 | ['notnull' => false, 'precision' => 0, 'comment' => '(DC2Type:money)'] |
||
184 | ); |
||
185 | $table->addColumn( |
||
186 | 'close_revenue', |
||
187 | 'money', |
||
188 | ['notnull' => false, 'precision' => 0, 'comment' => '(DC2Type:money)'] |
||
189 | ); |
||
190 | $table->addColumn('customer_need', 'text', ['notnull' => false]); |
||
191 | $table->addColumn('proposed_solution', 'text', ['notnull' => false]); |
||
192 | $table->addColumn('created_at', 'datetime', []); |
||
193 | $table->addColumn('updated_at', 'datetime', []); |
||
194 | $table->addColumn('notes', 'text', ['notnull' => false]); |
||
195 | $table->addIndex(['contact_id'], 'idx_c0fe4aace7a1254a', []); |
||
196 | $table->addIndex(['created_at'], 'opportunity_created_idx', []); |
||
197 | $table->addUniqueIndex(['workflow_item_id'], 'uniq_c0fe4aac1023c4ee'); |
||
198 | $table->addIndex(['user_owner_id'], 'idx_c0fe4aac9eb185f9', []); |
||
199 | $table->addIndex(['lead_id'], 'idx_c0fe4aac55458d', []); |
||
200 | $table->addIndex(['customer_id'], 'IDX_C0FE4AAC9395C3F3', []); |
||
201 | $table->addIndex(['data_channel_id'], 'IDX_C0FE4AACBDC09B73', []); |
||
202 | $table->addIndex(['close_reason_name'], 'idx_c0fe4aacd81b931c', []); |
||
203 | $table->setPrimaryKey(['id']); |
||
204 | $table->addIndex(['workflow_step_id'], 'idx_c0fe4aac71fe882c', []); |
||
205 | } |
||
206 | |||
207 | /** |
||
208 | * Create orocrm_sales_lead_status table |
||
209 | * |
||
210 | * @param Schema $schema |
||
211 | */ |
||
212 | View Code Duplication | protected function createOrocrmSalesLeadStatusTable(Schema $schema) |
|
220 | |||
221 | /** |
||
222 | * Create orocrm_sales_funnel table |
||
223 | * |
||
224 | * @param Schema $schema |
||
225 | */ |
||
226 | protected function createOrocrmSalesFunnelTable(Schema $schema) |
||
248 | |||
249 | /** |
||
250 | * Create orocrm_sales_opport_status table |
||
251 | * |
||
252 | * @param Schema $schema |
||
253 | */ |
||
254 | View Code Duplication | protected function createOrocrmSalesOpportStatusTable(Schema $schema) |
|
262 | |||
263 | /** |
||
264 | * Create orocrm_sales_opport_close_rsn table |
||
265 | * |
||
266 | * @param Schema $schema |
||
267 | */ |
||
268 | View Code Duplication | protected function createOrocrmSalesOpportCloseRsnTable(Schema $schema) |
|
276 | |||
277 | /** |
||
278 | * Create orocrm_sales_lead table |
||
279 | * |
||
280 | * @param Schema $schema |
||
281 | */ |
||
282 | protected function createOrocrmSalesLeadTable(Schema $schema) |
||
338 | |||
339 | /** |
||
340 | * Create orocrm_sales_b2bcustomer table |
||
341 | * |
||
342 | * @param Schema $schema |
||
343 | */ |
||
344 | protected function createOrocrmSalesB2bCustomerTable(Schema $schema) |
||
345 | { |
||
346 | $table = $schema->createTable('orocrm_sales_b2bcustomer'); |
||
422 | |||
423 | /** |
||
424 | * Add orocrm_sales_opportunity foreign keys. |
||
425 | * |
||
426 | * @param Schema $schema |
||
427 | */ |
||
428 | protected function addOrocrmSalesOpportunityForeignKeys(Schema $schema) |
||
481 | |||
482 | /** |
||
483 | * Add orocrm_sales_funnel foreign keys. |
||
484 | * |
||
485 | * @param Schema $schema |
||
486 | */ |
||
487 | View Code Duplication | protected function addOrocrmSalesFunnelForeignKeys(Schema $schema) |
|
528 | |||
529 | /** |
||
530 | * Add orocrm_sales_lead foreign keys. |
||
531 | * |
||
532 | * @param Schema $schema |
||
533 | */ |
||
534 | View Code Duplication | protected function addOrocrmSalesLeadForeignKeys(Schema $schema) |
|
593 | |||
594 | /** |
||
595 | * Add orocrm_sales_b2bcustomer foreign keys. |
||
596 | * |
||
597 | * @param Schema $schema |
||
598 | */ |
||
599 | View Code Duplication | protected function addOrocrmSalesB2bCustomerForeignKeys(Schema $schema) |
|
639 | |||
640 | /** |
||
641 | * Create oro_email_mailbox_processor table |
||
642 | * |
||
643 | * @param Schema $schema |
||
644 | */ |
||
645 | View Code Duplication | public static function addOroEmailMailboxProcessorColumns(Schema $schema) |
|
655 | |||
656 | /** |
||
657 | * Add oro_email_mailbox_processor foreign keys. |
||
658 | * |
||
659 | * @param Schema $schema |
||
660 | */ |
||
661 | public static function addOroEmailMailboxProcessorForeignKeys(Schema $schema) |
||
677 | } |
||
678 |
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.