| Conditions | 16 |
| Paths | 768 |
| Total Lines | 52 |
| Code Lines | 36 |
| 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 |
||
| 91 | public function createIO( |
||
| 92 | Application $application, |
||
| 93 | RawArgs $args, |
||
| 94 | InputStream $inputStream = null, |
||
| 95 | OutputStream $outputStream = null, |
||
| 96 | OutputStream $errorStream = null |
||
| 97 | ) { |
||
| 98 | $inputStream = $inputStream ?: new StandardInputStream(); |
||
| 99 | $outputStream = $outputStream ?: new StandardOutputStream(); |
||
| 100 | $errorStream = $errorStream ?: new ErrorOutputStream(); |
||
| 101 | $styleSet = $application->getConfig()->getStyleSet(); |
||
| 102 | |||
| 103 | if ($args->hasToken('--no-ansi')) { |
||
| 104 | $outputFormatter = $errorFormatter = new PlainFormatter($styleSet); |
||
| 105 | } elseif ($args->hasToken('--ansi')) { |
||
| 106 | $outputFormatter = $errorFormatter = new AnsiFormatter($styleSet); |
||
| 107 | } else { |
||
| 108 | $outputFormatter = $outputStream->supportsAnsi() |
||
| 109 | ? new AnsiFormatter($styleSet) |
||
| 110 | : new PlainFormatter($styleSet) |
||
| 111 | ; |
||
| 112 | |||
| 113 | $errorFormatter = $errorStream->supportsAnsi() |
||
| 114 | ? new AnsiFormatter($styleSet) |
||
| 115 | : new PlainFormatter($styleSet) |
||
| 116 | ; |
||
| 117 | } |
||
| 118 | |||
| 119 | $io = new ConsoleIO( |
||
| 120 | new Input($inputStream), |
||
| 121 | new Output($outputStream, $outputFormatter), |
||
| 122 | new Output($errorStream, $errorFormatter) |
||
| 123 | ); |
||
| 124 | |||
| 125 | if ($args->hasToken('-vvv') || $this->isDebug()) { |
||
| 126 | $io->setVerbosity(IO::DEBUG); |
||
| 127 | } elseif ($args->hasToken('-vv')) { |
||
| 128 | $io->setVerbosity(IO::VERY_VERBOSE); |
||
| 129 | } elseif ($args->hasToken('-v')) { |
||
| 130 | $io->setVerbosity(IO::VERBOSE); |
||
| 131 | } |
||
| 132 | |||
| 133 | if ($args->hasToken('--quiet') || $args->hasToken('-q')) { |
||
| 134 | $io->setQuiet(true); |
||
| 135 | } |
||
| 136 | |||
| 137 | if ($args->hasToken('--no-interaction') || $args->hasToken('-n')) { |
||
| 138 | $io->setInteractive(false); |
||
| 139 | } |
||
| 140 | |||
| 141 | return $io; |
||
| 142 | } |
||
| 143 | |||
| 175 |