| Conditions | 8 |
| Paths | 60 |
| Total Lines | 60 |
| 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 |
||
| 90 | protected function process() |
||
| 91 | { |
||
| 92 | |||
| 93 | // initialize the URL key and array for the categories |
||
| 94 | $urlKey = null; |
||
|
|
|||
| 95 | $categories = array(); |
||
| 96 | |||
| 97 | // set the entity ID for the category with the passed path |
||
| 98 | try { |
||
| 99 | $this->setIds($this->getCategoryByPath($this->getValue(ColumnKeys::PATH))); |
||
| 100 | } catch (\Exception $e) { |
||
| 101 | $this->setIds(array()); |
||
| 102 | } |
||
| 103 | |||
| 104 | // query whether or not the URL key column has a value |
||
| 105 | if ($this->hasValue(ColumnKeys::URL_KEY)) { |
||
| 106 | $urlKey = $this->makeUnique($this->getSubject(), $this->getValue(ColumnKeys::URL_KEY)); |
||
| 107 | } else { |
||
| 108 | $this->setValue( |
||
| 109 | ColumnKeys::URL_KEY, |
||
| 110 | $urlKey = $this->makeUnique($this->getSubject(), $this->convertNameToUrlKey($this->getValue(ColumnKeys::NAME))) |
||
| 111 | ); |
||
| 112 | } |
||
| 113 | |||
| 114 | // explode the path into the category names |
||
| 115 | if ($categories = $this->explode($this->getValue(ColumnKeys::PATH), '/')) { |
||
| 116 | // initialize the category with the actual category's URL key |
||
| 117 | $categoryPaths = array($urlKey); |
||
| 118 | // prepare the store view code |
||
| 119 | $this->prepareStoreViewCode(); |
||
| 120 | // load ID of the actual store view |
||
| 121 | $storeId = $this->getRowStoreId(StoreViewCodes::ADMIN); |
||
| 122 | |||
| 123 | // iterate over the category names and try to load the category therefore |
||
| 124 | for ($i = sizeof($categories) - 1; $i > 1; $i--) { |
||
| 125 | try { |
||
| 126 | // prepare the expected category name |
||
| 127 | $categoryPath = implode('/', array_slice($categories, 0, $i)); |
||
| 128 | // load the existing category and prepend the URL key the array with the category URL keys |
||
| 129 | $existingCategory = $this->getCategoryByPkAndStoreId($this->mapPath($categoryPath), $storeId); |
||
| 130 | // query whether or not an URL key is available or not |
||
| 131 | if (isset($existingCategory[MemberNames::URL_KEY])) { |
||
| 132 | array_unshift($categoryPaths, $existingCategory[MemberNames::URL_KEY]); |
||
| 133 | } else { |
||
| 134 | $this->getSystemLogger()->debug(sprintf('Can\'t find URL key for category %s', $categoryPath)); |
||
| 135 | } |
||
| 136 | } catch (\Exception $e) { |
||
| 137 | $this->getSystemLogger()->debug(sprintf('Can\'t load parent category %s', $categoryPath)); |
||
| 138 | } |
||
| 139 | } |
||
| 140 | |||
| 141 | // create the header for the URL path |
||
| 142 | if (!$this->hasHeader(ColumnKeys::URL_PATH)) { |
||
| 143 | $this->addHeader(ColumnKeys::URL_PATH); |
||
| 144 | } |
||
| 145 | |||
| 146 | // set the URL path |
||
| 147 | $this->setValue(ColumnKeys::URL_PATH, implode('/', $categoryPaths)); |
||
| 148 | } |
||
| 149 | } |
||
| 150 | |||
| 243 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.