| Conditions | 10 | 
| Paths | 25 | 
| 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 |         try { | ||
| 95 | // try to set the entity IDs for the category with the passed path | ||
| 96 |             if ($category = $this->getCategoryByPath($this->getValue(ColumnKeys::PATH)) && $this->hasValue(ColumnKeys::URL_KEY)) { | ||
| 97 | $this->setIds($category); | ||
|  | |||
| 98 |             } else { | ||
| 99 | // @todo See PAC-307 | ||
| 100 | // category already exists and NO new URL key | ||
| 101 | // has been specified in column `url_key`, so | ||
| 102 | // we stop processing here | ||
| 103 | |||
| 104 | return; | ||
| 105 | } | ||
| 106 |         } catch (\Exception $e) { | ||
| 107 | $this->setIds(array()); | ||
| 108 | } | ||
| 109 | |||
| 110 | // prepare the store view code | ||
| 111 | $this->prepareStoreViewCode(); | ||
| 112 | |||
| 113 | // load ID of the actual store view | ||
| 114 | $storeId = $this->getRowStoreId(StoreViewCodes::ADMIN); | ||
| 115 | |||
| 116 | // explode the path into the category names | ||
| 117 |         if ($categories = $this->explode($this->getValue(ColumnKeys::PATH), '/')) { | ||
| 118 | // initialize the array for the category paths | ||
| 119 | $categoryPaths = array(); | ||
| 120 | // iterate over the parent category names and try | ||
| 121 | // to load the categories to build the URL path | ||
| 122 |             for ($i = sizeof($categories) - 1; $i > 1; $i--) { | ||
| 123 |                 try { | ||
| 124 | // prepare the expected category name | ||
| 125 |                     $categoryPath = implode('/', array_slice($categories, 0, $i)); | ||
| 126 | // load the existing category and prepend the URL key the array with the category URL keys | ||
| 127 | $existingCategory = $this->getCategoryByPkAndStoreId($this->mapPath($categoryPath), $storeId); | ||
| 128 | // query whether or not an URL key is available or not | ||
| 129 |                     if (isset($existingCategory[MemberNames::URL_KEY])) { | ||
| 130 | array_unshift($categoryPaths, $existingCategory[MemberNames::URL_KEY]); | ||
| 131 |                     } else { | ||
| 132 |                         $this->getSystemLogger()->debug(sprintf('Can\'t find URL key for category "%s"', $categoryPath)); | ||
| 133 | } | ||
| 134 |                 } catch (\Exception $e) { | ||
| 135 |                     $this->getSystemLogger()->debug(sprintf('Can\'t load parent category "%s"', $categoryPath)); | ||
| 136 | } | ||
| 137 | } | ||
| 138 | } | ||
| 139 | |||
| 140 | // query whether or not the URL key column has a | ||
| 141 | // value, if yes, use the value from the column | ||
| 142 |         if ($this->hasValue(ColumnKeys::URL_KEY)) { | ||
| 143 | $urlKey = $this->getValue(ColumnKeys::URL_KEY); | ||
| 144 |         } else { | ||
| 145 | // initialize the URL key with the converted name | ||
| 146 | $urlKey = $this->convertNameToUrlKey($this->getValue(ColumnKeys::NAME)); | ||
| 147 | } | ||
| 148 | |||
| 149 | // update the URL key with the unique value | ||
| 150 | $this->setValue( | ||
| 151 | ColumnKeys::URL_KEY, | ||
| 152 |             $urlKey = $this->makeUnique($this->getSubject(), $urlKey, implode('/', $categoryPaths)) | ||
| 153 | ); | ||
| 154 | |||
| 155 | // finally, append the URL key as last element to the path | ||
| 156 | array_push($categoryPaths, $urlKey); | ||
| 157 | |||
| 158 | // create the virtual column for the URL path | ||
| 159 |         if ($this->hasHeader(ColumnKeys::URL_PATH) === false) { | ||
| 160 | $this->addHeader(ColumnKeys::URL_PATH); | ||
| 161 | } | ||
| 162 | |||
| 163 | // set the URL path | ||
| 164 |         $this->setValue(ColumnKeys::URL_PATH, implode('/', $categoryPaths)); | ||
| 165 | } | ||
| 166 | |||
| 260 | 
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: