Conditions | 12 |
Paths | 85 |
Total Lines | 58 |
Code Lines | 32 |
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 |
||
111 | private function runCommand(Process $process) |
||
112 | { |
||
113 | $output = $this->output; |
||
114 | |||
115 | /** @type DebugFormatterHelper $debugFormatter */ |
||
116 | $debugFormatter = $this->getHelperSet()->get('debug_formatter'); |
||
117 | if (null !== $dispatcher = $this->getEventDispatcher()) { |
||
118 | $event = new PreExecuteEvent($this, $process); |
||
119 | $dispatcher->dispatch(Event::PRE_EXECUTE, $event); |
||
120 | |||
121 | if ($event->isPropagationStopped()) { |
||
122 | $output->writeln( |
||
123 | ['', sprintf(' <info>[%s]</info> - <comment>Stopped</comment>', $this->getName()), ''] |
||
124 | ); |
||
125 | |||
126 | return true; |
||
127 | } |
||
128 | } |
||
129 | |||
130 | if ($output->getVerbosity() === OutputInterface::VERBOSITY_VERBOSE || $this->getParameter('dry_run')) { |
||
131 | $output->writeln(' // '.$process->getCommandLine()); |
||
132 | } |
||
133 | |||
134 | if ($this->getParameter('dry_run')) { |
||
135 | return true; |
||
136 | } |
||
137 | |||
138 | if ($this->hasParameter('cwd')) { |
||
139 | $process->setWorkingDirectory($this->getParameter('cwd')); |
||
140 | } |
||
141 | |||
142 | if ($output->getVerbosity() === OutputInterface::VERBOSITY_VERY_VERBOSE) { |
||
143 | $output->writeln( |
||
144 | sprintf( |
||
145 | ' // Setting timeout for %d seconds.', |
||
146 | $this->getParameter('timeout') |
||
147 | ) |
||
148 | ); |
||
149 | } |
||
150 | $process->setTimeout($this->getParameter('timeout') !== 0 ? $this->getParameter('timeout') : null); |
||
151 | |||
152 | if ($this->hasParameter('output')) { |
||
153 | $append = $this->hasParameter('append') && $this->getParameter('append') ? 'a' : 'w'; |
||
154 | $stream = fopen($this->getParameter('output'), $append); |
||
155 | $output = new StreamOutput($stream, StreamOutput::VERBOSITY_NORMAL, true); |
||
156 | } |
||
157 | |||
158 | $output->writeln( |
||
159 | $debugFormatter->start( |
||
160 | spl_object_hash($process), |
||
161 | $process->getCommandLine() |
||
162 | ) |
||
163 | ); |
||
164 | |||
165 | $process->start(); |
||
166 | |||
167 | return $process; |
||
168 | } |
||
169 | |||
201 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.