| Conditions | 13 |
| Paths | 18 |
| Total Lines | 89 |
| 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 |
||
| 52 | public function indexAction() |
||
| 53 | { |
||
| 54 | // console purge <entity> <id> |
||
| 55 | |||
| 56 | /* @var EntityEraser $eraser */ |
||
| 57 | |||
| 58 | $console = $this->getConsole(); |
||
| 59 | $eraser = $this->plugin(EntityEraser::class); |
||
| 60 | $options = \Zend\Json\Json::decode($this->params('options', '{}'), \Zend\Json\Json::TYPE_ARRAY); |
||
| 61 | $eraser->setOptions($options); |
||
| 62 | $entities = $eraser->loadEntities($this->params('entity'), $this->params('id')); |
||
|
|
|||
| 63 | |||
| 64 | $found = count($entities); |
||
| 65 | $console->writeLine(sprintf('Found %s entities to purge.', $found)); |
||
| 66 | |||
| 67 | if (0 == $found) { |
||
| 68 | return; |
||
| 69 | } |
||
| 70 | |||
| 71 | if (!$this->params('no-check')) { |
||
| 72 | |||
| 73 | |||
| 74 | $console->writeLine('Checking dependencies ... ' . PHP_EOL); |
||
| 75 | |||
| 76 | $eraser = $this->plugin(EntityEraser::class); |
||
| 77 | $counts = []; |
||
| 78 | $totalCount = 0; |
||
| 79 | foreach ($entities as $entity) { |
||
| 80 | $console->writeLine(' ' . $this->entityToString($entity)); |
||
| 81 | $totalCount += 1; |
||
| 82 | $dependencies = $eraser->checkDependencies($entity); |
||
| 83 | |||
| 84 | foreach ($dependencies as $dependencyList) { |
||
| 85 | $console->writeLine(' ' . $dependencyList->getName() . ': ' . $dependencyList->getDescription()); |
||
| 86 | $dependendEntities = $dependencyList->getEntities(); |
||
| 87 | $totalCount += count($dependendEntities); |
||
| 88 | if (!isset($counts[$dependencyList->getName()])) { $counts[$dependencyList->getName()] = 0; } |
||
| 89 | $counts[$dependencyList->getName()] += count($dependendEntities); |
||
| 90 | |||
| 91 | foreach ($dependendEntities as $dependendEntity) { |
||
| 92 | $console->writeLine(' - ' . $this->entityToString($dependendEntity)); |
||
| 93 | } |
||
| 94 | $console->writeLine(' '); |
||
| 95 | } |
||
| 96 | $console->writeLine(''); |
||
| 97 | } |
||
| 98 | |||
| 99 | $console->writeLine($totalCount . ' entities affected:'); |
||
| 100 | $console->writeLine(' ' . count($entities) . ' ' . $this->params('entity')); |
||
| 101 | foreach ($counts as $name => $count) { |
||
| 102 | $console->writeLine(' ' . $count . ' ' . $name); |
||
| 103 | } |
||
| 104 | |||
| 105 | $console->writeLine(''); |
||
| 106 | $confirmed = \Zend\Console\Prompt\Confirm::prompt('Proceed? [y/n] '); |
||
| 107 | |||
| 108 | if (!$confirmed) { |
||
| 109 | $console->writeLine('Aborted.'); |
||
| 110 | exit(1); |
||
| 111 | } |
||
| 112 | } |
||
| 113 | |||
| 114 | |||
| 115 | $totalCount = 0; |
||
| 116 | $counts = []; |
||
| 117 | |||
| 118 | $progress = new ProgressBar(count($entities)); |
||
| 119 | $i = 0; |
||
| 120 | foreach ($entities as $entity) { |
||
| 121 | $progress->update(++$i, $entity->getId()); |
||
| 122 | $dependencies = $eraser->erase($entity); |
||
| 123 | |||
| 124 | $totalCount += 1; |
||
| 125 | foreach ($dependencies as $list) { |
||
| 126 | $totalCount += count($list->getEntities()); |
||
| 127 | if (!isset($counts[$list->getName()])) { $counts[$list->getName()] = [0, $list->getDescription()]; } |
||
| 128 | $counts[$list->getName()][0] += count($list->getEntities()); |
||
| 129 | } |
||
| 130 | } |
||
| 131 | |||
| 132 | $progress->finish(); |
||
| 133 | $console->writeLine(''); |
||
| 134 | $console->writeLine('Processed ' . $totalCount . ' entities.'); |
||
| 135 | $console->writeLine(' ' . count($entities) . ' ' . $this->params('entity') . ' deleted.'); |
||
| 136 | foreach ($counts as $name => $count) { |
||
| 137 | $console->writeLine(' ' . $count[0] . ' ' . $name . ' ' . $count[1]); |
||
| 138 | } |
||
| 139 | |||
| 140 | } |
||
| 141 | |||
| 189 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.