| Conditions | 15 |
| Paths | 56 |
| Total Lines | 110 |
| Code Lines | 55 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 1 | Features | 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 |
||
| 113 | public function writeFinalReport($duration, $summary) |
||
| 114 | { |
||
| 115 | // keep count of what the final results are |
||
| 116 | $succeededGroups = []; |
||
| 117 | $skippedGroups = []; |
||
| 118 | $failedGroups = []; |
||
| 119 | |||
| 120 | // do we have any results? |
||
| 121 | if (!isset($this->results)) { |
||
| 122 | // huh - nothing happened at all |
||
| 123 | $this->write("HUH - nothing appears to have happened. Time taken: ", $this->writer->puzzledSummaryStyle); |
||
| 124 | $this->writeDuration($duration, $this->writer->puzzledSummaryStyle); |
||
| 125 | $this->write(PHP_EOL . PHP_EOL); |
||
| 126 | return 1; |
||
| 127 | } |
||
| 128 | |||
| 129 | // this is our opportunity to tell the user how our story(ies) |
||
| 130 | // went in detail |
||
| 131 | foreach ($this->results as $result) |
||
| 132 | { |
||
| 133 | // so what happened? |
||
| 134 | switch ($result->resultCode) |
||
| 135 | { |
||
| 136 | case PhaseGroup_Result::OKAY: |
||
| 137 | // this is a good result |
||
| 138 | $succeededGroups[] = $result; |
||
| 139 | break; |
||
| 140 | |||
| 141 | case PhaseGroup_Result::SKIPPED: |
||
| 142 | case PhaseGroup_Result::BLACKLISTED: |
||
| 143 | // this can legitimately happen |
||
| 144 | $skippedGroups[] = $result; |
||
| 145 | break; |
||
| 146 | |||
| 147 | default: |
||
| 148 | // everything else is an error of some kind |
||
| 149 | $failedGroups[] = $result; |
||
| 150 | } |
||
| 151 | } |
||
| 152 | |||
| 153 | // what's the final tally? |
||
| 154 | $this->write(PHP_EOL); |
||
| 155 | if (empty($succeededGroups) && empty($skippedGroups) && empty($failedGroups)) { |
||
| 156 | // huh - nothing happened at all |
||
| 157 | $this->write("HUH - nothing appears to have happened. Time taken: ", $this->writer->puzzledSummaryStyle); |
||
| 158 | $this->writeDuration($duration, $this->writer->puzzledSummaryStyle); |
||
| 159 | $this->write(PHP_EOL . PHP_EOL); |
||
| 160 | return 1; |
||
| 161 | } |
||
| 162 | if (empty($failedGroups)) { |
||
| 163 | // nothing failed |
||
| 164 | $this->write("SUCCESS - " . count($succeededGroups) . ' PASSED, ' . count($skippedGroups) . ' SKIPPED. Time taken: ', $this->writer->successSummaryStyle); |
||
| 165 | $this->writeDuration($duration, $this->writer->successSummaryStyle); |
||
| 166 | $this->write(PHP_EOL . PHP_EOL); |
||
| 167 | return 0; |
||
| 168 | } |
||
| 169 | |||
| 170 | // if we get here, then at least one thing failed |
||
| 171 | $this->write("FAILURE - " |
||
| 172 | . count($succeededGroups) . ' PASSED, ' |
||
| 173 | . count($skippedGroups) . ' SKIPPED, ' |
||
| 174 | . count($failedGroups) . ' FAILED :( Time taken: ', |
||
| 175 | $this->writer->failSummaryStyle); |
||
| 176 | $this->writeDuration($duration, $this->writer->failSummaryStyle); |
||
| 177 | $this->write(PHP_EOL . PHP_EOL); |
||
| 178 | |||
| 179 | // write out a list of failed tests - someone will want to look |
||
| 180 | // at them in detail |
||
| 181 | $this->write("Here's the list of everything that failed:" . PHP_EOL . PHP_EOL); |
||
| 182 | // foreach ($skippedGroups as $skippedGroup) { |
||
| 183 | // $this->writePhaseGroupSkipped(); |
||
| 184 | // $this->write(' ' . $skippedGroup->activity, $this->writer->activityStyle); |
||
| 185 | // $this->write(' ' . $skippedGroup->name . PHP_EOL, $this->writer->nameStyle); |
||
| 186 | |||
| 187 | // if (isset($skippedGroup->filename)) { |
||
| 188 | // $this->write(' (', $this->writer->punctuationStyle); |
||
| 189 | // $this->write($skippedGroup->filename, $this->writer->punctuationStyle); |
||
| 190 | // $this->write(')' . PHP_EOL, $this->writer->punctuationStyle); |
||
| 191 | // } |
||
| 192 | // } |
||
| 193 | foreach ($failedGroups as $failedGroup) { |
||
| 194 | $this->writePhaseGroupFailed(); |
||
| 195 | $this->write(' ' . $failedGroup->activity, $this->writer->activityStyle); |
||
| 196 | $this->write(' ' . $failedGroup->name . PHP_EOL, $this->writer->nameStyle); |
||
| 197 | |||
| 198 | if (isset($failedGroup->filename)) { |
||
| 199 | $this->write(' (', $this->writer->punctuationStyle); |
||
| 200 | $this->write($failedGroup->filename, $this->writer->punctuationStyle); |
||
| 201 | $this->write(')' . PHP_EOL, $this->writer->punctuationStyle); |
||
| 202 | } |
||
| 203 | } |
||
| 204 | $this->write(PHP_EOL); |
||
| 205 | |||
| 206 | // do we stop here? |
||
| 207 | if (!$summary) { |
||
| 208 | // we're in dev mode, which means the error reports have |
||
| 209 | // already been shown where they happened |
||
| 210 | return 1; |
||
| 211 | } |
||
| 212 | |||
| 213 | // are we being run by hand? |
||
| 214 | if (function_exists("posix_isatty") && posix_isatty(STDOUT)) { |
||
| 215 | $this->write("See "); |
||
| 216 | $this->write("storyplayer.log", $this->writer->argStyle); |
||
| 217 | $this->write(" for details on what went wrong." . PHP_EOL . PHP_EOL); |
||
| 218 | } |
||
| 219 | |||
| 220 | // all done |
||
| 221 | return 1; |
||
| 222 | } |
||
| 223 | |||
| 364 |
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.