Conditions | 15 |
Paths | 26 |
Total Lines | 97 |
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 | if ($dependencyList->isCount()) { |
||
86 | $entitiesCount = $dependencyList->getEntities(); |
||
87 | $dependendEntities = []; |
||
88 | } else { |
||
89 | $dependendEntities = $dependencyList->getEntities(); |
||
90 | $entitiesCount = count($dependendEntities); |
||
91 | } |
||
92 | |||
93 | $console->writeLine(' ' . $entitiesCount . ' ' . $dependencyList->getName() . ': ' . $dependencyList->getDescription()); |
||
94 | |||
95 | $totalCount += $entitiesCount; |
||
96 | if (!isset($counts[$dependencyList->getName()])) { $counts[$dependencyList->getName()] = 0; } |
||
97 | $counts[$dependencyList->getName()] += $entitiesCount; |
||
98 | |||
99 | foreach ($dependendEntities as $dependendEntity) { |
||
100 | $console->writeLine(' - ' . $this->entityToString($dependendEntity)); |
||
101 | } |
||
102 | $console->writeLine(' '); |
||
103 | } |
||
104 | $console->writeLine(''); |
||
105 | } |
||
106 | |||
107 | $console->writeLine($totalCount . ' entities affected:'); |
||
108 | $console->writeLine(' ' . count($entities) . ' ' . $this->params('entity')); |
||
109 | foreach ($counts as $name => $count) { |
||
110 | $console->writeLine(' ' . $count . ' ' . $name); |
||
111 | } |
||
112 | |||
113 | $console->writeLine(''); |
||
114 | $confirmed = \Zend\Console\Prompt\Confirm::prompt('Proceed? [y/n] '); |
||
115 | |||
116 | if (!$confirmed) { |
||
117 | $console->writeLine('Aborted.'); |
||
118 | exit(1); |
||
119 | } |
||
120 | } |
||
121 | |||
122 | |||
123 | $totalCount = 0; |
||
124 | $counts = []; |
||
125 | |||
126 | $progress = new ProgressBar(count($entities)); |
||
127 | $i = 0; |
||
128 | foreach ($entities as $entity) { |
||
129 | $progress->update(++$i, $entity->getId()); |
||
130 | $dependencies = $eraser->erase($entity); |
||
131 | |||
132 | $totalCount += 1; |
||
133 | foreach ($dependencies as $list) { |
||
134 | $entitiesCount = $list->isCount() ? $list->getEntities() : count($list->getEntities()); |
||
135 | $totalCount += $entitiesCount; |
||
136 | if (!isset($counts[$list->getName()])) { $counts[$list->getName()] = [0, $list->getDescription()]; } |
||
137 | $counts[$list->getName()][0] += $entitiesCount; |
||
138 | } |
||
139 | } |
||
140 | |||
141 | $progress->finish(); |
||
142 | $console->writeLine(''); |
||
143 | $console->writeLine('Processed ' . $totalCount . ' entities.'); |
||
144 | $console->writeLine(' ' . count($entities) . ' ' . $this->params('entity') . ' deleted.'); |
||
145 | foreach ($counts as $name => $count) { |
||
146 | $console->writeLine(' ' . $count[0] . ' ' . $name . ' ' . $count[1]); |
||
147 | } |
||
148 | } |
||
149 | |||
197 |
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.