| Conditions | 11 |
| Paths | 150 |
| Total Lines | 75 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 91 | protected function process() |
||
| 92 | { |
||
| 93 | |||
| 94 | // initialize the URL key and array for the categories |
||
| 95 | $urlKey = null; |
||
| 96 | $category = array(); |
||
| 97 | |||
| 98 | // set the entity ID for the category with the passed path |
||
| 99 | try { |
||
| 100 | $this->setIds($category = $this->getCategoryByPath($this->getValue(ColumnKeys::PATH))); |
||
| 101 | } catch (\Exception $e) { |
||
| 102 | $this->setIds(array()); |
||
| 103 | } |
||
| 104 | |||
| 105 | // query whether or not the URL key column has a value |
||
| 106 | if ($this->hasValue(ColumnKeys::URL_KEY)) { |
||
| 107 | $urlKey = $this->makeUnique($this->getSubject(), $this->getValue(ColumnKeys::URL_KEY)); |
||
|
|
|||
| 108 | } else { |
||
| 109 | // query whether or not the column `url_key` has a value |
||
| 110 | if ($category && |
||
| 111 | !$this->getSubject()->getConfiguration()->getParam(ConfigurationKeys::UPDATE_URL_KEY_FROM_NAME, true) |
||
| 112 | ) { |
||
| 113 | // product already exists and NO recalc from product key, |
||
| 114 | // so we search origin url_key from product |
||
| 115 | $urlKey = $this->loadUrlKey( |
||
| 116 | $this->getSubject(), |
||
| 117 | $this->getPrimaryKey() |
||
| 118 | ); |
||
| 119 | } |
||
| 120 | if (!$urlKey) { |
||
| 121 | $urlKey = $this->makeUnique($this->getSubject(), $this->convertNameToUrlKey($this->getValue(ColumnKeys::NAME))); |
||
| 122 | } |
||
| 123 | // let the `url_key` has a value |
||
| 124 | $this->setValue( |
||
| 125 | ColumnKeys::URL_KEY, |
||
| 126 | $urlKey |
||
| 127 | ); |
||
| 128 | } |
||
| 129 | |||
| 130 | // explode the path into the category names |
||
| 131 | if ($categories = $this->explode($this->getValue(ColumnKeys::PATH), '/')) { |
||
| 132 | // initialize the category with the actual category's URL key |
||
| 133 | $categoryPaths = array($urlKey); |
||
| 134 | // prepare the store view code |
||
| 135 | $this->prepareStoreViewCode(); |
||
| 136 | // load ID of the actual store view |
||
| 137 | $storeId = $this->getRowStoreId(StoreViewCodes::ADMIN); |
||
| 138 | |||
| 139 | // iterate over the category names and try to load the category therefore |
||
| 140 | for ($i = sizeof($categories) - 1; $i > 1; $i--) { |
||
| 141 | try { |
||
| 142 | // prepare the expected category name |
||
| 143 | $categoryPath = implode('/', array_slice($categories, 0, $i)); |
||
| 144 | // load the existing category and prepend the URL key the array with the category URL keys |
||
| 145 | $existingCategory = $this->getCategoryByPkAndStoreId($this->mapPath($categoryPath), $storeId); |
||
| 146 | // query whether or not an URL key is available or not |
||
| 147 | if (isset($existingCategory[MemberNames::URL_KEY])) { |
||
| 148 | array_unshift($categoryPaths, $existingCategory[MemberNames::URL_KEY]); |
||
| 149 | } else { |
||
| 150 | $this->getSystemLogger()->debug(sprintf('Can\'t find URL key for category %s', $categoryPath)); |
||
| 151 | } |
||
| 152 | } catch (\Exception $e) { |
||
| 153 | $this->getSystemLogger()->debug(sprintf('Can\'t load parent category %s', $categoryPath)); |
||
| 154 | } |
||
| 155 | } |
||
| 156 | |||
| 157 | // create the header for the URL path |
||
| 158 | if (!$this->hasHeader(ColumnKeys::URL_PATH)) { |
||
| 159 | $this->addHeader(ColumnKeys::URL_PATH); |
||
| 160 | } |
||
| 161 | |||
| 162 | // set the URL path |
||
| 163 | $this->setValue(ColumnKeys::URL_PATH, implode('/', $categoryPaths)); |
||
| 164 | } |
||
| 165 | } |
||
| 166 | |||
| 283 |
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: