Conditions | 8 |
Paths | 32 |
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 |
||
117 | public function writeLogLine(Tick $tick) |
||
118 | { |
||
119 | // Line segments |
||
120 | $lineSegs = array(); |
||
121 | |||
122 | // 1st Segment is a star |
||
123 | switch ($tick->getStatus()) { |
||
124 | case Tick::SUCCESS: |
||
125 | $lineSegs[] = sprintf("<fg=green>%s</fg=green>", $this->linePrefixMap[Tick::SUCCESS]); |
||
126 | break; |
||
127 | case Tick::FAIL: |
||
128 | $lineSegs[] = sprintf("<fg=red>%s</fg=red>", $this->linePrefixMap[Tick::FAIL]); |
||
129 | break; |
||
130 | case Tick::SKIP: |
||
131 | default: |
||
132 | $lineSegs[] = $this->linePrefixMap[Tick::SKIP]; |
||
133 | } |
||
134 | |||
135 | // Item Progress |
||
136 | $lineSegs[] = sprintf( |
||
137 | "[%s%s]", |
||
138 | $tick->getReport()->getNumItemsProcessed(), |
||
139 | $tick->getReport()->getTotalItemCount() != Tracker::UNKNOWN ? "/" . $tick->getReport()->getTotalItemCount() : '' |
||
140 | ); |
||
141 | |||
142 | // If verbose, add walltime and item counts |
||
143 | if ($this->output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) { |
||
144 | $lineSegs[] = $this->formatSeconds($tick->getReport()->getTimeElapsed()); |
||
145 | |||
146 | $lineSegs[] = sprintf( |
||
147 | '(<fg=green>%s</fg=green>/%s/<fg=red>%s</fg=red>)', |
||
148 | $tick->getReport()->getNumItemsSuccess(), |
||
149 | $tick->getReport()->getNumItemsSkip(), |
||
150 | $tick->getReport()->getNumItemsFail() |
||
151 | ); |
||
152 | } |
||
153 | |||
154 | // If very verbose, add memory usage |
||
155 | if ($this->output->getVerbosity() >= OutputInterface::VERBOSITY_VERY_VERBOSE) { |
||
156 | $lineSegs[] = sprintf("{%s/%s}", |
||
157 | $this->bytesToHuman($tick->getReport()->getMemUsage()), |
||
158 | $this->bytesToHuman($tick->getReport()->getMemPeakUsage()) |
||
159 | ); |
||
160 | } |
||
161 | |||
162 | // Add message |
||
163 | $lineSegs[] = $tick->getMessage() ?: sprintf( |
||
164 | "Processing item %s", |
||
165 | number_format($tick->getReport()->getNumItemsProcessed(), 0) |
||
166 | ); |
||
167 | |||
168 | // Output it! |
||
169 | $this->output->writeln(implode(' ', $lineSegs)); |
||
170 | } |
||
171 | |||
198 |