---
title: "Clear php code : between coding convention and conception"
url: https://www.exakat.io/clear-php-code-between-coding-convention-and-conception/
date: 2015-01-19
modified: 2015-01-19
author: "dams"
description: "[caption id=\"attachment_483\" align=\"alignleft\" width=\"313\"] A reference of clear PHP code rules[/caption] One question that keeps coming back while collecting the rules for clearPHP is the domain of the rule. Coding..."
categories:
  - "Company"
word_count: 398
---

# Clear php code : between coding convention and conception

[![A reference of clear PHP code rules](http://178.62.231.40/wp-content/uploads/2015/01/books.320.jpg)](http://178.62.231.40/wp-content/uploads/2015/01/books.320.jpg)A reference of clear PHP code rules

One question that keeps coming back while collecting the rules for clearPHP is the domain of the rule. Coding convention and conception rules covered different domains and seldom overlay each other. ClearPHP rules aim a being close to the language and its tricks, away from semantics and architecture. How come ?

## Coding conventions

Coding conventions are the rules of writing. They encompass the [number of spaces around operators](http://symfony.com/doc/current/contributing/code/standards.html), [the level of indentation](https://make.wordpress.org/core/handbook/coding-standards/php/) and [the meaning ](http://nette.org/en/coding-standard)[of names](http://nette.org/en/coding-standard). They are usually supported by PHP code sniffer which reports coding violations or PHP CS Fixer, which tries hard to fix them. This will avoid crossbreeding [camels and snakes](https://twitter.com/DragonBe/status/555396473341607936). Projects of all stripes and colours should have one and follow them.

## Conception

Conception, on the other hand, tries to wrestle with the problem from a higher point of view. This is the place for design patterns, dependency injections or Unit testing. You'll find them collected at [PHP the right way](https://twitter.com/DragonBe/status/555396473341607936). Automated feedback comes in metrics, with [phpmetrics](http://www.phpmetrics.org/) or [phpmd](http://phpmd.org/), which gives global and local values of quality and urges you to reduce [cyclomatic complexity](http://phpmd.org/rules/codesize.html) or [Halstead metrics](http://en.wikipedia.org/wiki/Halstead_complexity_measures).

## Clear PHP code

In between, there are a range of recommendations that are none of the above. For example, where would the famous [strpos() comparison rule](http://php.net/strpos) be? Strpos must be compared with === to avoid missing the case where the found value is at the index 0, mistaken with the unfound result false. And [foreach() loops that needs to unset their reference](http://php.net/manual/en/control-structures.foreach.php) to avoid reuse (and misuse) ? Both can't be can't be coding standard, nor conception.

The solution is to avoid them, of course, to build experience. This basically means that once after having experienced them, some immunity will be build. Sadly, some tricks are of the die-hard kind. So, the better solution is to include code reviews to hunt for those smaller rules and eradicates.

Since those tricks are numerous, [clearPHP](https://github.com/dseguy/clearPHP) has set the goal to collect them in one reference. Currently, there are 88 rules, with documentation, title and id. That makes half the job to build your own reference : simply select the one (or several) you need, and base your next code review with it. May be you'll have experienced some even rarer situation of PHP, and will care to share it with the rest of the community. See you there !