| Conditions | 10 |
| Paths | 62 |
| Total Lines | 70 |
| 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 | $categories = array(); |
||
| 97 | $category = array(); |
||
| 98 | |||
| 99 | // set the entity ID for the category with the passed path |
||
| 100 | try { |
||
| 101 | $this->setIds($category = $this->getCategoryByPath($this->getValue(ColumnKeys::PATH))); |
||
| 102 | } catch (\Exception $e) { |
||
| 103 | $this->setIds(array()); |
||
| 104 | } |
||
| 105 | |||
| 106 | // query whether or not the URL key column has a value |
||
| 107 | if ($this->hasValue(ColumnKeys::URL_KEY)) { |
||
| 108 | $urlKey = $this->makeUnique($this->getSubject(), $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 new URL key |
||
| 115 | // has been specified in column `url_key`, so |
||
| 116 | // we stop processing here |
||
| 117 | return; |
||
| 118 | } |
||
| 119 | $this->setValue( |
||
| 120 | ColumnKeys::URL_KEY, |
||
| 121 | $urlKey = $this->makeUnique($this->getSubject(), $this->convertNameToUrlKey($this->getValue(ColumnKeys::NAME))) |
||
| 122 | ); |
||
| 123 | } |
||
| 124 | |||
| 125 | // explode the path into the category names |
||
| 126 | if ($categories = $this->explode($this->getValue(ColumnKeys::PATH), '/')) { |
||
| 127 | // initialize the category with the actual category's URL key |
||
| 128 | $categoryPaths = array($urlKey); |
||
| 129 | // prepare the store view code |
||
| 130 | $this->prepareStoreViewCode(); |
||
| 131 | // load ID of the actual store view |
||
| 132 | $storeId = $this->getRowStoreId(StoreViewCodes::ADMIN); |
||
| 133 | |||
| 134 | // iterate over the category names and try to load the category therefore |
||
| 135 | for ($i = sizeof($categories) - 1; $i > 1; $i--) { |
||
| 136 | try { |
||
| 137 | // prepare the expected category name |
||
| 138 | $categoryPath = implode('/', array_slice($categories, 0, $i)); |
||
| 139 | // load the existing category and prepend the URL key the array with the category URL keys |
||
| 140 | $existingCategory = $this->getCategoryByPkAndStoreId($this->mapPath($categoryPath), $storeId); |
||
| 141 | // query whether or not an URL key is available or not |
||
| 142 | if (isset($existingCategory[MemberNames::URL_KEY])) { |
||
| 143 | array_unshift($categoryPaths, $existingCategory[MemberNames::URL_KEY]); |
||
| 144 | } else { |
||
| 145 | $this->getSystemLogger()->debug(sprintf('Can\'t find URL key for category %s', $categoryPath)); |
||
| 146 | } |
||
| 147 | } catch (\Exception $e) { |
||
| 148 | $this->getSystemLogger()->debug(sprintf('Can\'t load parent category %s', $categoryPath)); |
||
| 149 | } |
||
| 150 | } |
||
| 151 | |||
| 152 | // create the header for the URL path |
||
| 153 | if (!$this->hasHeader(ColumnKeys::URL_PATH)) { |
||
| 154 | $this->addHeader(ColumnKeys::URL_PATH); |
||
| 155 | } |
||
| 156 | |||
| 157 | // set the URL path |
||
| 158 | $this->setValue(ColumnKeys::URL_PATH, implode('/', $categoryPaths)); |
||
| 159 | } |
||
| 160 | } |
||
| 161 | |||
| 255 |
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.