PHPackages                             fig-r/psr2r-sniffer - 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. fig-r/psr2r-sniffer

ActivePhpcodesniffer-standard

fig-r/psr2r-sniffer
===================

Code-Sniffer, Auto-Fixer and Tokenizer for PSR2-R

2.7.1(3mo ago)321.2M↑14%820MITPHPPHP &gt;=8.1CI passing

Since Feb 15Pushed 2mo ago3 watchersCompare

[ Source](https://github.com/php-fig-rectified/psr2r-sniffer)[ Packagist](https://packagist.org/packages/fig-r/psr2r-sniffer)[ RSS](/packages/fig-r-psr2r-sniffer/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (5)Versions (46)Used By (20)

PSR-2-R Sniffer
===============

[](#psr-2-r-sniffer)

[![CI](https://github.com/php-fig-rectified/psr2r-sniffer/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/php-fig-rectified/psr2r-sniffer/actions/workflows/ci.yml)[![Latest Stable Version](https://camo.githubusercontent.com/9ec9268dd0d74a30593bdf901db903b453ad1c3150449a6f8cff17efeb21aea2/68747470733a2f2f706f7365722e707567782e6f72672f6669672d722f70737232722d736e69666665722f762f737461626c652e737667)](https://packagist.org/packages/fig-r/psr2r-sniffer)[![Minimum PHP Version](https://camo.githubusercontent.com/183804d09fec16ca7b6209b007250b7d8db1b915042feb093a9f20e6e1f25359/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344253230382e312d3838393242462e737667)](https://php.net/)[![License](https://camo.githubusercontent.com/ade96170421629e8ce3d4ceb0072ccb6fb7da5836041ea686f289ceab051e702/68747470733a2f2f706f7365722e707567782e6f72672f6669672d722f70737232722d736e69666665722f6c6963656e73652e737667)](https://packagist.org/packages/fig-r/psr2r-sniffer)[![Total Downloads](https://camo.githubusercontent.com/f38dbdd9180736baaad1214000719e5d0338b0bba9aeb33daca4bbcb65b27df9/68747470733a2f2f706f7365722e707567782e6f72672f6669672d722f70737232722d736e69666665722f642f746f74616c2e737667)](https://packagist.org/packages/fig-r/psr2r-sniffer)[![Coding Standards](https://camo.githubusercontent.com/dbabe22710e675cb88cd0b12196f1477e2376dea497332775692cf1359a75918/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f63732d5053522d2d322d2d522d79656c6c6f772e737667)](https://github.com/php-fig-rectified/fig-rectified-standards)

For details on PSR-2-R see [fig-rectified-standards](https://github.com/php-fig-rectified/fig-rectified-standards).

For PHP version compatibility see [version map](https://github.com/php-fig-rectified/psr2r-sniffer/wiki).

Documentation @ [/docs/](docs).

This branch is for use with **PHP 8.1+** repos.

Included sniffs
---------------

[](#included-sniffs)

The following sniffers are bundles together as `PSR2R` already, but you can also use them standalone/separately in any way you like.

**Currently, PSR2R ships with over 190 sniffs.**

- [List of included sniffs](docs/sniffs.md)

Furthermore, the following ones are recommended to add:

- PhpCollective.Commenting.DocBlockThrows
- PhpCollective.Commenting.DocBlockTagGrouping
- SlevomatCodingStandard.Functions.DisallowEmptyFunction
- SlevomatCodingStandard.PHP.UselessParentheses

This library uses [squizlabs/PHP\_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer/). It can detect all issues and fix some of them automatically and is ideal for CI integration (travis, jenkins, circleci, GA etc).

### Usage

[](#usage)

#### How to use for your project

[](#how-to-use-for-your-project)

Most likely you are using composer. As such, put it into the require-dev dependencies:

```
composer require --dev fig-r/psr2r-sniffer

```

Set up a `phpcs.xml` in the root of your library. Define here the standard to use as well as the project paths, usually

```

src/
tests/
```

You can then use it like this:

```
// Sniffs only
vendor/bin/phpcs {path/file}

// Sniffs and fixes
vendor/bin/phpcbf {path/file}

```

The path is optional if you want to run it on a specific subset of your defined paths. Otherwise, it defaults to the paths defined in your XML file.

### Customizing

[](#customizing)

You can always customize your `phpcs.xml` further, e.g.:

```

	src/
	tests/

	/config/Migrations/

		0

		0

```

#### Useful commands

[](#useful-commands)

Verbose output with `-v` is always useful. With `-vv` or even `-vvv` you get even more debug output.

If you want a list of all sniffs in this standard, use `-e`:

```
vendor/bin/phpcs -e

```

It will list them all grouped by their standard name and sniff type.

To just run a single sniff, use `--sniffs=...` and a comma separated list of sniffs, e.g.:

```
vendor/bin/phpcs --sniffs=PSR2R.Files.EndFileNewline

```

Usually, if you run it over your complete repository, you would want to exclude dirs like `tests/test_files/`:

```
vendor/bin/phpcs --ignore=/tests/test_files/

```

#### Windows usage

[](#windows-usage)

For Win OS you should be using `\` as separator:

```
vendor\bin\phpcs

```

#### Include it in your IDE via hotkey

[](#include-it-in-your-ide-via-hotkey)

E.g. for PHPStorm:

- Open Settings -&gt; Tools -&gt; External Tools
- Add a new tool named "cs-sniffer" and set Program to `$ProjectFileDir$/vendor/bin/phpcs`, Parameters to `--standard=$ProjectFileDir$/vendor/fig-r/psr2r-sniffer/PSR2R/ruleset.xml -p $FilePath$` and Working directoy to `$ProjectFileDir$`.
- Add a new tool named "cs-fixer" and set Program to `$ProjectFileDir$/vendor/bin/phpcbf`, Parameters to `--standard=$ProjectFileDir$/vendor/fig-r/psr2r-sniffer/PSR2R/ruleset.xml -v $FilePath$` and Working directoy to `$ProjectFileDir$`.
- Optionally uncheck "Open console" if you don't want to see any output here for the fixer.
- Now set up your hotkeys under Settings -&gt; Keymap (search for cs-sniffer and cs-fixer). E.g. `Control + Comma` for sniffing, and `Control + Dot` for fixing.

##### Hook it into your IDE for live-correction

[](#hook-it-into-your-ide-for-live-correction)

You can also easily make a "watcher" for your IDE, so any file you work on, will be auto-corrected when (auto-)saving. But here you should better only whitelist certain sniffs that only add things and don't remove anything.

Note: For PHPStorm, for example, make sure you switch `Show Console` to `never` to not be disturbed by it all the time.

### Writing new sniffs

[](#writing-new-sniffs)

You can contribute by adding new sniffs as per PSR-2-R standard.

#### Tokenizing Tool

[](#tokenizing-tool)

It really helps to see what the code looks like for the sniffer. So we can parse a PHP file into its tokens using the following tool:

```
bin/tokenize /path/to/file

```

(If you run this from your application, it will have to be run as `vendor/bin/tokenize`)

With more verbose output:

```
bin/tokenize /path/to/file -v

```

For a file `MyClass.php` it will create a token file `MyClass.tokens.php` in the same folder.

Example output of a single line of PHP code:

```
...
    protected static function _optionsToString($options) {
// T_WHITESPACE T_PROTECTED T_WHITESPACE T_STATIC T_WHITESPACE T_FUNCTION T_WHITESPACE T_STRING T_OPEN_PARENTHESIS T_VARIABLE T_CLOSE_PARENTHESIS T_WHITESPACE T_OPEN_CURLY_BRACKET T_WHITESPACE
...
```

Using the verbose option:

```
...
    protected static function _optionsToString($options) {
// T_WHITESPACE (935) code=379, line=105, column=1, length=1, level=1, conditions={"9":358}, content=`\t`
// T_PROTECTED (936) code=348, line=105, column=2, length=9, level=1, conditions={"9":358}, content=`protected`
// T_WHITESPACE (937) code=379, line=105, column=11, length=1, level=1, conditions={"9":358}, content=` `
// T_STATIC (938) code=352, line=105, column=12, length=6, level=1, conditions={"9":358}, content=`static`
// T_WHITESPACE (939) code=379, line=105, column=18, length=1, level=1, conditions={"9":358}, content=` `
// T_FUNCTION (940) code=337, line=105, column=19, length=8, parenthesis_opener=943, parenthesis_closer=945, parenthesis_owner=940, scope_condition=940, scope_opener=947, scope_closer=1079, level=1, conditions={"9":358}, content=`function`
// T_WHITESPACE (941) code=379, line=105, column=27, length=1, level=1, conditions={"9":358}, content=` `
// T_STRING (942) code=310, line=105, column=28, length=16, level=1, conditions={"9":358}, content=`_optionsToString`
// T_OPEN_PARENTHESIS (943) code=PHPCS_T_OPEN_PARENTHESIS, line=105, column=44, length=1, parenthesis_opener=943, parenthesis_owner=940, parenthesis_closer=945, level=1, conditions={"9":358}, content=`(`
// T_VARIABLE (944) code=312, line=105, column=45, length=8, nested_parenthesis={"943":945}, level=1, conditions={"9":358}, content=`$options`
// T_CLOSE_PARENTHESIS (945) code=PHPCS_T_CLOSE_PARENTHESIS, line=105, column=53, length=1, parenthesis_owner=940, parenthesis_opener=943, parenthesis_closer=945, level=1, conditions={"9":358}, content=`)`
// T_WHITESPACE (946) code=379, line=105, column=54, length=1, level=1, conditions={"9":358}, content=` `
// T_OPEN_CURLY_BRACKET (947) code=PHPCS_T_OPEN_CURLY_BRACKET, line=105, column=55, length=1, bracket_opener=947, bracket_closer=1079, scope_condition=940, scope_opener=947, scope_closer=1079, level=1, conditions={"9":358}, content=`{`
// T_WHITESPACE (948) code=379, line=105, column=56, length=0, level=2, conditions={"9":358,"940":337}, content=`\n`
...
```

###  Health Score

66

—

FairBetter than 99% of packages

Maintenance83

Actively maintained with recent releases

Popularity50

Moderate usage in the ecosystem

Community33

Small or concentrated contributor base

Maturity85

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 83.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~86 days

Recently: every ~23 days

Total

43

Last Release

115d ago

Major Versions

0.6.4 → 1.0.0-beta2020-04-19

1.5.1 → 2.0.02023-10-15

PHP version history (5 changes)0.1PHP &gt;=5.4.16

0.6.1PHP &gt;=5.6

1.0.0-betaPHP &gt;=7.2

1.3.0PHP &gt;=7.3

2.0.0PHP &gt;=8.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/39854?v=4)[Mark Scherer](/maintainers/dereuromark)[@dereuromark](https://github.com/dereuromark)

---

Top Contributors

[![dereuromark](https://avatars.githubusercontent.com/u/39854?v=4)](https://github.com/dereuromark "dereuromark (232 commits)")[![ewbarnard](https://avatars.githubusercontent.com/u/1979538?v=4)](https://github.com/ewbarnard "ewbarnard (42 commits)")[![hemberger](https://avatars.githubusercontent.com/u/846186?v=4)](https://github.com/hemberger "hemberger (2 commits)")[![mrrsm](https://avatars.githubusercontent.com/u/1251354?v=4)](https://github.com/mrrsm "mrrsm (1 commits)")[![rmccue](https://avatars.githubusercontent.com/u/21655?v=4)](https://github.com/rmccue "rmccue (1 commits)")

---

Tags

code-stylefixerphpsniffertokenizerstatic analysiscodesniffercs

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/fig-r-psr2r-sniffer/health.svg)

```
[![Health](https://phpackages.com/badges/fig-r-psr2r-sniffer/health.svg)](https://phpackages.com/packages/fig-r-psr2r-sniffer)
```

###  Alternatives

[phpcompatibility/phpcompatibility-wp

A ruleset for PHP\_CodeSniffer to check for PHP cross-version compatibility issues in projects, while accounting for polyfills provided by WordPress.

22130.6M587](/packages/phpcompatibility-phpcompatibility-wp)[sirbrillig/phpcs-variable-analysis

A PHPCS sniff to detect problems with variables.

14548.5M97](/packages/sirbrillig-phpcs-variable-analysis)[spryker/code-sniffer

Spryker Code Sniffer Standards

374.1M2.3k](/packages/spryker-code-sniffer)[consistence/coding-standard

Consistence - Coding Standard - PHP Code Sniffer rules

75833.3k94](/packages/consistence-coding-standard)[phpcsstandards/phpcsutils

A suite of utility functions for use with PHP\_CodeSniffer

6333.4M58](/packages/phpcsstandards-phpcsutils)[yoast/yoastcs

PHP\_CodeSniffer rules for Yoast projects

221.1M29](/packages/yoast-yoastcs)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
