mihaeu / dephpend

Detect flaws in your architecture, before they drag you down into the depths of dependency hell ...
https://dephpend.com
MIT License
530 stars 26 forks source link

Throw RuntimeException for --help option #18

Closed sergeyklay closed 7 years ago

sergeyklay commented 7 years ago

Inside my container:

php /project/tools/dephpend --help
PHP Fatal error:  Uncaught Symfony\Component\Console\Exception\RuntimeException: Not enough arguments (missing: "source"). in phar:///root/.phive/phars/dephpend-0.3.0.phar/vendor/symfony/console/Input/Input.php:83
Stack trace:
#0 phar:///root/.phive/phars/dephpend-0.3.0.phar/vendor/symfony/console/Input/Input.php(49): Symfony\Component\Console\Input\Input->validate()
#1 phar:///root/.phive/phars/dephpend-0.3.0.phar/vendor/symfony/console/Input/ArgvInput.php(63): Symfony\Component\Console\Input\Input->__construct(Object(Symfony\Component\Console\Input\InputDefinition))
#2 phar:///root/.phive/phars/dephpend-0.3.0.phar/src/Cli/Application.php(144): Symfony\Component\Console\Input\ArgvInput->__construct(Array, Object(Symfony\Component\Console\Input\InputDefinition))
#3 phar:///root/.phive/phars/dephpend-0.3.0.phar/src/Cli/Application.php(41): Mihaeu\PhpDependencies\Cli\Application->createFakeInput()
#4 phar:///root/.phive/phars/dephpend-0.3.0.phar/bin/dephpend(33): Mihaeu\PhpDependencies\Cli\Application->__construct('      _       in phar:///root/.phive/phars/dephpend-0.3.0.phar/vendor/symfony/console/Input/Input.php on line 83

In my opinion it's not quite right to throw the exception here and does not look professional. Maybe replace it by message "Command/Option/Argument not found"?

sergeyklay commented 7 years ago

Well, I can't get any help:

root@58be6f9ed085:/project# php /project/tools/dephpend dsm --help
PHP Fatal error:  Uncaught Symfony\Component\Console\Exception\RuntimeException: The "--help" option does not exist. in phar:///root/.phive/phars/dephpend-0.3.0.phar/vendor/symfony/console/Input/ArgvInput.php:219
Stack trace:
#0 phar:///root/.phive/phars/dephpend-0.3.0.phar/vendor/symfony/console/Input/ArgvInput.php(155): Symfony\Component\Console\Input\ArgvInput->addLongOption('help', NULL)
#1 phar:///root/.phive/phars/dephpend-0.3.0.phar/vendor/symfony/console/Input/ArgvInput.php(84): Symfony\Component\Console\Input\ArgvInput->parseLongOption('--help')
#2 phar:///root/.phive/phars/dephpend-0.3.0.phar/vendor/symfony/console/Input/Input.php(62): Symfony\Component\Console\Input\ArgvInput->parse()
#3 phar:///root/.phive/phars/dephpend-0.3.0.phar/vendor/symfony/console/Input/Input.php(48): Symfony\Component\Console\Input\Input->bind(Object(Symfony\Component\Console\Input\InputDefinition))
#4 phar:///root/.phive/phars/dephpend-0.3.0.phar/vendor/symfony/console/Input/ArgvInput.php(63): Symfony\Component\Console\Input\Input->__const in phar:///root/.phive/phars/dephpend-0.3.0.phar/vendor/symfony/console/Input/ArgvInput.php on line 219

root@58be6f9ed085:/project# php /project/tools/dephpend dsm
PHP Fatal error:  Uncaught Symfony\Component\Console\Exception\RuntimeException: Not enough arguments (missing: "source"). in phar:///root/.phive/phars/dephpend-0.3.0.phar/vendor/symfony/console/Input/Input.php:83
Stack trace:
#0 phar:///root/.phive/phars/dephpend-0.3.0.phar/vendor/symfony/console/Input/Input.php(49): Symfony\Component\Console\Input\Input->validate()
#1 phar:///root/.phive/phars/dephpend-0.3.0.phar/vendor/symfony/console/Input/ArgvInput.php(63): Symfony\Component\Console\Input\Input->__construct(Object(Symfony\Component\Console\Input\InputDefinition))
#2 phar:///root/.phive/phars/dephpend-0.3.0.phar/src/Cli/Application.php(144): Symfony\Component\Console\Input\ArgvInput->__construct(Array, Object(Symfony\Component\Console\Input\InputDefinition))
#3 phar:///root/.phive/phars/dephpend-0.3.0.phar/src/Cli/Application.php(41): Mihaeu\PhpDependencies\Cli\Application->createFakeInput()
#4 phar:///root/.phive/phars/dephpend-0.3.0.phar/bin/dephpend(33): Mihaeu\PhpDependencies\Cli\Application->__construct('      _       in phar:///root/.phive/phars/dephpend-0.3.0.phar/vendor/symfony/console/Input/Input.php on line 83

root@58be6f9ed085:/project# php /project/tools/dephpend --help dsm
PHP Fatal error:  Uncaught Mihaeu\PhpDependencies\Exceptions\FileDoesNotExistException: dsm does not exist. in phar:///root/.phive/phars/dephpend-0.3.0.phar/src/OS/PhpFile.php:53
Stack trace:
#0 phar:///root/.phive/phars/dephpend-0.3.0.phar/src/OS/PhpFile.php(17): Mihaeu\PhpDependencies\OS\PhpFile->ensureFileExists(Object(SplFileInfo))
#1 phar:///root/.phive/phars/dephpend-0.3.0.phar/src/OS/PhpFileFinder.php(13): Mihaeu\PhpDependencies\OS\PhpFile->__construct(Object(SplFileInfo))
#2 phar:///root/.phive/phars/dephpend-0.3.0.phar/src/OS/PhpFileFinder.php(40): Mihaeu\PhpDependencies\OS\PhpFileFinder->find(Object(SplFileInfo))
#3 [internal function]: Mihaeu\PhpDependencies\OS\PhpFileFinder->Mihaeu\PhpDependencies\OS\{closure}(Object(Mihaeu\PhpDependencies\OS\PhpFileSet), 'dsm')
#4 phar:///root/.phive/phars/dephpend-0.3.0.phar/src/OS/PhpFileFinder.php(41): array_reduce(Array, Object(Closure), Object(Mihaeu\PhpDependencies\OS\PhpFileSet))
#5 phar:///root/.phive/phars/dephpend-0.3.0.phar/src/Cli/Application.php(168): Mihaeu\PhpDepend in phar:///root/.phive/phars/dephpend-0.3.0.phar/src/OS/PhpFile.php on line 53
mihaeu commented 7 years ago

Hey @sergeyklay

Thanks so much for your feedback, I really appreciate it.

I fixed this bug in 04ea8db15d92924a2a93cca5196e4837bc83cc73 and it is available in v0.3.1 (.phar download).

I do handle exceptions differently (but still not properly) and you are right it is unprofessional to show them to the user in this way. This was actually due to a very ugly workaround which I had to use in order to properly use dependency injection with Symfony commands (not their weird interpretation of method injection). I'll keep working on it.

Thanks again for the feedback, if you find anything else please let me know!

sergeyklay commented 7 years ago

Thanks for so fast fix