| Conditions | 7 |
| Paths | 34 |
| Total Lines | 51 |
| Code Lines | 25 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 52 | protected function process() |
||
| 53 | { |
||
| 54 | |||
| 55 | // initialize the URL key and array for the categories |
||
| 56 | $urlKey = null; |
||
|
|
|||
| 57 | $categories = array(); |
||
| 58 | |||
| 59 | // query whether or not the URL key column has a value |
||
| 60 | if ($this->hasValue(ColumnKeys::URL_KEY)) { |
||
| 61 | $urlKey = $this->getValue(ColumnKeys::URL_KEY); |
||
| 62 | } else { |
||
| 63 | $this->setValue( |
||
| 64 | ColumnKeys::URL_KEY, |
||
| 65 | $urlKey = $this->convertNameToUrlKey($this->getValue(ColumnKeys::NAME)) |
||
| 66 | ); |
||
| 67 | } |
||
| 68 | |||
| 69 | // explode the path into the category names |
||
| 70 | if ($categories = $this->explode($this->getValue(ColumnKeys::PATH), '/')) { |
||
| 71 | // initialize the category with the actual category's URL key |
||
| 72 | $categoryPaths = array($urlKey); |
||
| 73 | |||
| 74 | // iterate over the category names and try to load the category therefore |
||
| 75 | for ($i = sizeof($categories); $i > 1; $i--) { |
||
| 76 | try { |
||
| 77 | // prepare the expected category name |
||
| 78 | $categoryPath = implode('/', array_slice($categories, 0, $i)); |
||
| 79 | |||
| 80 | // load the existing category and prepend the URL key the array with the category URL keys |
||
| 81 | $existingCategory = $this->getCategoryByPath($categoryPath); |
||
| 82 | if (isset($existingCategory[MemberNames::URL_KEY])) { |
||
| 83 | array_unshift($categoryPaths, $existingCategory[MemberNames::URL_KEY]); |
||
| 84 | } else { |
||
| 85 | error_log(var_export($existingCategory, true)); |
||
| 86 | $this->getSystemLogger()->debug(sprintf('Can\'t find URL key for category %s', $categoryPath)); |
||
| 87 | } |
||
| 88 | |||
| 89 | } catch (\Exception $e) { |
||
| 90 | $this->getSystemLogger()->debug(sprintf('Can\'t load parent category %s', $categoryPath)); |
||
| 91 | } |
||
| 92 | } |
||
| 93 | |||
| 94 | // create the header for the URL path |
||
| 95 | if (!$this->hasHeader(ColumnKeys::URL_PATH)) { |
||
| 96 | $this->addHeader(ColumnKeys::URL_PATH); |
||
| 97 | } |
||
| 98 | |||
| 99 | // set the URL path |
||
| 100 | $this->setValue(ColumnKeys::URL_PATH, implode('/', $categoryPaths)); |
||
| 101 | } |
||
| 102 | } |
||
| 103 | |||
| 116 |
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.