| Conditions | 59 |
| Paths | > 20000 |
| Total Lines | 235 |
| Code Lines | 131 |
| 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 declare(strict_types=1); |
||
| 180 | protected function handleArguments(array $argv): void |
||
| 181 | { |
||
| 182 | try { |
||
| 183 | $arguments = (new ArgumentsBuilder)->fromParameters($argv, \array_keys($this->longOptions)); |
||
| 184 | } catch (ArgumentsException $e) { |
||
| 185 | $this->exitWithErrorMessage($e->getMessage()); |
||
| 186 | } |
||
| 187 | |||
| 188 | \assert(isset($arguments) && $arguments instanceof Arguments); |
||
| 189 | |||
| 190 | if ($arguments->hasGenerateConfiguration() && $arguments->generateConfiguration()) { |
||
| 191 | $this->printVersionString(); |
||
| 192 | |||
| 193 | print 'Generating phpunit.xml in ' . \getcwd() . \PHP_EOL . \PHP_EOL; |
||
| 194 | print 'Bootstrap script (relative to path shown above; default: vendor/autoload.php): '; |
||
| 195 | |||
| 196 | $bootstrapScript = \trim(\fgets(\STDIN)); |
||
| 197 | |||
| 198 | print 'Tests directory (relative to path shown above; default: tests): '; |
||
| 199 | |||
| 200 | $testsDirectory = \trim(\fgets(\STDIN)); |
||
| 201 | |||
| 202 | print 'Source directory (relative to path shown above; default: src): '; |
||
| 203 | |||
| 204 | $src = \trim(\fgets(\STDIN)); |
||
| 205 | |||
| 206 | if ($bootstrapScript === '') { |
||
| 207 | $bootstrapScript = 'vendor/autoload.php'; |
||
| 208 | } |
||
| 209 | |||
| 210 | if ($testsDirectory === '') { |
||
| 211 | $testsDirectory = 'tests'; |
||
| 212 | } |
||
| 213 | |||
| 214 | if ($src === '') { |
||
| 215 | $src = 'src'; |
||
| 216 | } |
||
| 217 | |||
| 218 | $generator = new Generator; |
||
| 219 | |||
| 220 | \file_put_contents( |
||
| 221 | 'phpunit.xml', |
||
| 222 | $generator->generateDefaultConfiguration( |
||
| 223 | Version::series(), |
||
| 224 | $bootstrapScript, |
||
| 225 | $testsDirectory, |
||
| 226 | $src |
||
| 227 | ) |
||
| 228 | ); |
||
| 229 | |||
| 230 | print \PHP_EOL . 'Generated phpunit.xml in ' . \getcwd() . \PHP_EOL; |
||
| 231 | |||
| 232 | exit(TestRunner::SUCCESS_EXIT); |
||
| 233 | } |
||
| 234 | |||
| 235 | if ($arguments->hasAtLeastVersion()) { |
||
| 236 | if (\version_compare(Version::id(), $arguments->atLeastVersion(), '>=')) { |
||
| 237 | exit(TestRunner::SUCCESS_EXIT); |
||
| 238 | } |
||
| 239 | |||
| 240 | exit(TestRunner::FAILURE_EXIT); |
||
| 241 | } |
||
| 242 | |||
| 243 | if ($arguments->hasVersion() && $arguments->version()) { |
||
| 244 | $this->printVersionString(); |
||
| 245 | |||
| 246 | exit(TestRunner::SUCCESS_EXIT); |
||
| 247 | } |
||
| 248 | |||
| 249 | if ($arguments->hasCheckVersion() && $arguments->checkVersion()) { |
||
| 250 | $this->handleVersionCheck(); |
||
| 251 | } |
||
| 252 | |||
| 253 | if ($arguments->hasHelp()) { |
||
| 254 | $this->showHelp(); |
||
| 255 | |||
| 256 | exit(TestRunner::SUCCESS_EXIT); |
||
| 257 | } |
||
| 258 | |||
| 259 | if ($arguments->hasUnrecognizedOrderBy()) { |
||
| 260 | $this->exitWithErrorMessage( |
||
| 261 | \sprintf( |
||
| 262 | 'unrecognized --order-by option: %s', |
||
| 263 | $arguments->unrecognizedOrderBy() |
||
| 264 | ) |
||
| 265 | ); |
||
| 266 | } |
||
| 267 | |||
| 268 | if ($arguments->hasIniSettings()) { |
||
| 269 | foreach ($arguments->iniSettings() as $name => $value) { |
||
| 270 | \ini_set($name, $value); |
||
| 271 | } |
||
| 272 | } |
||
| 273 | |||
| 274 | if ($arguments->hasIncludePath()) { |
||
| 275 | \ini_set( |
||
| 276 | 'include_path', |
||
| 277 | $arguments->includePath() . \PATH_SEPARATOR . \ini_get('include_path') |
||
| 278 | ); |
||
| 279 | } |
||
| 280 | |||
| 281 | $this->arguments = (new ArgumentsMapper)->mapToLegacyArray($arguments); |
||
| 282 | |||
| 283 | if ($arguments->hasUnrecognizedOptions()) { |
||
| 284 | foreach ($arguments->unrecognizedOptions() as $name => $value) { |
||
| 285 | if (isset($this->longOptions[$name])) { |
||
| 286 | $handler = $this->longOptions[$name]; |
||
| 287 | } elseif (isset($this->longOptions[$name . '='])) { |
||
| 288 | $handler = $this->longOptions[$name . '=']; |
||
| 289 | } |
||
| 290 | |||
| 291 | if (isset($handler) && \is_callable([$this, $handler])) { |
||
| 292 | $this->{$handler}($value); |
||
| 293 | |||
| 294 | unset($handler); |
||
| 295 | } |
||
| 296 | } |
||
| 297 | } |
||
| 298 | |||
| 299 | $this->handleCustomTestSuite(); |
||
| 300 | |||
| 301 | if (!isset($this->arguments['testSuffixes'])) { |
||
| 302 | $this->arguments['testSuffixes'] = ['Test.php', '.phpt']; |
||
| 303 | } |
||
| 304 | |||
| 305 | if (!isset($this->arguments['test']) && $arguments->hasArgument()) { |
||
| 306 | $this->arguments['test'] = \realpath($arguments->argument()); |
||
| 307 | |||
| 308 | if ($this->arguments['test'] === false) { |
||
| 309 | $this->exitWithErrorMessage( |
||
| 310 | \sprintf( |
||
| 311 | 'Cannot open file "%s".', |
||
| 312 | $arguments->argument() |
||
| 313 | ) |
||
| 314 | ); |
||
| 315 | } |
||
| 316 | } |
||
| 317 | |||
| 318 | if ($this->arguments['loader'] !== null) { |
||
| 319 | $this->arguments['loader'] = $this->handleLoader($this->arguments['loader']); |
||
| 320 | } |
||
| 321 | |||
| 322 | if (isset($this->arguments['configuration']) && \is_dir($this->arguments['configuration'])) { |
||
| 323 | $configurationFile = $this->arguments['configuration'] . '/phpunit.xml'; |
||
| 324 | |||
| 325 | if (\file_exists($configurationFile)) { |
||
| 326 | $this->arguments['configuration'] = \realpath( |
||
| 327 | $configurationFile |
||
| 328 | ); |
||
| 329 | } elseif (\file_exists($configurationFile . '.dist')) { |
||
| 330 | $this->arguments['configuration'] = \realpath( |
||
| 331 | $configurationFile . '.dist' |
||
| 332 | ); |
||
| 333 | } |
||
| 334 | } elseif (!isset($this->arguments['configuration']) && $this->arguments['useDefaultConfiguration']) { |
||
| 335 | if (\file_exists('phpunit.xml')) { |
||
| 336 | $this->arguments['configuration'] = \realpath('phpunit.xml'); |
||
| 337 | } elseif (\file_exists('phpunit.xml.dist')) { |
||
| 338 | $this->arguments['configuration'] = \realpath( |
||
| 339 | 'phpunit.xml.dist' |
||
| 340 | ); |
||
| 341 | } |
||
| 342 | } |
||
| 343 | |||
| 344 | if (isset($this->arguments['configuration'])) { |
||
| 345 | try { |
||
| 346 | $configuration = Registry::getInstance()->get($this->arguments['configuration']); |
||
| 347 | } catch (\Throwable $e) { |
||
| 348 | print $e->getMessage() . \PHP_EOL; |
||
| 349 | |||
| 350 | exit(TestRunner::FAILURE_EXIT); |
||
| 351 | } |
||
| 352 | |||
| 353 | $phpunitConfiguration = $configuration->phpunit(); |
||
| 354 | |||
| 355 | (new PhpHandler)->handle($configuration->php()); |
||
| 356 | |||
| 357 | if (isset($this->arguments['bootstrap'])) { |
||
| 358 | $this->handleBootstrap($this->arguments['bootstrap']); |
||
| 359 | } elseif ($phpunitConfiguration->hasBootstrap()) { |
||
| 360 | $this->handleBootstrap($phpunitConfiguration->bootstrap()); |
||
| 361 | } |
||
| 362 | |||
| 363 | if (!isset($this->arguments['stderr'])) { |
||
| 364 | $this->arguments['stderr'] = $phpunitConfiguration->stderr(); |
||
| 365 | } |
||
| 366 | |||
| 367 | if (!isset($this->arguments['noExtensions']) && $phpunitConfiguration->hasExtensionsDirectory() && \extension_loaded('phar')) { |
||
| 368 | $this->handleExtensions($phpunitConfiguration->extensionsDirectory()); |
||
| 369 | } |
||
| 370 | |||
| 371 | if (!isset($this->arguments['columns'])) { |
||
| 372 | $this->arguments['columns'] = $phpunitConfiguration->columns(); |
||
| 373 | } |
||
| 374 | |||
| 375 | if (!isset($this->arguments['printer']) && $phpunitConfiguration->hasPrinterClass()) { |
||
| 376 | $file = $phpunitConfiguration->hasPrinterFile() ? $phpunitConfiguration->printerFile() : ''; |
||
| 377 | |||
| 378 | $this->arguments['printer'] = $this->handlePrinter( |
||
| 379 | $phpunitConfiguration->printerClass(), |
||
| 380 | $file |
||
| 381 | ); |
||
| 382 | } |
||
| 383 | |||
| 384 | if ($phpunitConfiguration->hasTestSuiteLoaderClass()) { |
||
| 385 | $file = $phpunitConfiguration->hasTestSuiteLoaderFile() ? $phpunitConfiguration->testSuiteLoaderFile() : ''; |
||
| 386 | |||
| 387 | $this->arguments['loader'] = $this->handleLoader( |
||
| 388 | $phpunitConfiguration->testSuiteLoaderClass(), |
||
| 389 | $file |
||
| 390 | ); |
||
| 391 | } |
||
| 392 | |||
| 393 | if (!isset($this->arguments['testsuite']) && $phpunitConfiguration->hasDefaultTestSuite()) { |
||
| 394 | $this->arguments['testsuite'] = $phpunitConfiguration->defaultTestSuite(); |
||
| 395 | } |
||
| 396 | |||
| 397 | if (!isset($this->arguments['test'])) { |
||
| 398 | $this->arguments['test'] = (new TestSuiteMapper)->map( |
||
| 399 | $configuration->testSuite(), |
||
| 400 | $this->arguments['testsuite'] ?? '' |
||
| 401 | ); |
||
| 402 | } |
||
| 403 | } elseif (isset($this->arguments['bootstrap'])) { |
||
| 404 | $this->handleBootstrap($this->arguments['bootstrap']); |
||
| 405 | } |
||
| 406 | |||
| 407 | if (isset($this->arguments['printer']) && \is_string($this->arguments['printer'])) { |
||
| 408 | $this->arguments['printer'] = $this->handlePrinter($this->arguments['printer']); |
||
| 409 | } |
||
| 410 | |||
| 411 | if (!isset($this->arguments['test'])) { |
||
| 412 | $this->showHelp(); |
||
| 413 | |||
| 414 | exit(TestRunner::EXCEPTION_EXIT); |
||
| 415 | } |
||
| 741 |