Phint is a static code analysis tool for PHP. Very much a work in progress. Currently checks for:
- Undefined variables
- Properties/methods being called exist
- Classes being used in your code exist (instantiation, type-hinting,
- Exception being caught actually exist and are exceptions (
catch (stdClass $e)will error, for example)
- Functions being called actually exist
- Methods and functions are called with the correct number of arguments
More features to come. Check the Github issues.
On a per-project basis:
composer require --dev anlutro/phint:dev-master@dev ./vendor/bin/phint /path/to/src
wget https://files.lutro.me/phint.phar chmod +x phint.phar sudo mv phint.phar /usr/local/bin phint /path/to/src
Note that you must be in your project's root for Phint to run. You also need a composer autoloader to be present in
Example output from a simple command run:
You can pass
-s as an arugment to get more errors. The errors marked as strict are more prone to be wrong, but should be more accurate as time goes on.
You can also pass
-d to get some debug information. Currently this isn't much, unless you hit a fatal error, in which case you might get some more info.
By default, if you pass a directory or multiple file paths to the command, Phint will analyze all of them and spit out the errors as it goes along. If you pass
-e, Phint will exit as soon as it finds a file with errors.
This tool makes some very heavy assumptions about how you're using it and your application.
Your project must have some sort of autoloader register script present in
vendor/autoload.php. This autoloader must make every class and function in your project available.
The checker works best if all the files being checked are classes with methods, nothing more.
See the CONTRIBUTING.md file for information on contributing.