PHPackages                             bit3/php-coding-standard - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. bit3/php-coding-standard

Abandoned → [contao-community-alliance/coding-standard](/?search=contao-community-alliance%2Fcoding-standard)ArchivedCoding-standard[Utility &amp; Helpers](/categories/utility)

bit3/php-coding-standard
========================

bit3 PHP coding standards

2.4(12y ago)31.8k20BSD-3-ClausePHP

Since Jul 21Pushed 12y ago1 watchersCompare

[ Source](https://github.com/bit3archive/php-coding-standard)[ Packagist](https://packagist.org/packages/bit3/php-coding-standard)[ Docs](http://bit3.de)[ RSS](/packages/bit3-php-coding-standard/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (2)Versions (7)Used By (20)

bit3 coding standards
=====================

[](#bit3-coding-standards)

These are our coding standards.

This coding standard based on the great TYPO3 coding standard, see [http://forge.typo3.org/projects/team-php\_codesniffer/wiki/Using\_the\_TYPO3\_Coding\_Standard](http://forge.typo3.org/projects/team-php_codesniffer/wiki/Using_the_TYPO3_Coding_Standard)

Philosophy
----------

[](#philosophy)

Our philosophy: Write fast readable and comprehensible code. Don't be shy to write more lines, if it makes each line more atomic.

**What is the benefit of atomic lines?**When each line is full atomic (only contains one operation), the order of lines reflect the execution order of the commands.

When you have a complex line like this:

```
$variable = ($foo != $bar && count($zap) || $dig) ? $this->func($zap, $foo, $bar) : $this->other(count($zap))->chain($foo, $bar);
```

How is the order of execution? What do this code? You can understand if you analyse the line, but its hard to do. Simplified this is the execution order of the operations:

```
evaluate $foo != $bar
execute count($zap)
evaluate count($zap)
evaluate .. && ..
evaluate $zip
evaluate .. || ..
if true
  execute $this->func($zap, $foo, $bar)
else
  execute count($zap)
  evaluate count($zap)
  execute $this->other(count($zap))
  execute $..->chain($foo, $bar)
assign $variable

```

If you want to understand what this code do, you have to understand the execution order of the operations and the meaning of each operation. If you write this in a more atomic style, you make it easier to understand, for others and yourself if you nod touch the code a long time!

Compare against this, it is exactly the same code:

```
if (
	$foo != $bar && count($zap) ||
	$dig
) {
	$variable = $this->func($zap, $foo, $bar);
}
else {
	$variable = $this->other(count($zap))->chain($foo, $bar);
}
```

As you can see, this snippet more reflect the execution order and it is much easier to understand what it do.

Usage
=====

[](#usage)

Install the coding standards via composer:

```
"require-dev":{
	"bit3/php-coding-standard":"@dev"
}
```

After updating dependencies, copy the example ant build file from vendor/bit3/php-coding-standard/example/build.xml into your project. If your sources are not in `src/`, change the path to your sources in the build file.

Hint: If you not use phpunit, remove the phpunit target from build file.

You can run the tests by invoke `ant phpmd` and `ant phpcs`. Running `ant` or `ant test` will run all test targets.

Hint: To run all testes, even if one fail, use `ant -keep-going`.

Definitions
===========

[](#definitions)

- *long line* means a line that is longer than **60** characters.
- No line should be longer than **100** characters.
- No line must be longer than **120** characters.

Files
=====

[](#files)

No file must contain more than one class, interface or function. The file name must the same (including case) as the class, interface or function named defined in it. Without any prefix (e.g. `class.`) or suffix (e.g. `.inc`), expect the the file type extension `.php`.

Runner scripts, should contain a runner class, containing a `run` method.

Example `index.php`:

```
