| Conditions | 11 | 
| Paths | 40 | 
| Total Lines | 83 | 
| 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 = false;  | 
            ||
| 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  | 
            ||
| 106 | // value, if yes, use the value from the column  | 
            ||
| 107 |         if ($this->hasValue(ColumnKeys::URL_KEY)) { | 
            ||
| 108 | $urlKey = $this->getValue(ColumnKeys::URL_KEY);  | 
            ||
| 109 |         } else { | 
            ||
| 110 | // query whether or not the column `url_key` has a value  | 
            ||
| 111 | if ($category &&  | 
            ||
| 
                                                                                                    
                        
                         | 
                |||
| 112 | !$this->getSubject()->getConfiguration()->getParam(ConfigurationKeys::UPDATE_URL_KEY_FROM_NAME, true)  | 
            ||
| 113 |             ) { | 
            ||
| 114 | // product already exists and NO recalc from product key,  | 
            ||
| 115 | // so we search origin url_key from product  | 
            ||
| 116 | $urlKey = $this->loadUrlKey(  | 
            ||
| 117 | $this->getSubject(),  | 
            ||
| 118 | $this->getPrimaryKey()  | 
            ||
| 119 | );  | 
            ||
| 120 | }  | 
            ||
| 121 |             if (!$urlKey) { | 
            ||
| 122 | // initialize the URL key with the converted name  | 
            ||
| 123 | $urlKey = $this->convertNameToUrlKey($this->getValue(ColumnKeys::NAME));  | 
            ||
| 124 | }  | 
            ||
| 125 | }  | 
            ||
| 126 | |||
| 127 | // prepare the store view code  | 
            ||
| 128 | $this->prepareStoreViewCode();  | 
            ||
| 129 | |||
| 130 | // load ID of the actual store view  | 
            ||
| 131 | $storeId = $this->getRowStoreId(StoreViewCodes::ADMIN);  | 
            ||
| 132 | |||
| 133 | // explode the path into the category names  | 
            ||
| 134 |         if ($categories = $this->explode($this->getValue(ColumnKeys::PATH), '/')) { | 
            ||
| 135 | // initialize the array for the category paths  | 
            ||
| 136 | $categoryPaths = array();  | 
            ||
| 137 | // iterate over the parent category names and try  | 
            ||
| 138 | // to load the categories to build the URL path  | 
            ||
| 139 |             for ($i = sizeof($categories) - 1; $i > 1; $i--) { | 
            ||
| 140 |                 try { | 
            ||
| 141 | // prepare the expected category name  | 
            ||
| 142 |                     $categoryPath = implode('/', array_slice($categories, 0, $i)); | 
            ||
| 143 | // load the existing category and prepend the URL key the array with the category URL keys  | 
            ||
| 144 | $existingCategory = $this->getCategoryByPkAndStoreId($this->mapPath($categoryPath), $storeId);  | 
            ||
| 145 | // query whether or not an URL key is available or not  | 
            ||
| 146 |                     if (isset($existingCategory[MemberNames::URL_KEY])) { | 
            ||
| 147 | array_unshift($categoryPaths, $existingCategory[MemberNames::URL_KEY]);  | 
            ||
| 148 |                     } else { | 
            ||
| 149 |                         $this->getSystemLogger()->debug(sprintf('Can\'t find URL key for category "%s"', $categoryPath)); | 
            ||
| 150 | }  | 
            ||
| 151 |                 } catch (\Exception $e) { | 
            ||
| 152 |                     $this->getSystemLogger()->debug(sprintf('Can\'t load parent category "%s"', $categoryPath)); | 
            ||
| 153 | }  | 
            ||
| 154 | }  | 
            ||
| 155 | }  | 
            ||
| 156 | |||
| 157 | // update the URL key with the unique value  | 
            ||
| 158 | $this->setValue(  | 
            ||
| 159 | ColumnKeys::URL_KEY,  | 
            ||
| 160 |             $urlKey = $this->makeUnique($this->getSubject(), $urlKey, implode('/', $categoryPaths)) | 
            ||
| 161 | );  | 
            ||
| 162 | |||
| 163 | // finally, append the URL key as last element to the path  | 
            ||
| 164 | array_push($categoryPaths, $urlKey);  | 
            ||
| 165 | |||
| 166 | // create the virtual column for the URL path  | 
            ||
| 167 |         if ($this->hasHeader(ColumnKeys::URL_PATH) === false) { | 
            ||
| 168 | $this->addHeader(ColumnKeys::URL_PATH);  | 
            ||
| 169 | }  | 
            ||
| 170 | |||
| 171 | // set the URL path  | 
            ||
| 172 |         $this->setValue(ColumnKeys::URL_PATH, implode('/', $categoryPaths)); | 
            ||
| 173 | }  | 
            ||
| 174 | |||
| 291 | 
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.