Code quality control: Lint, CS, Exakat

About me

  • Eugene Zenko
  • Tech Lead (PHP) @ Colours (Den Bosch, Rotterdam)
  • Drupal 5-8
  • Football, books, music, rock!
  • Socials: @zeuty
  • Linkedin: yzenko

Assumptions

  1. Quality is not a variable

2. Anything that can go wrong will go wrong (Murphy's law)

3. A man is (a little bit) lazy

3. A man is (a little bit) non-conformist

Code problems

  1. Syntax errors

2. Not following code standards, best practices, different approach to code formatting in the same team

3. Structural problems: not secure, not performing, not maintainable code

Harm

  1. Psychological

2. Reputational

3. Time

What to do?

Processes

Instruments

PHP Lint

Built-in native functionality

php -l {filename}

Example:
php -l sites/all/modules/custom/with_error.php 
PHP Parse error:  syntax error, unexpected '?>' 
in sites/all/modules/custom/with_error.php on line 4
Errors parsing sites/all/modules/custom/with_error.php

PHP Code Sniffer

Automatic code analysis on violation of the coding standards

  • Out of the box - PSR1, PEAR, PSR2, MySource, Squiz, PHPCS, Zend
  • Available - Drupal и DrupalPractice
  • Integrates with PHPStorm
  • Possible to define own standards

PHP Code Beautifier and Fixer

  • Automatically generates diff between source file and coding standard
  • Automatically applies it to the source file

Exakat

  • Static analysis PHP5.2-7.2
  • Code compatibility with PHP version
  • Security
  • Performance
  • Complexity and maintainability
  • Automatic documentation
  • >700 rules, grouped into Recipes: Security, Performances, Dead code, etc.

PHP Mess Detector

  • Simple tool, no dependencies, just phar
  • 6 rulesets: clean code, code size, naming, unused code, etc.
  • Simple configuration - xml file with a list of rules to be used
  • Fast

Yes, but...

How many people will run this beautiful tools during daily routine?

Idea

  • Let's do more code reviews!
  • Let's punish harder the people sabotaging the agreements!
  • Let's simply be individually more responsible!

And maybe let's try to automate this somehow?

Integration with git

  • Using git hooks
  • In our particular case - pre-commit (or pre-receive)

Example

Roadmap?

  • Composer package with git hook configuration wizard and necessary dependencies

Questions, ideas, suggestions?

Made with Slides.com