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 |
||
| 44 | class BunchSubject extends AbstractCategorySubject implements ExportableSubjectInterface, FileUploadSubjectInterface, UrlKeyAwareSubjectInterface |
||
| 45 | { |
||
| 46 | |||
| 47 | /** |
||
| 48 | * The trait that implements the export functionality. |
||
| 49 | * |
||
| 50 | * @var \TechDivision\Import\Subjects\ExportableTrait |
||
| 51 | */ |
||
| 52 | use ExportableTrait; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * The trait that provides file upload functionality. |
||
| 56 | * |
||
| 57 | * @var \TechDivision\Import\Subjects\FileUploadTrait |
||
| 58 | */ |
||
| 59 | use FileUploadTrait; |
||
| 60 | |||
| 61 | /** |
||
| 62 | * The array with the available display mode keys. |
||
| 63 | * |
||
| 64 | * @var array |
||
| 65 | */ |
||
| 66 | protected $availableDisplayModes = array( |
||
| 67 | 'Products only' => DisplayModeKeys::DISPLAY_MODE_PRODUCTS_ONLY, |
||
| 68 | 'Static block only' => DisplayModeKeys::DISPLAY_MODE_STATIC_BLOCK_ONLY, |
||
| 69 | 'Static block and products' => DisplayModeKeys::DISPLAY_MODE_BOTH |
||
| 70 | ); |
||
| 71 | |||
| 72 | /** |
||
| 73 | * The array with the available page layout keys. |
||
| 74 | * |
||
| 75 | * @var array |
||
| 76 | */ |
||
| 77 | protected $availablePageLayouts = array( |
||
| 78 | '1 column' => PageLayoutKeys::PAGE_LAYOUT_1_COLUMN, |
||
| 79 | '2 columns with left bar' => PageLayoutKeys::PAGE_LAYOUT_2_COLUMNS_LEFT, |
||
| 80 | '2 columns with right bar' => PageLayoutKeys::PAGE_LAYOUT_2_COLUMNS_RIGHT, |
||
| 81 | '3 columns' => PageLayoutKeys::PAGE_LAYOUT_3_COLUMNS, |
||
| 82 | 'Empty' => PageLayoutKeys::PAGE_LAYOUT_EMPTY |
||
| 83 | ); |
||
| 84 | /** |
||
| 85 | * The default callback mappings for the Magento standard category attributes. |
||
| 86 | * |
||
| 87 | * @var array |
||
| 88 | */ |
||
| 89 | protected $defaultCallbackMappings = array( |
||
| 90 | 'display_mode' => array('import_category.callback.display.mode'), |
||
| 91 | 'page_layout' => array('import_category.callback.page.layout'), |
||
| 92 | ); |
||
| 93 | |||
| 94 | /** |
||
| 95 | * The available entity types. |
||
| 96 | * |
||
| 97 | * @var array |
||
| 98 | */ |
||
| 99 | protected $entityTypes = array(); |
||
| 100 | |||
| 101 | /** |
||
| 102 | * Intializes the previously loaded global data for exactly one bunch. |
||
| 103 | * |
||
| 104 | * @param string $serial The serial of the actual import |
||
| 105 | * |
||
| 106 | * @return void |
||
| 107 | */ |
||
| 108 | public function setUp($serial) |
||
| 109 | { |
||
| 110 | |||
| 111 | // load the status of the actual import |
||
| 112 | $status = $this->getRegistryProcessor()->getAttribute(RegistryKeys::STATUS); |
||
| 113 | |||
| 114 | // load the global data we've prepared initially |
||
| 115 | $this->entityTypes = $status[RegistryKeys::GLOBAL_DATA][RegistryKeys::ENTITY_TYPES]; |
||
| 116 | |||
| 117 | // initialize the flag whether to copy images or not |
||
| 118 | if ($this->getConfiguration()->hasParam(ConfigurationKeys::COPY_IMAGES)) { |
||
| 119 | $this->setCopyImages($this->getConfiguration()->getParam(ConfigurationKeys::COPY_IMAGES)); |
||
|
|
|||
| 120 | } |
||
| 121 | |||
| 122 | // initialize media directory => can be absolute or relative |
||
| 123 | View Code Duplication | if ($this->getConfiguration()->hasParam(ConfigurationKeys::MEDIA_DIRECTORY)) { |
|
| 124 | try { |
||
| 125 | $this->setMediaDir($this->resolvePath($this->getConfiguration()->getParam(ConfigurationKeys::MEDIA_DIRECTORY))); |
||
| 126 | } catch (\InvalidArgumentException $iae) { |
||
| 127 | $this->getSystemLogger()->warning($iae); |
||
| 128 | } |
||
| 129 | } |
||
| 130 | |||
| 131 | // initialize images directory => can be absolute or relative |
||
| 132 | View Code Duplication | if ($this->getConfiguration()->hasParam(ConfigurationKeys::IMAGES_FILE_DIRECTORY)) { |
|
| 133 | try { |
||
| 134 | $this->setImagesFileDir($this->resolvePath($this->getConfiguration()->getParam(ConfigurationKeys::IMAGES_FILE_DIRECTORY))); |
||
| 135 | } catch (\InvalidArgumentException $iae) { |
||
| 136 | $this->getSystemLogger()->warning($iae); |
||
| 137 | } |
||
| 138 | } |
||
| 139 | |||
| 140 | // prepare the callbacks |
||
| 141 | parent::setUp($serial); |
||
| 142 | } |
||
| 143 | |||
| 144 | /** |
||
| 145 | * Return's the default callback mappings. |
||
| 146 | * |
||
| 147 | * @return array The default callback mappings |
||
| 148 | */ |
||
| 149 | public function getDefaultCallbackMappings() |
||
| 153 | |||
| 154 | /** |
||
| 155 | * Return's the display mode for the passed display mode string. |
||
| 156 | * |
||
| 157 | * @param string $displayMode The display mode string to return the key for |
||
| 158 | * |
||
| 159 | * @return integer The requested display mode |
||
| 160 | * @throws \Exception Is thrown, if the requested display mode is not available |
||
| 161 | */ |
||
| 162 | public function getDisplayModeByValue($displayMode) |
||
| 177 | |||
| 178 | /** |
||
| 179 | * Return's the page layout for the passed page layout string. |
||
| 180 | * |
||
| 181 | * @param string $pageLayout The page layout string to return the key for |
||
| 182 | * |
||
| 183 | * @return integer The requested page layout |
||
| 184 | * @throws \Exception Is thrown, if the requested page layout is not available |
||
| 185 | */ |
||
| 186 | public function getPageLayoutByValue($pageLayout) |
||
| 201 | |||
| 202 | /** |
||
| 203 | * Return's the available store view codes of the available stores. |
||
| 204 | * |
||
| 205 | * @return array The array with the available store view codes |
||
| 206 | */ |
||
| 207 | public function getStoreViewCodes() |
||
| 211 | |||
| 212 | /** |
||
| 213 | * Returns the store view codes relevant to the category represented by the current row. |
||
| 214 | * |
||
| 215 | * @param string $path The path to return the root category's store view codes for |
||
| 216 | * |
||
| 217 | * @return array The store view codes for the given root category |
||
| 218 | * @throws \Exception Is thrown, if the root category of the passed path is NOT available |
||
| 219 | */ |
||
| 220 | public function getRootCategoryStoreViewCodes($path) |
||
| 250 | |||
| 251 | /** |
||
| 252 | * Return's the PK column name to create the product => attribute relation. |
||
| 253 | * |
||
| 254 | * @return string The PK column name |
||
| 255 | */ |
||
| 256 | protected function getPrimaryKeyMemberName() |
||
| 260 | |||
| 261 | /** |
||
| 262 | * Return's the entity type for the configured entity type code. |
||
| 263 | * |
||
| 264 | * @return array The requested entity type |
||
| 265 | * @throws \Exception Is thrown, if the requested entity type is not available |
||
| 266 | */ |
||
| 267 | View Code Duplication | public function getEntityType() |
|
| 282 | |||
| 283 | /** |
||
| 284 | * Return's TRUE, if the passed URL key varchar value IS related with the actual PK. |
||
| 285 | * |
||
| 286 | * @param array $categoryVarcharAttribute The varchar value to check |
||
| 287 | * |
||
| 288 | * @return boolean TRUE if the URL key is related, else FALSE |
||
| 289 | */ |
||
| 290 | public function isUrlKeyOf(array $categoryVarcharAttribute) |
||
| 295 | } |
||
| 296 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: