| Conditions | 18 |
| Paths | 8320 |
| Total Lines | 111 |
| Code Lines | 66 |
| 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 |
||
| 136 | public function run(TestResult $result = null) |
||
| 137 | { |
||
| 138 | $sections = $this->parse(); |
||
| 139 | $code = $this->render($sections['FILE']); |
||
| 140 | |||
| 141 | if ($result === null) { |
||
| 142 | $result = new TestResult; |
||
| 143 | } |
||
| 144 | |||
| 145 | $skip = false; |
||
| 146 | $xfail = false; |
||
| 147 | $time = 0; |
||
| 148 | $settings = $this->settings; |
||
| 149 | |||
| 150 | $result->startTest($this); |
||
| 151 | |||
| 152 | if (isset($sections['INI'])) { |
||
| 153 | $settings = \array_merge($settings, $this->parseIniSection($sections['INI'])); |
||
| 154 | } |
||
| 155 | |||
| 156 | if (isset($sections['ENV'])) { |
||
| 157 | $env = $this->parseEnvSection($sections['ENV']); |
||
| 158 | $this->phpUtil->setEnv($env); |
||
| 159 | } |
||
| 160 | |||
| 161 | // Redirects STDERR to STDOUT |
||
| 162 | $this->phpUtil->setUseStderrRedirection(true); |
||
| 163 | |||
| 164 | if ($result->enforcesTimeLimit()) { |
||
| 165 | $this->phpUtil->setTimeout($result->getTimeoutForLargeTests()); |
||
| 166 | } |
||
| 167 | |||
| 168 | if (isset($sections['SKIPIF'])) { |
||
| 169 | $skipif = $this->render($sections['SKIPIF']); |
||
| 170 | $jobResult = $this->phpUtil->runJob($skipif, $settings); |
||
| 171 | |||
| 172 | if (!\strncasecmp('skip', \ltrim($jobResult['stdout']), 4)) { |
||
| 173 | if (\preg_match('/^\s*skip\s*(.+)\s*/i', $jobResult['stdout'], $message)) { |
||
| 174 | $message = \substr($message[1], 2); |
||
| 175 | } else { |
||
| 176 | $message = ''; |
||
| 177 | } |
||
| 178 | |||
| 179 | $result->addFailure($this, new SkippedTestError($message), 0); |
||
| 180 | |||
| 181 | $skip = true; |
||
| 182 | } |
||
| 183 | } |
||
| 184 | |||
| 185 | if (isset($sections['XFAIL'])) { |
||
| 186 | $xfail = \trim($sections['XFAIL']); |
||
| 187 | } |
||
| 188 | |||
| 189 | if (!$skip) { |
||
| 190 | if (isset($sections['STDIN'])) { |
||
| 191 | $this->phpUtil->setStdin($sections['STDIN']); |
||
| 192 | } |
||
| 193 | |||
| 194 | if (isset($sections['ARGS'])) { |
||
| 195 | $this->phpUtil->setArgs($sections['ARGS']); |
||
| 196 | } |
||
| 197 | |||
| 198 | PHP_Timer::start(); |
||
| 199 | |||
| 200 | $jobResult = $this->phpUtil->runJob($code, $settings); |
||
| 201 | $time = PHP_Timer::stop(); |
||
| 202 | |||
| 203 | try { |
||
| 204 | $this->assertPhptExpectation($sections, $jobResult['stdout']); |
||
| 205 | } catch (AssertionFailedError $e) { |
||
| 206 | if ($xfail !== false) { |
||
| 207 | $result->addFailure( |
||
| 208 | $this, |
||
| 209 | new IncompleteTestError( |
||
| 210 | $xfail, |
||
| 211 | 0, |
||
| 212 | $e |
||
| 213 | ), |
||
| 214 | $time |
||
| 215 | ); |
||
| 216 | } else { |
||
| 217 | $result->addFailure($this, $e, $time); |
||
| 218 | } |
||
| 219 | } catch (Throwable $t) { |
||
| 220 | $result->addError($this, $t, $time); |
||
| 221 | } |
||
| 222 | |||
| 223 | if ($result->allCompletelyImplemented() && $xfail !== false) { |
||
| 224 | $result->addFailure( |
||
| 225 | $this, |
||
| 226 | new IncompleteTestError( |
||
| 227 | 'XFAIL section but test passes' |
||
| 228 | ), |
||
| 229 | $time |
||
| 230 | ); |
||
| 231 | } |
||
| 232 | |||
| 233 | $this->phpUtil->setStdin(''); |
||
| 234 | $this->phpUtil->setArgs(''); |
||
| 235 | |||
| 236 | if (isset($sections['CLEAN'])) { |
||
| 237 | $cleanCode = $this->render($sections['CLEAN']); |
||
| 238 | |||
| 239 | $this->phpUtil->runJob($cleanCode, $this->settings); |
||
| 240 | } |
||
| 241 | } |
||
| 242 | |||
| 243 | $result->endTest($this, $time); |
||
| 244 | |||
| 245 | return $result; |
||
| 246 | } |
||
| 247 | |||
| 441 |