PHPackages                             forrest79/phpcs - 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. [Validation &amp; Sanitization](/categories/validation)
4. /
5. forrest79/phpcs

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

forrest79/phpcs
===============

Forrest79 - PHP Coding Standard - PHP Code Sniffer rules

v2.3(8mo ago)014.9k↓50%16(BSD-3-Clause and MIT)PHPPHP ^8.3CI passing

Since Jun 12Pushed 8mo ago1 watchersCompare

[ Source](https://github.com/forrest79/phpcs)[ Packagist](https://packagist.org/packages/forrest79/phpcs)[ RSS](/packages/forrest79-phpcs/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (6)Versions (24)Used By (16)

Forrest79 Coding Standard for PHP
=================================

[](#forrest79-coding-standard-for-php)

[![Latest Stable Version](https://camo.githubusercontent.com/300595dd7c945b887a47bb0ad8bf9d1c97c8beb5802ba5e872b8a82958c7cf59/68747470733a2f2f706f7365722e707567782e6f72672f666f727265737437392f70687063732f76)](//packagist.org/packages/forrest79/phpcs)[![Monthly Downloads](https://camo.githubusercontent.com/d8f123f37b2a909ab3f565d387289027c49b7fb59276b155a9487b30aaad6a8e/68747470733a2f2f706f7365722e707567782e6f72672f666f727265737437392f70687063732f642f6d6f6e74686c79)](//packagist.org/packages/forrest79/phpcs)[![License](https://camo.githubusercontent.com/25cd51762158c6fa7043c1d1df5cfce97ad38fa861838596a70091c28c00c07c/68747470733a2f2f706f7365722e707567782e6f72672f666f727265737437392f70687063732f6c6963656e7365)](//packagist.org/packages/forrest79/phpcs)[![Build](https://github.com/forrest79/phpcs/actions/workflows/build.yml/badge.svg?branch=master)](https://github.com/forrest79/phpcs/actions/workflows/build.yml)

> Based on (no more developed)  and work of . Thanks!

Installation
------------

[](#installation)

The recommended way to install Forrest79 PHP Coding Standard is through Composer:

```
composer require --dev forrest79/phpcs
```

Forrest79 PHP Coding Standard requires PHP 8.0.

How to use it:
--------------

[](#how-to-use-it)

- Create your CS XML and include this Forrest79CodingStandard:

```

```

- Or you can use version with fully qualified global functions (`\` prefix before global functions i.e. `\is_array($x)`) and constants (`\` prefix before global constants i.e. `\FILE_APPEND`):

```

```

- You can use it and ignore some rules.

```

```

- Or just concrete files.

```

    tests/Sniffs/TestCase.php

```

PSR-4 settings
--------------

[](#psr-4-settings)

- Recommend is to proper set PSR-4 via these settings:

```

```

- key is directory, value is namespace

Custom sniffs
-------------

[](#custom-sniffs)

### Exceptions\\ExceptionDeclarationSniff

[](#exceptionsexceptiondeclarationsniff)

#### Forrest79CodingStandard.Exceptions.ExceptionDeclarationSniff.NotEndingWithException

[](#forrest79codingstandardexceptionsexceptiondeclarationsniffnotendingwithexception)

Or exceptions should have `Exception` suffix.

#### Forrest79CodingStandard.Exceptions.ExceptionDeclarationSniff.NotChainable

[](#forrest79codingstandardexceptionsexceptiondeclarationsniffnotchainable)

Exceptions should be chainable, last constructor argument must be `\Throwable`.

#### Forrest79CodingStandard.Exceptions.ExceptionDeclarationSniff.IncorrectExceptionDirectory

[](#forrest79codingstandardexceptionsexceptiondeclarationsniffincorrectexceptiondirectory)

All exceptions should be in `Exceptions` subdirectory. You can change subdirectory name via settings:

```

```

### Methods\\MethodStructureSniff

[](#methodsmethodstructuresniff)

#### Forrest79CodingStandard.Methods.MethodStructureSniff.AlphabeticalOrder

[](#forrest79codingstandardmethodsmethodstructuresniffalphabeticalorder)

Check if class has public methods in alphabetical order. Set files via settings:

```

```

### NamingConventions\\MethodStructureSniff

[](#namingconventionsmethodstructuresniff)

#### Forrest79CodingStandard.NamingConventions.ValidVariableNameSniff.NotCamelCaps

[](#forrest79codingstandardnamingconventionsvalidvariablenamesniffnotcamelcaps)

Check camel caps variable names.

### Nette\\FinalInjectMethodSniff

[](#nettefinalinjectmethodsniff)

#### Forrest79CodingStandard.Nette.FinalInjectMethodSniff.MissingFinal

[](#forrest79codingstandardnettefinalinjectmethodsniffmissingfinal)

For Nette Framework. If some presenter or other object uses inject functionality, class should be `final` or `inject` methods should be `final`.

### Nette\\ParentCallSniff

[](#netteparentcallsniff)

#### Forrest79CodingStandard.Nette.ParentCallSniff.MissingParent

[](#forrest79codingstandardnetteparentcallsniffmissingparent)

For Nette Framework. In presenters, all `beforeRender` methods should call their parent.

### Nette\\PresenterMethodsSniff

[](#nettepresentermethodssniff)

#### Forrest79CodingStandard.Nette.PresenterMethodsSniff.NotProtected

[](#forrest79codingstandardnettepresentermethodssniffnotprotected)

For Nette Framework. In presenters, all `startup`, `beforeRender` and `createComponent` methods should be `protected`.

General naming conventions
--------------------------

[](#general-naming-conventions)

- Avoid abbreviations, use them only if long name would be less readable.
- For 2-letter shortcuts use `UPPERCASE`, for longer `PascalCase`.

```
`.
- There are no characters (including BOM) before the PHP opening tag.
- Long opening tags are used (always `
