Running Snoopy with the -h or --help command line argument will print a full list of commands that Snoopy will respond to. The output of snoopy --help is shown below.
Usage: /usr/bin/snoopy [-g] [-s] [-t] [-h] [-q] <file>|<dir> [--tests=<tests>] <file> : a specific file to check <dir> : a directory to traverse and find files to check <tests> : a comma separated list of test names -q : run quiet and only produce report output -g : generate a PDF of the coding standards -s : only print the summary error report -t : self test the code sniffs (no <file> or <dir> required) -h --help : print this help message
Running Snoopy without any command line arguments will also print the usage information displayed above.
$ snoopy
The simplest way of using Snoopy is to provide the location of a file or folder for Snoopy to check. If a folder is provided, Snoopy will check all files it finds in that folder and all its sub-folders.
In the example below, the first command tells Snoopy to check the asset.inc file for coding standard errors while the second command tells Snoopy to check all PHP files in the core/include directory of MySource Matrix.
$ snoopy /path/to/matrix/core/include/asset.inc $ snoopy /path/to/matrix/core/include
By default, Snoopy will check PHP files for all coding standards that it knows about. Sometimes, you just want to check for a specific coding standard.
You can specify the coding standards to check by using the --tests command line argument. The test names are separated by commas on the command line.
The example below checks the asset.inc file for violations of the Array Declaration and Inline IF coding standards. No other coding standards checks will be performed on the file.
$ cd /path/to/matrix $ snoopy core/include/asset.inc --tests=array_declaration,inline_if
By default, Snoopy will print its progress as it tests files.
$ snoopy /path/to/matrix/core/include Getting sniff list... DONE Registering token handlers... DONE Sniffing assertions.inc [2375 tokens in 535 lines]... DONE IN 1 second(s) Sniffing asset.inc [26462 tokens in 4467 lines]... DONE IN 12 second(s) Sniffing asset_attribute.inc [1420 tokens in 382 lines]... DONE IN 1 second(s) Sniffing asset_cache.inc [1624 tokens in 378 lines]... DONE IN < 1 second(s) Sniffing asset_edit_interface.inc [16424 tokens in 2238 lines]...
This output is handy if you are running Snoopy over a large number of files that may take a long time. However, you can suppress this output using the -q command line argument. Using this argument will ensure Snoopy will only output errors that it finds. If no errors are found, Snoopy will not output anything.
$ snoopy -q /path/to/matrix/core/include
By default, Snoopy will print a complete list of all errors it find in each PHP file after the error report summary. This list can become quite long, especially when checking a large number of files at once. To suppress the complete list of errors and only print the error report summary, use the -s command line argument.
$ cd /path/to/matrix/core/include $ snoopy -s asset_status Getting sniff list... DONE Registering token handlers... DONE Sniffing asset_status.inc [508 tokens in 140 lines]... DONE IN 1 second(s) ... SNOOPY ERROR REPORT SUMMARY -------------------------------------------------------------------------- FILE ERRORS -------------------------------------------------------------------------- asset_status/asset_status.inc 7 asset_status/asset_status_approved.inc 11 asset_status/asset_status_archived.inc 5 asset_status/asset_status_editing.inc 20 asset_status/asset_status_editing_approval.inc 1 asset_status/asset_status_editing_approved.inc 6 asset_status/asset_status_live.inc 18 asset_status/asset_status_live_approval.inc 31 asset_status/asset_status_pending_approval.inc 21 asset_status/asset_status_under_construction.inc 18 -------------------------------------------------------------------------- A TOTAL OF 138 ERROR(S) WERE FOUND IN 10 FILE(S) --------------------------------------------------------------------------
The quiet and summary only options are a good combination if running Snoopy as a cron job. With these two options, Snoopy will only produce output if it finds errors and, if it does find any, will only produce a small summary report. This format is ideal for emailing.
$ snoopy -q -s /path/to/matrix/core/include
Besides testing PHP files for coding standard errors, Snoopy can also generate a PDF of the coding standard it is testing against. See the Snoopy features page for more information about the Snoopy coding standards PDF.
The following command will generate a file named coding_standards.pdf in the /path/to/snoopy directory.
$ snoopy -g
Self-testing is a process whereby Snoopy verifies that each of its coding standards are functioning correctly. See the Snoopy features page for more information about self-testing, or see the Snoopy testing tutorial for information about how self-testing can help you write better Snoopy coding standard tests.
The following command will generate a list of errors that Snoopy found in the self-test files.
$ snoopy -t inline_if: an expected error was not found on line 5 [1 error(s) expected] inline_if: an expected error was not found on line 7 [1 error(s) expected] php_keywords: an expected error was not found on line 17 [1 error(s) expected] php_keywords: an expected error was not found on line 19 [1 error(s) expected]
The self-test function is most often used by developers when writing new Snoopy coding standard tests. You will not need to use the -t option if you are just testing PHP files for coding standard violations.