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 |
||
| 47 | abstract class AbstractSubject implements SubjectInterface |
||
| 48 | { |
||
| 49 | |||
| 50 | /** |
||
| 51 | * The trait that provides basic filesystem handling functionality. |
||
| 52 | * |
||
| 53 | * @var TechDivision\Import\Subjects\FilesystemTrait |
||
| 54 | */ |
||
| 55 | use FilesystemTrait; |
||
| 56 | |||
| 57 | /** |
||
| 58 | * The import adapter instance. |
||
| 59 | * |
||
| 60 | * @var \TechDivision\Import\Adapter\AdapterInterface |
||
| 61 | */ |
||
| 62 | protected $importAdapter; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * The system configuration. |
||
| 66 | * |
||
| 67 | * @var \TechDivision\Import\Configuration\SubjectConfigurationInterface |
||
| 68 | */ |
||
| 69 | protected $configuration; |
||
| 70 | |||
| 71 | /** |
||
| 72 | * The array with the system logger instances. |
||
| 73 | * |
||
| 74 | * @var array |
||
| 75 | */ |
||
| 76 | protected $systemLoggers = array(); |
||
| 77 | |||
| 78 | /** |
||
| 79 | * The RegistryProcessor instance to handle running threads. |
||
| 80 | * |
||
| 81 | * @var \TechDivision\Import\Services\RegistryProcessorInterface |
||
| 82 | */ |
||
| 83 | protected $registryProcessor; |
||
| 84 | |||
| 85 | /** |
||
| 86 | * The actions unique serial. |
||
| 87 | * |
||
| 88 | * @var string |
||
| 89 | */ |
||
| 90 | protected $serial; |
||
| 91 | |||
| 92 | /** |
||
| 93 | * The name of the file to be imported. |
||
| 94 | * |
||
| 95 | * @var string |
||
| 96 | */ |
||
| 97 | protected $filename; |
||
| 98 | |||
| 99 | /** |
||
| 100 | * Array with the subject's observers. |
||
| 101 | * |
||
| 102 | * @var array |
||
| 103 | */ |
||
| 104 | protected $observers = array(); |
||
| 105 | |||
| 106 | /** |
||
| 107 | * Array with the subject's callbacks. |
||
| 108 | * |
||
| 109 | * @var array |
||
| 110 | */ |
||
| 111 | protected $callbacks = array(); |
||
| 112 | |||
| 113 | /** |
||
| 114 | * The subject's callback mappings. |
||
| 115 | * |
||
| 116 | * @var array |
||
| 117 | */ |
||
| 118 | protected $callbackMappings = array(); |
||
| 119 | |||
| 120 | /** |
||
| 121 | * Contain's the column names from the header line. |
||
| 122 | * |
||
| 123 | * @var array |
||
| 124 | */ |
||
| 125 | protected $headers = array(); |
||
| 126 | |||
| 127 | /** |
||
| 128 | * The actual line number. |
||
| 129 | * |
||
| 130 | * @var integer |
||
| 131 | */ |
||
| 132 | protected $lineNumber = 0; |
||
| 133 | |||
| 134 | /** |
||
| 135 | * The actual operation name. |
||
| 136 | * |
||
| 137 | * @var string |
||
| 138 | */ |
||
| 139 | protected $operationName ; |
||
| 140 | |||
| 141 | /** |
||
| 142 | * The flag that stop's overserver execution on the actual row. |
||
| 143 | * |
||
| 144 | * @var boolean |
||
| 145 | */ |
||
| 146 | protected $skipRow = false; |
||
| 147 | |||
| 148 | /** |
||
| 149 | * The available root categories. |
||
| 150 | * |
||
| 151 | * @var array |
||
| 152 | */ |
||
| 153 | protected $rootCategories = array(); |
||
| 154 | |||
| 155 | /** |
||
| 156 | * The Magento configuration. |
||
| 157 | * |
||
| 158 | * @var array |
||
| 159 | */ |
||
| 160 | protected $coreConfigData = array(); |
||
| 161 | |||
| 162 | /** |
||
| 163 | * The available stores. |
||
| 164 | * |
||
| 165 | * @var array |
||
| 166 | */ |
||
| 167 | protected $stores = array(); |
||
| 168 | |||
| 169 | /** |
||
| 170 | * The available websites. |
||
| 171 | * |
||
| 172 | * @var array |
||
| 173 | */ |
||
| 174 | protected $storeWebsites = array(); |
||
| 175 | |||
| 176 | /** |
||
| 177 | * The default store. |
||
| 178 | * |
||
| 179 | * @var array |
||
| 180 | */ |
||
| 181 | protected $defaultStore; |
||
| 182 | |||
| 183 | /** |
||
| 184 | * The store view code the create the product/attributes for. |
||
| 185 | * |
||
| 186 | * @var string |
||
| 187 | */ |
||
| 188 | protected $storeViewCode; |
||
| 189 | |||
| 190 | /** |
||
| 191 | * The UID generator for the core config data. |
||
| 192 | * |
||
| 193 | * @var \TechDivision\Import\Utils\Generators\GeneratorInterface |
||
| 194 | */ |
||
| 195 | protected $coreConfigDataUidGenerator; |
||
| 196 | |||
| 197 | /** |
||
| 198 | * The actual row. |
||
| 199 | * |
||
| 200 | * @var array |
||
| 201 | */ |
||
| 202 | protected $row = array(); |
||
| 203 | |||
| 204 | /** |
||
| 205 | * Initialize the subject instance. |
||
| 206 | * |
||
| 207 | * @param \TechDivision\Import\Services\RegistryProcessorInterface $registryProcessor The registry processor instance |
||
| 208 | * @param \TechDivision\Import\Utils\Generators\GeneratorInterface $coreConfigDataUidGenerator The UID generator for the core config data |
||
| 209 | * @param array $systemLoggers The array with the system loggers instances |
||
| 210 | */ |
||
| 211 | 80 | public function __construct( |
|
| 220 | |||
| 221 | /** |
||
| 222 | * Return's the default callback mappings. |
||
| 223 | * |
||
| 224 | * @return array The default callback mappings |
||
| 225 | */ |
||
| 226 | 1 | public function getDefaultCallbackMappings() |
|
| 230 | |||
| 231 | /** |
||
| 232 | * Return's the actual row. |
||
| 233 | * |
||
| 234 | * @return array The actual row |
||
| 235 | */ |
||
| 236 | 4 | public function getRow() |
|
| 240 | |||
| 241 | /** |
||
| 242 | * Stop's observer execution on the actual row. |
||
| 243 | * |
||
| 244 | * @return void |
||
| 245 | */ |
||
| 246 | 1 | public function skipRow() |
|
| 250 | |||
| 251 | /** |
||
| 252 | * Return's the actual line number. |
||
| 253 | * |
||
| 254 | * @return integer The line number |
||
| 255 | */ |
||
| 256 | 8 | public function getLineNumber() |
|
| 260 | |||
| 261 | /** |
||
| 262 | * Return's the actual operation name. |
||
| 263 | * |
||
| 264 | * @return string |
||
| 265 | */ |
||
| 266 | 1 | public function getOperationName() |
|
| 267 | { |
||
| 268 | 1 | return $this->operationName; |
|
| 269 | } |
||
| 270 | |||
| 271 | /** |
||
| 272 | * Set's the array containing header row. |
||
| 273 | * |
||
| 274 | * @param array $headers The array with the header row |
||
| 275 | * |
||
| 276 | * @return void |
||
| 277 | */ |
||
| 278 | 9 | public function setHeaders(array $headers) |
|
| 282 | |||
| 283 | /** |
||
| 284 | * Return's the array containing header row. |
||
| 285 | * |
||
| 286 | * @return array The array with the header row |
||
| 287 | */ |
||
| 288 | 2 | public function getHeaders() |
|
| 292 | |||
| 293 | /** |
||
| 294 | * Queries whether or not the header with the passed name is available. |
||
| 295 | * |
||
| 296 | * @param string $name The header name to query |
||
| 297 | * |
||
| 298 | * @return boolean TRUE if the header is available, else FALSE |
||
| 299 | */ |
||
| 300 | 8 | public function hasHeader($name) |
|
| 304 | |||
| 305 | /** |
||
| 306 | * Return's the header value for the passed name. |
||
| 307 | * |
||
| 308 | * @param string $name The name of the header to return the value for |
||
| 309 | * |
||
| 310 | * @return mixed The header value |
||
| 311 | * \InvalidArgumentException Is thrown, if the header with the passed name is NOT available |
||
| 312 | */ |
||
| 313 | 7 | public function getHeader($name) |
|
| 324 | |||
| 325 | /** |
||
| 326 | * Add's the header with the passed name and position, if not NULL. |
||
| 327 | * |
||
| 328 | * @param string $name The header name to add |
||
| 329 | * |
||
| 330 | * @return integer The new headers position |
||
| 331 | */ |
||
| 332 | 2 | public function addHeader($name) |
|
| 341 | |||
| 342 | /** |
||
| 343 | * Query whether or not a value for the column with the passed name exists. |
||
| 344 | * |
||
| 345 | * @param string $name The column name to query for a valid value |
||
| 346 | * |
||
| 347 | * @return boolean TRUE if the value is set, else FALSE |
||
| 348 | */ |
||
| 349 | 2 | View Code Duplication | public function hasValue($name) |
| 364 | |||
| 365 | /** |
||
| 366 | * Set the value in the passed column name. |
||
| 367 | * |
||
| 368 | * @param string $name The column name to set the value for |
||
| 369 | * @param mixed $value The value to set |
||
| 370 | * |
||
| 371 | * @return void |
||
| 372 | */ |
||
| 373 | 2 | public function setValue($name, $value) |
|
| 377 | |||
| 378 | /** |
||
| 379 | * Resolve's the value with the passed colum name from the actual row. If a callback will |
||
| 380 | * be passed, the callback will be invoked with the found value as parameter. If |
||
| 381 | * the value is NULL or empty, the default value will be returned. |
||
| 382 | * |
||
| 383 | * @param string $name The name of the column to return the value for |
||
| 384 | * @param mixed|null $default The default value, that has to be returned, if the row's value is empty |
||
| 385 | * @param callable|null $callback The callback that has to be invoked on the value, e. g. to format it |
||
| 386 | * |
||
| 387 | * @return mixed|null The, almost formatted, value |
||
| 388 | */ |
||
| 389 | 5 | View Code Duplication | public function getValue($name, $default = null, callable $callback = null) |
| 418 | |||
| 419 | /** |
||
| 420 | * Tries to format the passed value to a valid date with format 'Y-m-d H:i:s'. |
||
| 421 | * If the passed value is NOT a valid date, NULL will be returned. |
||
| 422 | * |
||
| 423 | * @param string $value The value to format |
||
| 424 | * |
||
| 425 | * @return string|null The formatted date or NULL if the date is not valid |
||
| 426 | */ |
||
| 427 | 2 | public function formatDate($value) |
|
| 438 | |||
| 439 | /** |
||
| 440 | * Extracts the elements of the passed value by exploding them |
||
| 441 | * with the also passed delimiter. |
||
| 442 | * |
||
| 443 | * @param string $value The value to extract |
||
| 444 | * @param string|null $delimiter The delimiter used to extrace the elements |
||
| 445 | * |
||
| 446 | * @return array The exploded values |
||
| 447 | */ |
||
| 448 | 2 | public function explode($value, $delimiter = null) |
|
| 461 | |||
| 462 | /** |
||
| 463 | * Queries whether or not debug mode is enabled or not, default is TRUE. |
||
| 464 | * |
||
| 465 | * @return boolean TRUE if debug mode is enabled, else FALSE |
||
| 466 | */ |
||
| 467 | 1 | public function isDebugMode() |
|
| 471 | |||
| 472 | /** |
||
| 473 | * Set's the subject configuration. |
||
| 474 | * |
||
| 475 | * @param \TechDivision\Import\Configuration\SubjectConfigurationInterface $configuration The subject configuration |
||
| 476 | * |
||
| 477 | * @return void |
||
| 478 | */ |
||
| 479 | 80 | public function setConfiguration(SubjectConfigurationInterface $configuration) |
|
| 483 | |||
| 484 | /** |
||
| 485 | * Return's the subject configuration. |
||
| 486 | * |
||
| 487 | * @return \TechDivision\Import\Configuration\SubjectConfigurationInterface The subject configuration |
||
| 488 | */ |
||
| 489 | 80 | public function getConfiguration() |
|
| 493 | |||
| 494 | /** |
||
| 495 | * Return's the logger with the passed name, by default the system logger. |
||
| 496 | * |
||
| 497 | * @param string $name The name of the requested system logger |
||
| 498 | * |
||
| 499 | * @return \Psr\Log\LoggerInterface The logger instance |
||
| 500 | * @throws \Exception Is thrown, if the requested logger is NOT available |
||
| 501 | */ |
||
| 502 | 75 | public function getSystemLogger($name = LoggerKeys::SYSTEM) |
|
| 513 | |||
| 514 | /** |
||
| 515 | * Set's the import adapter instance. |
||
| 516 | * |
||
| 517 | * @param \TechDivision\Import\Adapter\ImportAdapterInterface $importAdapter The import adapter instance |
||
| 518 | * |
||
| 519 | * @return void |
||
| 520 | */ |
||
| 521 | 3 | public function setImportAdapter(ImportAdapterInterface $importAdapter) |
|
| 525 | |||
| 526 | /** |
||
| 527 | * Return's the import adapter instance. |
||
| 528 | * |
||
| 529 | * @return \TechDivision\Import\Adapter\ImportAdapterInterface The import adapter instance |
||
| 530 | */ |
||
| 531 | 3 | public function getImportAdapter() |
|
| 535 | |||
| 536 | /** |
||
| 537 | * Return's the array with the system logger instances. |
||
| 538 | * |
||
| 539 | * @return array The logger instance |
||
| 540 | */ |
||
| 541 | 1 | public function getSystemLoggers() |
|
| 545 | |||
| 546 | /** |
||
| 547 | * Return's the RegistryProcessor instance to handle the running threads. |
||
| 548 | * |
||
| 549 | * @return \TechDivision\Import\Services\RegistryProcessorInterface The registry processor instance |
||
| 550 | */ |
||
| 551 | 80 | public function getRegistryProcessor() |
|
| 555 | |||
| 556 | /** |
||
| 557 | * Set's the unique serial for this import process. |
||
| 558 | * |
||
| 559 | * @param string $serial The unique serial |
||
| 560 | * |
||
| 561 | * @return void |
||
| 562 | */ |
||
| 563 | 6 | public function setSerial($serial) |
|
| 567 | |||
| 568 | /** |
||
| 569 | * Return's the unique serial for this import process. |
||
| 570 | * |
||
| 571 | * @return string The unique serial |
||
| 572 | */ |
||
| 573 | 3 | public function getSerial() |
|
| 577 | |||
| 578 | /** |
||
| 579 | * Set's the name of the file to import |
||
| 580 | * |
||
| 581 | * @param string $filename The filename |
||
| 582 | * |
||
| 583 | * @return void |
||
| 584 | */ |
||
| 585 | 10 | public function setFilename($filename) |
|
| 589 | |||
| 590 | /** |
||
| 591 | * Return's the name of the file to import. |
||
| 592 | * |
||
| 593 | * @return string The filename |
||
| 594 | */ |
||
| 595 | 8 | public function getFilename() |
|
| 599 | |||
| 600 | /** |
||
| 601 | * Return's the source date format to use. |
||
| 602 | * |
||
| 603 | * @return string The source date format |
||
| 604 | */ |
||
| 605 | 4 | public function getSourceDateFormat() |
|
| 609 | |||
| 610 | /** |
||
| 611 | * Return's the multiple field delimiter character to use, default value is comma (,). |
||
| 612 | * |
||
| 613 | * @return string The multiple field delimiter character |
||
| 614 | */ |
||
| 615 | 1 | public function getMultipleFieldDelimiter() |
|
| 619 | |||
| 620 | /** |
||
| 621 | * Return's the multiple value delimiter character to use, default value is comma (|). |
||
| 622 | * |
||
| 623 | * @return string The multiple value delimiter character |
||
| 624 | */ |
||
| 625 | 1 | public function getMultipleValueDelimiter() |
|
| 629 | |||
| 630 | /** |
||
| 631 | * Intializes the previously loaded global data for exactly one bunch. |
||
| 632 | * |
||
| 633 | * @param string $serial The serial of the actual import |
||
| 634 | * |
||
| 635 | * @return void |
||
| 636 | * @see \Importer\Csv\Actions\ProductImportAction::prepare() |
||
| 637 | */ |
||
| 638 | 80 | public function setUp($serial) |
|
| 673 | |||
| 674 | /** |
||
| 675 | * Clean up the global data after importing the variants. |
||
| 676 | * |
||
| 677 | * @param string $serial The serial of the actual import |
||
| 678 | * |
||
| 679 | * @return void |
||
| 680 | */ |
||
| 681 | 1 | public function tearDown($serial) |
|
| 698 | |||
| 699 | /** |
||
| 700 | * Return's the next source directory, which will be the target directory |
||
| 701 | * of this subject, in most cases. |
||
| 702 | * |
||
| 703 | * @param string $serial The serial of the actual import |
||
| 704 | * |
||
| 705 | * @return string The new source directory |
||
| 706 | */ |
||
| 707 | 1 | protected function getNewSourceDir($serial) |
|
| 711 | |||
| 712 | /** |
||
| 713 | * Register the passed observer with the specific type. |
||
| 714 | * |
||
| 715 | * @param \TechDivision\Import\Observers\ObserverInterface $observer The observer to register |
||
| 716 | * @param string $type The type to register the observer with |
||
| 717 | * |
||
| 718 | * @return void |
||
| 719 | */ |
||
| 720 | 6 | public function registerObserver(ObserverInterface $observer, $type) |
|
| 732 | |||
| 733 | /** |
||
| 734 | * Register the passed callback with the specific type. |
||
| 735 | * |
||
| 736 | * @param \TechDivision\Import\Callbacks\CallbackInterface $callback The subject to register the callbacks for |
||
| 737 | * @param string $type The type to register the callback with |
||
| 738 | * |
||
| 739 | * @return void |
||
| 740 | */ |
||
| 741 | 2 | public function registerCallback(CallbackInterface $callback, $type) |
|
| 753 | |||
| 754 | /** |
||
| 755 | * Return's the array with callbacks for the passed type. |
||
| 756 | * |
||
| 757 | * @param string $type The type of the callbacks to return |
||
| 758 | * |
||
| 759 | * @return array The callbacks |
||
| 760 | */ |
||
| 761 | 1 | public function getCallbacksByType($type) |
|
| 775 | |||
| 776 | /** |
||
| 777 | * Return's the array with the available observers. |
||
| 778 | * |
||
| 779 | * @return array The observers |
||
| 780 | */ |
||
| 781 | 6 | public function getObservers() |
|
| 785 | |||
| 786 | /** |
||
| 787 | * Return's the array with the available callbacks. |
||
| 788 | * |
||
| 789 | * @return array The callbacks |
||
| 790 | */ |
||
| 791 | 1 | public function getCallbacks() |
|
| 795 | |||
| 796 | /** |
||
| 797 | * Return's the callback mappings for this subject. |
||
| 798 | * |
||
| 799 | * @return array The array with the subject's callback mappings |
||
| 800 | */ |
||
| 801 | 2 | public function getCallbackMappings() |
|
| 805 | |||
| 806 | /** |
||
| 807 | * Imports the content of the file with the passed filename. |
||
| 808 | * |
||
| 809 | * |
||
| 810 | * @param string $serial The serial of the actual import |
||
| 811 | * @param string $filename The filename to process |
||
| 812 | * |
||
| 813 | * @return void |
||
| 814 | * @throws \Exception Is thrown, if the import can't be processed |
||
| 815 | */ |
||
| 816 | 5 | public function import($serial, $filename) |
|
| 882 | |||
| 883 | /** |
||
| 884 | * This method queries whether or not the passed filename matches |
||
| 885 | * the pattern, based on the subjects configured prefix. |
||
| 886 | * |
||
| 887 | * @param string $filename The filename to match |
||
| 888 | * |
||
| 889 | * @return boolean TRUE if the filename matches, else FALSE |
||
| 890 | */ |
||
| 891 | 5 | protected function match($filename) |
|
| 904 | |||
| 905 | /** |
||
| 906 | * Imports the passed row into the database. If the import failed, the exception |
||
| 907 | * will be catched and logged, but the import process will be continued. |
||
| 908 | * |
||
| 909 | * @param array $row The row with the data to be imported |
||
| 910 | * |
||
| 911 | * @return void |
||
| 912 | */ |
||
| 913 | 7 | public function importRow(array $row) |
|
| 957 | |||
| 958 | /** |
||
| 959 | * Map the passed attribute code, if a header mapping exists and return the |
||
| 960 | * mapped mapping. |
||
| 961 | * |
||
| 962 | * @param string $attributeCode The attribute code to map |
||
| 963 | * |
||
| 964 | * @return string The mapped attribute code, or the original one |
||
| 965 | */ |
||
| 966 | 2 | public function mapAttributeCodeByHeaderMapping($attributeCode) |
|
| 980 | |||
| 981 | /** |
||
| 982 | * Queries whether or not that the subject needs an OK file to be processed. |
||
| 983 | * |
||
| 984 | * @return boolean TRUE if the subject needs an OK file, else FALSE |
||
| 985 | */ |
||
| 986 | 1 | public function isOkFileNeeded() |
|
| 990 | |||
| 991 | /** |
||
| 992 | * Return's the default store. |
||
| 993 | * |
||
| 994 | * @return array The default store |
||
| 995 | */ |
||
| 996 | 4 | public function getDefaultStore() |
|
| 1000 | |||
| 1001 | /** |
||
| 1002 | * Set's the store view code the create the product/attributes for. |
||
| 1003 | * |
||
| 1004 | * @param string $storeViewCode The store view code |
||
| 1005 | * |
||
| 1006 | * @return void |
||
| 1007 | */ |
||
| 1008 | 4 | public function setStoreViewCode($storeViewCode) |
|
| 1012 | |||
| 1013 | /** |
||
| 1014 | * Return's the store view code the create the product/attributes for. |
||
| 1015 | * |
||
| 1016 | * @param string|null $default The default value to return, if the store view code has not been set |
||
| 1017 | * |
||
| 1018 | * @return string The store view code |
||
| 1019 | */ |
||
| 1020 | 8 | public function getStoreViewCode($default = null) |
|
| 1034 | |||
| 1035 | /** |
||
| 1036 | * Return's the store ID of the store with the passed store view code |
||
| 1037 | * |
||
| 1038 | * @param string $storeViewCode The store view code to return the store ID for |
||
| 1039 | * |
||
| 1040 | * @return integer The ID of the store with the passed ID |
||
| 1041 | * @throws \Exception Is thrown, if the store with the actual code is not available |
||
| 1042 | */ |
||
| 1043 | 4 | public function getStoreId($storeViewCode) |
|
| 1061 | |||
| 1062 | /** |
||
| 1063 | * Return's the store ID of the actual row, or of the default store |
||
| 1064 | * if no store view code is set in the CSV file. |
||
| 1065 | * |
||
| 1066 | * @param string|null $default The default store view code to use, if no store view code is set in the CSV file |
||
| 1067 | * |
||
| 1068 | * @return integer The ID of the actual store |
||
| 1069 | * @throws \Exception Is thrown, if the store with the actual code is not available |
||
| 1070 | */ |
||
| 1071 | 2 | public function getRowStoreId($default = null) |
|
| 1083 | |||
| 1084 | /** |
||
| 1085 | * Prepare's the store view code in the subject. |
||
| 1086 | * |
||
| 1087 | * @return void |
||
| 1088 | */ |
||
| 1089 | 2 | public function prepareStoreViewCode() |
|
| 1100 | |||
| 1101 | /** |
||
| 1102 | * Return's the root category for the actual view store. |
||
| 1103 | * |
||
| 1104 | * @return array The store's root category |
||
| 1105 | * @throws \Exception Is thrown if the root category for the passed store code is NOT available |
||
| 1106 | */ |
||
| 1107 | 2 | public function getRootCategory() |
|
| 1124 | |||
| 1125 | /** |
||
| 1126 | * Return's the Magento configuration value. |
||
| 1127 | * |
||
| 1128 | * @param string $path The Magento path of the requested configuration value |
||
| 1129 | * @param mixed $default The default value that has to be returned, if the requested configuration value is not set |
||
| 1130 | * @param string $scope The scope the configuration value has been set |
||
| 1131 | * @param integer $scopeId The scope ID the configuration value has been set |
||
| 1132 | * |
||
| 1133 | * @return mixed The configuration value |
||
| 1134 | * @throws \Exception Is thrown, if nor a value can be found or a default value has been passed |
||
| 1135 | */ |
||
| 1136 | 5 | public function getCoreConfigData($path, $default = null, $scope = ScopeKeys::SCOPE_DEFAULT, $scopeId = 0) |
|
| 1212 | |||
| 1213 | /** |
||
| 1214 | * Resolve the original column name for the passed one. |
||
| 1215 | * |
||
| 1216 | * @param string $columnName The column name that has to be resolved |
||
| 1217 | * |
||
| 1218 | * @return string|null The original column name |
||
| 1219 | */ |
||
| 1220 | 2 | public function resolveOriginalColumnName($columnName) |
|
| 1242 | |||
| 1243 | /** |
||
| 1244 | * Return's the original data if available, or an empty array. |
||
| 1245 | * |
||
| 1246 | * @return array The original data |
||
| 1247 | */ |
||
| 1248 | 2 | public function getOriginalData() |
|
| 1263 | |||
| 1264 | /** |
||
| 1265 | * Query's whether or not the actual column contains original data like |
||
| 1266 | * filename, line number and column names. |
||
| 1267 | * |
||
| 1268 | * @return boolean TRUE if the actual column contains origin data, else FALSE |
||
| 1269 | */ |
||
| 1270 | 3 | public function hasOriginalData() |
|
| 1274 | |||
| 1275 | /** |
||
| 1276 | * Wraps the passed exeception into a new one by trying to resolve the original filname, |
||
| 1277 | * line number and column names and use it for a detailed exception message. |
||
| 1278 | * |
||
| 1279 | * @param array $columnNames The column names that should be resolved and wrapped |
||
| 1280 | * @param \Exception $parent The exception we want to wrap |
||
| 1281 | * @param string $className The class name of the exception type we want to wrap the parent one |
||
| 1282 | * |
||
| 1283 | * @return \Exception the wrapped exception |
||
| 1284 | */ |
||
| 1285 | 2 | public function wrapException( |
|
| 1330 | |||
| 1331 | /** |
||
| 1332 | * Strip's the exception suffix containing filename and line number from the |
||
| 1333 | * passed message. |
||
| 1334 | * |
||
| 1335 | * @param string $message The message to strip the exception suffix from |
||
| 1336 | * |
||
| 1337 | * @return mixed The message without the exception suffix |
||
| 1338 | */ |
||
| 1339 | 2 | public function stripExceptionSuffix($message) |
|
| 1343 | |||
| 1344 | /** |
||
| 1345 | * Append's the exception suffix containing filename and line number to the |
||
| 1346 | * passed message. If no message has been passed, only the suffix will be |
||
| 1347 | * returned |
||
| 1348 | * |
||
| 1349 | * @param string|null $message The message to append the exception suffix to |
||
| 1350 | * @param string|null $filename The filename used to create the suffix |
||
| 1351 | * @param string|null $lineNumber The line number used to create the suffx |
||
| 1352 | * |
||
| 1353 | * @return string The message with the appended exception suffix |
||
| 1354 | */ |
||
| 1355 | 7 | public function appendExceptionSuffix($message = null, $filename = null, $lineNumber = null) |
|
| 1376 | |||
| 1377 | /** |
||
| 1378 | * Raises the value for the counter with the passed key by one. |
||
| 1379 | * |
||
| 1380 | * @param mixed $counterName The name of the counter to raise |
||
| 1381 | * |
||
| 1382 | * @return integer The counter's new value |
||
| 1383 | */ |
||
| 1384 | 1 | public function raiseCounter($counterName) |
|
| 1393 | |||
| 1394 | /** |
||
| 1395 | * Merge the passed array into the status of the actual import. |
||
| 1396 | * |
||
| 1397 | * @param array $status The status information to be merged |
||
| 1398 | * |
||
| 1399 | * @return void |
||
| 1400 | */ |
||
| 1401 | 1 | public function mergeAttributesRecursive(array $status) |
|
| 1410 | } |
||
| 1411 |
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.