MySource Matrix Developer

Main Content

Frequently Asked Questions about Snoopy

Can I use Snoopy in my applications?

Yes. Snoopy is released under the BSD licence. You are free to use, modify and redistribute Snoopy as you see fit.

My code is fine! Why do I need Snoopy?

Maybe you don't, but if you want to ensure you adhere to a set of coding standards, Snoopy is a quick and easy way to do that. Snoopy is a replacement for the more manual task of checking coding standards in code reviews. With Snoopy, you can reserve code reviews for the checking of code correctness.

Coding standards are a good thing. They will make your code easier to read and maintain, especially when multiple developers are working on the same application.

Consider using coding standards if you don't already.

Does Snoopy perform any code coverage or unit testing?

No. Snoopy is not a tool for testing that your PHP application works correctly. All Snoopy will do is ensure your PHP code meets the standards that you are following.

Does Snoopy parse my code to ensure it will execute?

No. Snoopy does not actually parse your code, and so cannot tell if your code contains parse errors. Snoopy may return an incorrect number of errors if checking code that does contain parse errors.

You can easily check for parse errors in a file using the PHP command line interface and the -l (lowercase L) option.

$ php -l /path/to/matrix/core/include/asset.inc
No syntax errors detected in /path/to/matrix/core/include/asset.inc

I'm working on many projects with multiple developers. Can we all use the same installation of Snoopy, even between projects?

Yes. You can create a common Snoopy install, adding this install into your $PATH environmental variable. You can then be able to invoke Snoopy over a directory or file using the command snoopy /path/to/code.

I don't agree with your coding standards! Can I make Snoopy enforce my own?

Yes. At its core, Snoopy is just a framework for enforcing coding standards. We release Snoopy with the coding standards that we enforce to help developers get started on projects where they do not have a standard.

You are free to use as much or as little of our coding standard as you like, or to write new tests to enforce your own standard. See the Snoopy testing tutorial for more information on writing Snoopy tests.

Can I use Snoopy on Microsoft Windows?

Yes. Snoopy will run correctly on Windows using PHP4.

Why doesn't Snoopy just make the changes it suggests for me?

As much as we trust Snoopy to check your code for coding standard errors, we don't trust any application to ever change code for us without reviewing it first. Considering we would have to check each change Snoopy made before releasing the source code, why not make the changes manually?

Making the changes manually ensures a couple of positive things happen:

  • Developers learn the coding standards and make less mistakes in the future
  • Developers can ensure that Snoopy is working correctly
  • Developers can decide if a coding standard doesn't fit a particular piece of code

So if you find yourself wishing Snoopy would just go ahead and make those changes for you, maybe you just need to read the coding standards and adhere to them a bit better.

No matter how small of a change you make, always test your code before committing it to your code repository or releasing it. Even changes suggested by Snoopy need to be tested, as small and insignificant as they may seem.

How come Snoopy reported errors, I fixed them, now I get even more?

Sometimes, errors mask the existence of other errors, or new errors are created as you fix others.

For example, Snoopy might tell you that an in-line IF statement needs to be defined with braces. Once you make this change, Snoopy may report that the braces you added are not correctly aligned.

Always run Snoopy until you get a passing result. Once you've made the changes Snoopy recommends, run Snoopy again to ensure no new errors have been added.

Why doesn't Snoopy offer positive reinforcement when no errors are found?

Snoopy used to output the phrase Perfect! when no errors were found, offering some satisfaction to developers. This "feature" was later removed so that Snoopy could run more effectively as a cron job.

For most cron systems, outputting any content to screen will result in an email being sent containing that output. Generally, you don't want to receive an email unless something has gone wrong. So Snoopy now only prints output to screen when it encounters errors.

Consider no news to be good news.