| Conditions | 7 |
| Paths | 48 |
| Total Lines | 54 |
| 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 |
||
| 41 | public function generateAction() |
||
| 42 | { |
||
| 43 | $beVerbose = $this->beVerbose(); |
||
| 44 | |||
| 45 | $configuration = $this->configuration; |
||
| 46 | $console = $this->getConsole(); |
||
| 47 | $processPipe = $this->processPipe; |
||
| 48 | |||
| 49 | try { |
||
| 50 | $this->throwExceptionIfNotCalledInsideAnCliEnvironment(); |
||
| 51 | $configuration = $configuration['name_to_configuration_path']; |
||
| 52 | |||
| 53 | if ($this->hasParameter('locator_name')) { |
||
| 54 | $locatorName = $this->getParameter('locator_name'); |
||
| 55 | |||
| 56 | if (!isset($configuration[$locatorName])) { |
||
| 57 | throw new InvalidArgumentException( |
||
| 58 | 'invalid locator name provided' |
||
| 59 | ); |
||
| 60 | } |
||
| 61 | |||
| 62 | $namesToPath = array($locatorName => $configuration[$locatorName]); |
||
| 63 | } else { |
||
| 64 | $namesToPath = $configuration; |
||
| 65 | } |
||
| 66 | |||
| 67 | //@todo implement usage of $this->processItems(); |
||
| 68 | foreach ($namesToPath as $name => $path) { |
||
| 69 | if ($beVerbose) { |
||
| 70 | $console->writeLine( |
||
| 71 | 'generating "' . $name . '" by using configuration file "' . $path . '"' |
||
| 72 | ); |
||
| 73 | } else { |
||
| 74 | $console->write('.'); |
||
| 75 | } |
||
| 76 | |||
| 77 | $arguments = array( |
||
| 78 | __FILE__, |
||
| 79 | $path |
||
| 80 | ); |
||
| 81 | |||
| 82 | try { |
||
| 83 | $processPipe->execute($arguments); |
||
| 84 | } catch (Exception $exception) { |
||
| 85 | $console->setColor(ColorInterface::LIGHT_RED); |
||
| 86 | $console->writeLine('could not generate locator for "' . $name . '"'); |
||
| 87 | $console->writeLine('error: ' . $exception->getMessage()); |
||
| 88 | $console->resetColor(); |
||
| 89 | } |
||
| 90 | } |
||
| 91 | } catch (Exception $exception) { |
||
| 92 | $this->handleException($exception); |
||
| 93 | } |
||
| 94 | } |
||
| 95 | |||
| 121 | } |