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:
Complex classes like AbstractSubject often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use AbstractSubject, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
52 | abstract class AbstractSubject implements SubjectInterface, FilesystemSubjectInterface, DateConverterSubjectInterface |
||
53 | { |
||
54 | |||
55 | /** |
||
56 | * The trait that provides basic filesystem handling functionality. |
||
57 | * |
||
58 | * @var \TechDivision\Import\Subjects\FilesystemTrait |
||
59 | */ |
||
60 | use FilesystemTrait; |
||
61 | |||
62 | /** |
||
63 | * The trait that provides basic filesystem handling functionality. |
||
64 | * |
||
65 | * @var \TechDivision\Import\SystemLoggerTrait |
||
66 | */ |
||
67 | use SystemLoggerTrait; |
||
68 | |||
69 | /** |
||
70 | * The trait that provides date converting functionality. |
||
71 | * |
||
72 | * @var \TechDivision\Import\DateConverterTrait |
||
73 | */ |
||
74 | use DateConverterTrait; |
||
75 | |||
76 | /** |
||
77 | * The trait that provides header handling functionality. |
||
78 | * |
||
79 | * @var \TechDivision\Import\HeaderTrait |
||
80 | */ |
||
81 | use HeaderTrait; |
||
82 | |||
83 | /** |
||
84 | * The trait that provides row handling functionality. |
||
85 | * |
||
86 | * @var \TechDivision\Import\RowTrait |
||
87 | */ |
||
88 | use RowTrait; |
||
89 | |||
90 | /** |
||
91 | * The unique identifier for the actual invocation. |
||
92 | * |
||
93 | * @var string |
||
94 | */ |
||
95 | protected $uniqueId; |
||
96 | |||
97 | /** |
||
98 | * The name of the file to be imported. |
||
99 | * |
||
100 | * @var string |
||
101 | */ |
||
102 | protected $filename; |
||
103 | |||
104 | /** |
||
105 | * The actual line number. |
||
106 | * |
||
107 | * @var integer |
||
108 | */ |
||
109 | protected $lineNumber = 0; |
||
110 | |||
111 | /** |
||
112 | * The import adapter instance. |
||
113 | * |
||
114 | * @var \TechDivision\Import\Adapter\ImportAdapterInterface |
||
115 | */ |
||
116 | protected $importAdapter; |
||
117 | |||
118 | /** |
||
119 | * The subject configuration. |
||
120 | * |
||
121 | * @var \TechDivision\Import\Configuration\SubjectConfigurationInterface |
||
122 | */ |
||
123 | protected $configuration; |
||
124 | |||
125 | /** |
||
126 | * The plugin configuration. |
||
127 | * |
||
128 | * @var \TechDivision\Import\Configuration\PluginConfigurationInterface |
||
129 | */ |
||
130 | protected $pluginConfiguration; |
||
131 | |||
132 | /** |
||
133 | * The RegistryProcessor instance to handle running threads. |
||
134 | * |
||
135 | * @var \TechDivision\Import\Services\RegistryProcessorInterface |
||
136 | */ |
||
137 | protected $registryProcessor; |
||
138 | |||
139 | /** |
||
140 | * The actions unique serial. |
||
141 | * |
||
142 | * @var string |
||
143 | */ |
||
144 | protected $serial; |
||
145 | |||
146 | /** |
||
147 | * Array with the subject's observers. |
||
148 | * |
||
149 | * @var array |
||
150 | */ |
||
151 | protected $observers = array(); |
||
152 | |||
153 | /** |
||
154 | * Array with the subject's callbacks. |
||
155 | * |
||
156 | * @var array |
||
157 | */ |
||
158 | protected $callbacks = array(); |
||
159 | |||
160 | /** |
||
161 | * The subject's callback mappings. |
||
162 | * |
||
163 | * @var array |
||
164 | */ |
||
165 | protected $callbackMappings = array(); |
||
166 | |||
167 | /** |
||
168 | * The available root categories. |
||
169 | * |
||
170 | * @var array |
||
171 | */ |
||
172 | protected $rootCategories = array(); |
||
173 | |||
174 | /** |
||
175 | * The Magento configuration. |
||
176 | * |
||
177 | * @var array |
||
178 | */ |
||
179 | protected $coreConfigData = array(); |
||
180 | |||
181 | /** |
||
182 | * The available stores. |
||
183 | * |
||
184 | * @var array |
||
185 | */ |
||
186 | protected $stores = array(); |
||
187 | |||
188 | /** |
||
189 | * The available websites. |
||
190 | * |
||
191 | * @var array |
||
192 | */ |
||
193 | protected $storeWebsites = array(); |
||
194 | |||
195 | /** |
||
196 | * The default store. |
||
197 | * |
||
198 | * @var array |
||
199 | */ |
||
200 | protected $defaultStore; |
||
201 | |||
202 | /** |
||
203 | * The store view code the create the product/attributes for. |
||
204 | * |
||
205 | * @var string |
||
206 | */ |
||
207 | protected $storeViewCode; |
||
208 | |||
209 | /** |
||
210 | * The UID generator for the core config data. |
||
211 | * |
||
212 | * @var \TechDivision\Import\Utils\Generators\GeneratorInterface |
||
213 | */ |
||
214 | protected $coreConfigDataUidGenerator; |
||
215 | |||
216 | /** |
||
217 | * UNIX timestamp with the date the last row counter has been logged. |
||
218 | * |
||
219 | * @var integer |
||
220 | */ |
||
221 | protected $lastLog = 0; |
||
222 | |||
223 | /** |
||
224 | * The number of the last line that has been logged with the row counter |
||
225 | * @var integer |
||
226 | */ |
||
227 | protected $lastLineNumber = 0; |
||
228 | |||
229 | /** |
||
230 | * The event emitter instance. |
||
231 | * |
||
232 | * @var \League\Event\EmitterInterface |
||
233 | */ |
||
234 | protected $emitter; |
||
235 | |||
236 | /** |
||
237 | * The status of the file (0 = not processed, 1 = successfully processed, 2 = processed with failure) |
||
238 | * |
||
239 | * @var array |
||
240 | */ |
||
241 | protected $status = array(); |
||
242 | |||
243 | /** |
||
244 | * The default values for the columns from the configuration. |
||
245 | * |
||
246 | * @var array |
||
247 | */ |
||
248 | protected $defaultColumnValues = array(); |
||
249 | |||
250 | protected $columnValues = array(); |
||
251 | |||
252 | /** |
||
253 | * Mapping for the virtual entity type code to the real Magento 2 EAV entity type code. |
||
254 | * |
||
255 | * @var array |
||
256 | */ |
||
257 | protected $entityTypeCodeMappings = array( |
||
258 | EntityTypeCodes::EAV_ATTRIBUTE => EntityTypeCodes::CATALOG_PRODUCT, |
||
259 | EntityTypeCodes::EAV_ATTRIBUTE_SET => EntityTypeCodes::CATALOG_PRODUCT, |
||
260 | EntityTypeCodes::CATALOG_PRODUCT_PRICE => EntityTypeCodes::CATALOG_PRODUCT, |
||
261 | EntityTypeCodes::CATALOG_PRODUCT_INVENTORY => EntityTypeCodes::CATALOG_PRODUCT, |
||
262 | EntityTypeCodes::CATALOG_PRODUCT_INVENTORY_MSI => EntityTypeCodes::CATALOG_PRODUCT, |
||
263 | EntityTypeCodes::CATALOG_PRODUCT_TIER_PRICE => EntityTypeCodes::CATALOG_PRODUCT |
||
264 | ); |
||
265 | |||
266 | /** |
||
267 | * Initialize the subject instance. |
||
268 | * |
||
269 | * @param \TechDivision\Import\Services\RegistryProcessorInterface $registryProcessor The registry processor instance |
||
270 | * @param \TechDivision\Import\Utils\Generators\GeneratorInterface $coreConfigDataUidGenerator The UID generator for the core config data |
||
271 | * @param \Doctrine\Common\Collections\Collection $systemLoggers The array with the system loggers instances |
||
272 | * @param \League\Event\EmitterInterface $emitter The event emitter instance |
||
273 | */ |
||
274 | 81 | public function __construct( |
|
285 | |||
286 | /** |
||
287 | * Return's the event emitter instance. |
||
288 | * |
||
289 | * @return \League\Event\EmitterInterface The event emitter instance |
||
290 | */ |
||
291 | 9 | public function getEmitter() |
|
295 | |||
296 | /** |
||
297 | * Set's the name of the file to import |
||
298 | * |
||
299 | * @param string $filename The filename |
||
300 | * |
||
301 | * @return void |
||
302 | */ |
||
303 | 13 | public function setFilename($filename) |
|
307 | |||
308 | /** |
||
309 | * Return's the name of the file to import. |
||
310 | * |
||
311 | * @return string The filename |
||
312 | */ |
||
313 | 12 | public function getFilename() |
|
317 | |||
318 | /** |
||
319 | * Set's the actual line number. |
||
320 | * |
||
321 | * @param integer $lineNumber The line number |
||
322 | * |
||
323 | * @return void |
||
324 | */ |
||
325 | 1 | public function setLineNumber($lineNumber) |
|
329 | |||
330 | /** |
||
331 | * Return's the actual line number. |
||
332 | * |
||
333 | * @return integer The line number |
||
334 | */ |
||
335 | 17 | public function getLineNumber() |
|
339 | |||
340 | /** |
||
341 | * Return's the default callback mappings. |
||
342 | * |
||
343 | * @return array The default callback mappings |
||
344 | */ |
||
345 | 1 | public function getDefaultCallbackMappings() |
|
349 | |||
350 | /** |
||
351 | * Load the default column values from the configuration. |
||
352 | * |
||
353 | * @return array The array with the default column values |
||
354 | */ |
||
355 | 81 | View Code Duplication | public function getDefaultColumnValues() |
375 | |||
376 | /** |
||
377 | * Load the default header mappings from the configuration. |
||
378 | * |
||
379 | * @return array The array with the default header mappings |
||
380 | */ |
||
381 | 81 | View Code Duplication | public function getDefaultHeaderMappings() |
401 | |||
402 | /** |
||
403 | * Tries to format the passed value to a valid date with format 'Y-m-d H:i:s'. |
||
404 | * If the passed value is NOT a valid date, NULL will be returned. |
||
405 | * |
||
406 | * @param string $value The value to format |
||
407 | * |
||
408 | * @return string|null The formatted date or NULL if the date is not valid |
||
409 | */ |
||
410 | public function formatDate($value) |
||
414 | |||
415 | /** |
||
416 | * Extracts the elements of the passed value by exploding them |
||
417 | * with the also passed delimiter. |
||
418 | * |
||
419 | * @param string $value The value to extract |
||
420 | * @param string|null $delimiter The delimiter used to extrace the elements |
||
421 | * |
||
422 | * @return array The exploded values |
||
423 | */ |
||
424 | public function explode($value, $delimiter = null) |
||
428 | |||
429 | /** |
||
430 | * Queries whether or not debug mode is enabled or not, default is TRUE. |
||
431 | * |
||
432 | * @return boolean TRUE if debug mode is enabled, else FALSE |
||
433 | */ |
||
434 | 1 | public function isDebugMode() |
|
438 | |||
439 | /** |
||
440 | * Return's the subject's execution context configuration. |
||
441 | * |
||
442 | * @return \TechDivision\Import\ExecutionContextInterface The execution context configuration to use |
||
443 | */ |
||
444 | public function getExecutionContext() |
||
448 | |||
449 | /** |
||
450 | * Set's the subject configuration. |
||
451 | * |
||
452 | * @param \TechDivision\Import\Configuration\SubjectConfigurationInterface $configuration The subject configuration |
||
453 | * |
||
454 | * @return void |
||
455 | */ |
||
456 | 81 | public function setConfiguration(SubjectConfigurationInterface $configuration) |
|
460 | |||
461 | /** |
||
462 | * Return's the subject configuration. |
||
463 | * |
||
464 | * @return \TechDivision\Import\Configuration\SubjectConfigurationInterface The subject configuration |
||
465 | */ |
||
466 | 81 | public function getConfiguration() |
|
470 | |||
471 | /** |
||
472 | * Set's the import adapter instance. |
||
473 | * |
||
474 | * @param \TechDivision\Import\Adapter\ImportAdapterInterface $importAdapter The import adapter instance |
||
475 | * |
||
476 | * @return void |
||
477 | */ |
||
478 | 1 | public function setImportAdapter(ImportAdapterInterface $importAdapter) |
|
482 | |||
483 | /** |
||
484 | * Return's the import adapter instance. |
||
485 | * |
||
486 | * @return \TechDivision\Import\Adapter\ImportAdapterInterface The import adapter instance |
||
487 | */ |
||
488 | 1 | public function getImportAdapter() |
|
492 | |||
493 | /** |
||
494 | * Return's the RegistryProcessor instance to handle the running threads. |
||
495 | * |
||
496 | * @return \TechDivision\Import\Services\RegistryProcessorInterface The registry processor instance |
||
497 | */ |
||
498 | 81 | public function getRegistryProcessor() |
|
502 | |||
503 | /** |
||
504 | * Set's the unique serial for this import process. |
||
505 | * |
||
506 | * @param string $serial The unique serial |
||
507 | * |
||
508 | * @return void |
||
509 | */ |
||
510 | 8 | public function setSerial($serial) |
|
514 | |||
515 | /** |
||
516 | * Return's the unique serial for this import process. |
||
517 | * |
||
518 | * @return string The unique serial |
||
519 | */ |
||
520 | 1 | public function getSerial() |
|
524 | |||
525 | /** |
||
526 | * Merge's the passed status into the actual one. |
||
527 | * |
||
528 | * @param array $status The status to MergeBuilder |
||
529 | * |
||
530 | * @return void |
||
531 | */ |
||
532 | 4 | public function mergeStatus(array $status) |
|
536 | |||
537 | /** |
||
538 | * Retur's the actual status. |
||
539 | * |
||
540 | * @return array The actual status |
||
541 | */ |
||
542 | public function getStatus() |
||
546 | |||
547 | /** |
||
548 | * Return's the unique identifier for the actual invocation. |
||
549 | * |
||
550 | * @return string The unique identifier |
||
551 | */ |
||
552 | 4 | public function getUniqueId() |
|
556 | |||
557 | /** |
||
558 | * Return's the source date format to use. |
||
559 | * |
||
560 | * @return string The source date format |
||
561 | */ |
||
562 | public function getSourceDateFormat() |
||
566 | |||
567 | /** |
||
568 | * Return's the multiple field delimiter character to use, default value is comma (,). |
||
569 | * |
||
570 | * @return string The multiple field delimiter character |
||
571 | */ |
||
572 | 1 | public function getMultipleFieldDelimiter() |
|
576 | |||
577 | /** |
||
578 | * Return's the multiple value delimiter character to use, default value is comma (|). |
||
579 | * |
||
580 | * @return string The multiple value delimiter character |
||
581 | */ |
||
582 | 1 | public function getMultipleValueDelimiter() |
|
586 | |||
587 | /** |
||
588 | * Intializes the previously loaded global data for exactly one bunch. |
||
589 | * |
||
590 | * @param string $serial The serial of the actual import |
||
591 | * |
||
592 | * @return void |
||
593 | */ |
||
594 | 81 | public function setUp($serial) |
|
640 | |||
641 | /** |
||
642 | * Clean up the global data after importing the variants. |
||
643 | * |
||
644 | * @param string $serial The serial of the actual import |
||
645 | * |
||
646 | * @return void |
||
647 | */ |
||
648 | 1 | public function tearDown($serial) |
|
664 | |||
665 | /** |
||
666 | * Return's the target directory for the artefact export. |
||
667 | * |
||
668 | * @return string The target directory for the artefact export |
||
669 | */ |
||
670 | 1 | View Code Duplication | public function getTargetDir() |
684 | |||
685 | /** |
||
686 | * Register the passed observer with the specific type. |
||
687 | * |
||
688 | * @param \TechDivision\Import\Observers\ObserverInterface $observer The observer to register |
||
689 | * @param string $type The type to register the observer with |
||
690 | * |
||
691 | * @return void |
||
692 | */ |
||
693 | 6 | public function registerObserver(ObserverInterface $observer, $type) |
|
705 | |||
706 | /** |
||
707 | * Register the passed callback with the specific type. |
||
708 | * |
||
709 | * @param \TechDivision\Import\Callbacks\CallbackInterface $callback The subject to register the callbacks for |
||
710 | * @param string $type The type to register the callback with |
||
711 | * |
||
712 | * @return void |
||
713 | */ |
||
714 | 2 | public function registerCallback(CallbackInterface $callback, $type) |
|
726 | |||
727 | /** |
||
728 | * Return's the array with callbacks for the passed type. |
||
729 | * |
||
730 | * @param string $type The type of the callbacks to return |
||
731 | * |
||
732 | * @return array The callbacks |
||
733 | */ |
||
734 | 1 | public function getCallbacksByType($type) |
|
748 | |||
749 | /** |
||
750 | * Return's the array with the available observers. |
||
751 | * |
||
752 | * @return array The observers |
||
753 | */ |
||
754 | 6 | public function getObservers() |
|
758 | |||
759 | /** |
||
760 | * Return's the array with the available callbacks. |
||
761 | * |
||
762 | * @return array The callbacks |
||
763 | */ |
||
764 | 1 | public function getCallbacks() |
|
768 | |||
769 | /** |
||
770 | * Return's the callback mappings for this subject. |
||
771 | * |
||
772 | * @return array The array with the subject's callback mappings |
||
773 | */ |
||
774 | 2 | public function getCallbackMappings() |
|
778 | |||
779 | /** |
||
780 | * Imports the content of the file with the passed filename. |
||
781 | * |
||
782 | * |
||
783 | * @param string $serial The serial of the actual import |
||
784 | * @param string $filename The filename to process |
||
785 | * |
||
786 | * @return void |
||
787 | * @throws \Exception Is thrown, if the import can't be processed |
||
788 | */ |
||
789 | 2 | public function import($serial, $filename) |
|
907 | |||
908 | /** |
||
909 | * Imports the passed row into the database. If the import failed, the exception |
||
910 | * will be catched and logged, but the import process will be continued. |
||
911 | * |
||
912 | * @param array $row The row with the data to be imported |
||
913 | * |
||
914 | * @return void |
||
915 | */ |
||
916 | 7 | public function importRow(array $row) |
|
1024 | |||
1025 | /** |
||
1026 | * Queries whether or not that the subject needs an OK file to be processed. |
||
1027 | * |
||
1028 | * @return boolean TRUE if the subject needs an OK file, else FALSE |
||
1029 | */ |
||
1030 | 1 | public function isOkFileNeeded() |
|
1034 | |||
1035 | /** |
||
1036 | * Return's the default store. |
||
1037 | * |
||
1038 | * @return array The default store |
||
1039 | */ |
||
1040 | public function getDefaultStore() |
||
1044 | |||
1045 | /** |
||
1046 | * Return's the default store view code. |
||
1047 | * |
||
1048 | * @return array The default store view code |
||
1049 | */ |
||
1050 | 5 | public function getDefaultStoreViewCode() |
|
1054 | |||
1055 | /** |
||
1056 | * Set's the store view code the create the product/attributes for. |
||
1057 | * |
||
1058 | * @param string $storeViewCode The store view code |
||
1059 | * |
||
1060 | * @return void |
||
1061 | */ |
||
1062 | 4 | public function setStoreViewCode($storeViewCode) |
|
1066 | |||
1067 | /** |
||
1068 | * Return's the store view code the create the product/attributes for. |
||
1069 | * |
||
1070 | * @param string|null $default The default value to return, if the store view code has not been set |
||
1071 | * |
||
1072 | * @return string The store view code |
||
1073 | */ |
||
1074 | 8 | public function getStoreViewCode($default = null) |
|
1091 | |||
1092 | /** |
||
1093 | * Prepare's the store view code in the subject. If the store_view_code row doesn't contain |
||
1094 | * any value, the default code of the default store view will be set. |
||
1095 | * |
||
1096 | * @return void |
||
1097 | */ |
||
1098 | 2 | public function prepareStoreViewCode() |
|
1109 | |||
1110 | /** |
||
1111 | * Return's the store ID of the store with the passed store view code |
||
1112 | * |
||
1113 | * @param string $storeViewCode The store view code to return the store ID for |
||
1114 | * |
||
1115 | * @return integer The ID of the store with the passed ID |
||
1116 | * @throws \Exception Is thrown, if the store with the actual code is not available |
||
1117 | */ |
||
1118 | 4 | public function getStoreId($storeViewCode) |
|
1119 | { |
||
1120 | |||
1121 | // query whether or not, the requested store is available |
||
1122 | 4 | if (isset($this->stores[$storeViewCode])) { |
|
1123 | 3 | return (integer) $this->stores[$storeViewCode][MemberNames::STORE_ID]; |
|
1124 | } |
||
1125 | |||
1126 | // throw an exception, if not |
||
1127 | 1 | throw new \Exception( |
|
1128 | 1 | sprintf( |
|
1129 | 1 | 'Found invalid store view code %s in file %s on line %d', |
|
1130 | $storeViewCode, |
||
1131 | 1 | $this->getFilename(), |
|
1132 | 1 | $this->getLineNumber() |
|
1133 | ) |
||
1134 | ); |
||
1135 | } |
||
1136 | |||
1137 | /** |
||
1138 | * Return's the store ID of the actual row, or of the default store |
||
1139 | * if no store view code is set in the CSV file. |
||
1140 | * |
||
1141 | * @param string|null $default The default store view code to use, if no store view code is set in the CSV file |
||
1142 | * |
||
1143 | * @return integer The ID of the actual store |
||
1144 | * @throws \Exception Is thrown, if the store with the actual code is not available |
||
1145 | */ |
||
1146 | 2 | public function getRowStoreId($default = null) |
|
1157 | |||
1158 | /** |
||
1159 | * Return's the root category for the actual view store. |
||
1160 | * |
||
1161 | * @return array The store's root category |
||
1162 | * @throws \Exception Is thrown if the root category for the passed store code is NOT available |
||
1163 | */ |
||
1164 | 2 | public function getRootCategory() |
|
1178 | |||
1179 | /** |
||
1180 | * Return's the Magento configuration value. |
||
1181 | * |
||
1182 | * @param string $path The Magento path of the requested configuration value |
||
1183 | * @param mixed $default The default value that has to be returned, if the requested configuration value is not set |
||
1184 | * @param string $scope The scope the configuration value has been set |
||
1185 | * @param integer $scopeId The scope ID the configuration value has been set |
||
1186 | * |
||
1187 | * @return mixed The configuration value |
||
1188 | * @throws \Exception Is thrown, if nor a value can be found or a default value has been passed |
||
1189 | */ |
||
1190 | 5 | public function getCoreConfigData($path, $default = null, $scope = ScopeKeys::SCOPE_DEFAULT, $scopeId = 0) |
|
1191 | { |
||
1192 | |||
1193 | // initialize the core config data |
||
1194 | $coreConfigData = array( |
||
1195 | 5 | MemberNames::PATH => $path, |
|
1196 | 5 | MemberNames::SCOPE => $scope, |
|
1197 | 5 | MemberNames::SCOPE_ID => $scopeId |
|
1198 | ); |
||
1199 | |||
1200 | // generate the UID from the passed data |
||
1201 | 5 | $uniqueIdentifier = $this->coreConfigDataUidGenerator->generate($coreConfigData); |
|
1202 | |||
1203 | // iterate over the core config data and try to find the requested configuration value |
||
1204 | 5 | if (isset($this->coreConfigData[$uniqueIdentifier])) { |
|
1205 | 1 | return $this->coreConfigData[$uniqueIdentifier][MemberNames::VALUE]; |
|
1206 | } |
||
1207 | |||
1208 | // query whether or not we've to query for the configuration value on fallback level 'websites' also |
||
1209 | 4 | if ($scope === ScopeKeys::SCOPE_STORES) { |
|
1210 | // query whether or not the website with the passed ID is available |
||
1211 | 2 | foreach ($this->storeWebsites as $storeWebsite) { |
|
1212 | 2 | if ($storeWebsite[MemberNames::WEBSITE_ID] === $scopeId) { |
|
1213 | // replace scope with 'websites' and website ID |
||
1214 | 2 | $coreConfigData = array_merge( |
|
1215 | 2 | $coreConfigData, |
|
1216 | array( |
||
1217 | 2 | MemberNames::SCOPE => ScopeKeys::SCOPE_WEBSITES, |
|
1218 | MemberNames::SCOPE_ID => $storeWebsite[MemberNames::WEBSITE_ID] |
||
1219 | ) |
||
1220 | ); |
||
1221 | |||
1222 | // generate the UID from the passed data, merged with the 'websites' scope and ID |
||
1223 | 2 | $uniqueIdentifier = $this->coreConfigDataUidGenerator->generate($coreConfigData); |
|
1224 | |||
1225 | // query whether or not, the configuration value on 'websites' level |
||
1226 | 2 | View Code Duplication | if (isset($this->coreConfigData[$uniqueIdentifier][MemberNames::VALUE])) { |
1227 | 1 | return $this->coreConfigData[$uniqueIdentifier][MemberNames::VALUE]; |
|
1228 | } |
||
1229 | } |
||
1230 | } |
||
1231 | } |
||
1232 | |||
1233 | // replace scope with 'default' and scope ID '0' |
||
1234 | 3 | $coreConfigData = array_merge( |
|
1235 | 3 | $coreConfigData, |
|
1236 | array( |
||
1237 | 3 | MemberNames::SCOPE => ScopeKeys::SCOPE_DEFAULT, |
|
1238 | MemberNames::SCOPE_ID => 0 |
||
1239 | ) |
||
1240 | ); |
||
1241 | |||
1242 | // generate the UID from the passed data, merged with the 'default' scope and ID 0 |
||
1243 | 3 | $uniqueIdentifier = $this->coreConfigDataUidGenerator->generate($coreConfigData); |
|
1244 | |||
1245 | // query whether or not, the configuration value on 'default' level |
||
1246 | 3 | View Code Duplication | if (isset($this->coreConfigData[$uniqueIdentifier][MemberNames::VALUE])) { |
1247 | 1 | return $this->coreConfigData[$uniqueIdentifier][MemberNames::VALUE]; |
|
1248 | } |
||
1249 | |||
1250 | // if not, return the passed default value |
||
1251 | 2 | if ($default !== null) { |
|
1252 | 1 | return $default; |
|
1253 | } |
||
1254 | |||
1255 | // throw an exception if no value can be found |
||
1256 | // in the Magento configuration |
||
1257 | 1 | throw new \Exception( |
|
1258 | 1 | sprintf( |
|
1259 | 1 | 'Can\'t find a value for configuration "%s-%s-%d" in "core_config_data"', |
|
1260 | $path, |
||
1261 | $scope, |
||
1262 | $scopeId |
||
1263 | ) |
||
1264 | ); |
||
1265 | } |
||
1266 | |||
1267 | /** |
||
1268 | * Resolve the original column name for the passed one. |
||
1269 | * |
||
1270 | * @param string $columnName The column name that has to be resolved |
||
1271 | * |
||
1272 | * @return string|null The original column name |
||
1273 | */ |
||
1274 | 2 | public function resolveOriginalColumnName($columnName) |
|
1296 | |||
1297 | /** |
||
1298 | * Return's the original data if available, or an empty array. |
||
1299 | * |
||
1300 | * @return array The original data |
||
1301 | */ |
||
1302 | 2 | public function getOriginalData() |
|
1317 | |||
1318 | /** |
||
1319 | * Query's whether or not the actual column contains original data like |
||
1320 | * filename, line number and column names. |
||
1321 | * |
||
1322 | * @return boolean TRUE if the actual column contains origin data, else FALSE |
||
1323 | */ |
||
1324 | 2 | public function hasOriginalData() |
|
1328 | |||
1329 | /** |
||
1330 | * Wraps the passed exeception into a new one by trying to resolve the original filname, |
||
1331 | * line number and column names and use it for a detailed exception message. |
||
1332 | * |
||
1333 | * @param array $columnNames The column names that should be resolved and wrapped |
||
1334 | * @param \Exception $parent The exception we want to wrap |
||
1335 | * @param string $className The class name of the exception type we want to wrap the parent one |
||
1336 | * |
||
1337 | * @return \Exception the wrapped exception |
||
1338 | */ |
||
1339 | 1 | public function wrapException( |
|
1383 | |||
1384 | /** |
||
1385 | * Strip's the exception suffix containing filename and line number from the |
||
1386 | * passed message. |
||
1387 | * |
||
1388 | * @param string $message The message to strip the exception suffix from |
||
1389 | * |
||
1390 | * @return mixed The message without the exception suffix |
||
1391 | */ |
||
1392 | 1 | public function stripExceptionSuffix($message) |
|
1396 | |||
1397 | /** |
||
1398 | * Append's the exception suffix containing filename and line number to the |
||
1399 | * passed message. If no message has been passed, only the suffix will be |
||
1400 | * returned |
||
1401 | * |
||
1402 | * @param string|null $message The message to append the exception suffix to |
||
1403 | * @param string|null $filename The filename used to create the suffix |
||
1404 | * @param string|null $lineNumber The line number used to create the suffx |
||
1405 | * |
||
1406 | * @return string The message with the appended exception suffix |
||
1407 | */ |
||
1408 | 12 | public function appendExceptionSuffix($message = null, $filename = null, $lineNumber = null) |
|
1429 | |||
1430 | /** |
||
1431 | * Raises the value for the counter with the passed key by one. |
||
1432 | * |
||
1433 | * @param mixed $counterName The name of the counter to raise |
||
1434 | * |
||
1435 | * @return integer The counter's new value |
||
1436 | */ |
||
1437 | 1 | public function raiseCounter($counterName) |
|
1438 | { |
||
1439 | |||
1440 | // raise the counter with the passed name |
||
1441 | 1 | return $this->getRegistryProcessor()->raiseCounter( |
|
1442 | 1 | RegistryKeys::COUNTERS, |
|
1443 | $counterName |
||
1444 | ); |
||
1445 | } |
||
1446 | |||
1447 | /** |
||
1448 | * Merge the passed array into the status of the actual import. |
||
1449 | * |
||
1450 | * @param array $status The status information to be merged |
||
1451 | * |
||
1452 | * @return void |
||
1453 | */ |
||
1454 | 1 | public function mergeAttributesRecursive(array $status) |
|
1455 | { |
||
1456 | |||
1457 | // merge the passed status |
||
1458 | 1 | return $this->getRegistryProcessor()->mergeAttributesRecursive( |
|
1459 | 1 | RegistryKeys::STATUS, |
|
1460 | $status |
||
1461 | ); |
||
1462 | } |
||
1463 | |||
1464 | /** |
||
1465 | * Return's the entity type code to be used. |
||
1466 | * |
||
1467 | * @return string The entity type code to be used |
||
1468 | */ |
||
1469 | public function getEntityTypeCode() |
||
1483 | |||
1484 | /** |
||
1485 | * Concatenates and returns the event name for the actual plugin and subject context. |
||
1486 | * |
||
1487 | * @param string $eventName The event name to concatenate |
||
1488 | * |
||
1489 | * @return string The concatenated event name |
||
1490 | */ |
||
1491 | 9 | protected function getEventName($eventName) |
|
1492 | { |
||
1493 | 9 | return sprintf( |
|
1494 | 9 | '%s.%s.%s', |
|
1495 | 9 | $this->getConfiguration()->getPluginConfiguration()->getId(), |
|
1496 | 9 | $this->getConfiguration()->getId(), |
|
1497 | $eventName |
||
1498 | ); |
||
1499 | } |
||
1500 | |||
1501 | /** |
||
1502 | * Return's the full opration name, which consists of the Magento edition, the entity type code and the operation name. |
||
1503 | * |
||
1504 | * @param string $separator The separator used to seperate the elements |
||
1505 | * |
||
1506 | * @return string The full operation name |
||
1507 | */ |
||
1508 | public function getFullOperationName($separator = '/') |
||
1512 | } |
||
1513 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..