| Conditions | 6 |
| Paths | 6 |
| Total Lines | 74 |
| 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 declare(strict_types=1); |
||
| 62 | public function execute(Script $script, array $commands) |
||
| 63 | { |
||
| 64 | $this->logger->startScript($script); |
||
| 65 | |||
| 66 | $this->executeTemplateRendering(); |
||
| 67 | |||
| 68 | foreach ($commands as $index => $command) { |
||
| 69 | switch ($command) { |
||
| 70 | case $command instanceof ProcessCommand: |
||
| 71 | $parsedCommand = $this->getParsedShellCommand($command); |
||
|
|
|||
| 72 | $process = $this->environment->createProcess($parsedCommand); |
||
| 73 | $this->setProcessDefaults($command, $process); |
||
| 74 | |||
| 75 | if ($command->isDeferred()) { |
||
| 76 | $this->logger->logStart( |
||
| 77 | 'Defering', |
||
| 78 | $parsedCommand, |
||
| 79 | $command->getLineNumber(), |
||
| 80 | $command->isIgnoreError(), |
||
| 81 | $index, |
||
| 82 | count($commands) |
||
| 83 | ); |
||
| 84 | $this->deferProcess($command, $process); |
||
| 85 | } else { |
||
| 86 | $this->logger->logStart( |
||
| 87 | 'Starting', |
||
| 88 | $parsedCommand, |
||
| 89 | $command->getLineNumber(), |
||
| 90 | $command->isIgnoreError(), |
||
| 91 | $index, |
||
| 92 | count($commands) |
||
| 93 | ); |
||
| 94 | |||
| 95 | $this->runProcess($process); |
||
| 96 | $this->testProcessResultValid($command, $process); |
||
| 97 | } |
||
| 98 | |||
| 99 | break; |
||
| 100 | |||
| 101 | |||
| 102 | case $command instanceof TemplateCommand: |
||
| 103 | $template = $command->getTemplate(); |
||
| 104 | |||
| 105 | $this->logger->logStart( |
||
| 106 | 'Template', |
||
| 107 | $template->getDestination(), |
||
| 108 | $command->getLineNumber(), |
||
| 109 | false, |
||
| 110 | $index, |
||
| 111 | count($commands) |
||
| 112 | ); |
||
| 113 | |||
| 114 | $this->renderTemplate($template); |
||
| 115 | break; |
||
| 116 | |||
| 117 | case $command instanceof WaitCommand: |
||
| 118 | $this->logger->logStart( |
||
| 119 | 'Waiting', |
||
| 120 | '', |
||
| 121 | $command->getLineNumber(), |
||
| 122 | false, |
||
| 123 | $index, |
||
| 124 | count($commands) |
||
| 125 | ); |
||
| 126 | |||
| 127 | $this->waitForDeferredProcesses(); |
||
| 128 | break; |
||
| 129 | } |
||
| 130 | } |
||
| 131 | |||
| 132 | $this->waitForDeferredProcesses(); |
||
| 133 | |||
| 134 | $this->logger->finishScript($script); |
||
| 135 | } |
||
| 136 | |||
| 262 |
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.