PHPCSStandards / PHP_CodeSniffer

PHP_CodeSniffer tokenizes PHP files and detects violations of a defined set of coding standards.
BSD 3-Clause "New" or "Revised" License
976 stars 58 forks source link

PHP fatal error when user passes an invalid generator #709

Open rodrigoprimo opened 8 hours ago

rodrigoprimo commented 8 hours ago

Describe the bug

PHPCS throws a fatal error when the user passes an invalid generator.

To reproduce

Steps to reproduce the behavior:

  1. Run phpcs test.php --generator=InvalidGenerator --standard=Generic
  2. See the error message displayed
    $ phpcs test.php --generator=InvalidGenerator --standard=Generic          
    PHP Fatal error:  Uncaught Error: Class "PHP_CodeSniffer\Generators\InvalidGenerator" not found in src/Runner.php:98
    Stack trace:
    #0 bin/phpcs(14): PHP_CodeSniffer\Runner->runPHPCS()
    #1 {main}
    thrown in src/Runner.php on line 98

Expected behavior

PHPCS should display a friendly error message informing the user that the generator does not exist and potentially listing the available generators.

Please confirm

jrfnl commented 8 hours ago

Marking this as an enhancement instead of a bug, as the error is with the user, not with PHPCS, but PHPCS can handle the error in a more user-friendly manner, hence: enhancement.