Code Style at Compufácil

Jean Carlo Machado
BlogTech
Published in
1 min readAug 16, 2016

--

In Compufácil repository we have a set of style guides that must be followed by the developer for the code to be accepted on the repository. This rules help us to avoid common mistakes and make our code reviews quicker. We enforce this rules through phpmd and phpcs plus some shell scripting.

To do what the video showed we simply called a script (cpf-code-checker) on each changed PHP file in the current commit.

The important part here is the command responsible for style checking cpf-code-check, and when it returns failure the hole command fails.

Code Checker

The following is the definition of the checker:

We can ignore files with the styleignore file. This is useful for some new syntax that appears in PHP like anonymous classes, that are detected as errors by the checkers so are disabled meanwhile.

And the last part is our custom configurations of phpmd and phpcs.

ruleset.xml (phpcs)

phpmd.xml

Those configurations are very specific for our case but it’s works well as an skeleton for other projects.

That’s it, if your find this checker useful let us know.

Originally published at jeancarlomachado.com.br.

--

--

I care about science and humanism. Programmer, teacher, philanthropist, violinist.