PHPackages                             bmitch/codor - 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. [Testing &amp; Quality](/categories/testing)
4. /
5. bmitch/codor

ActiveLibrary[Testing &amp; Quality](/categories/testing)

bmitch/codor
============

Custom PHPCS sniffs to find Code Smells.

1.2.3(4y ago)4648.0k↓58%9[21 issues](https://github.com/bmitch/Codor/issues)[1 PRs](https://github.com/bmitch/Codor/pulls)MITPHPPHP &gt;=7.1.3CI failing

Since Dec 6Pushed 4y ago3 watchersCompare

[ Source](https://github.com/bmitch/Codor)[ Packagist](https://packagist.org/packages/bmitch/codor)[ RSS](/packages/bmitch-codor/feed)WikiDiscussions master Synced yesterday

READMEChangelog (10)Dependencies (4)Versions (30)Used By (0)

Code Odor Sniffer
=================

[](#code-odor-sniffer)

👃 💩 Custom PHP Code Sniffer sniffs to help find Code Smells (Odor).

[![Build Status](https://github.com/bmitch/Codor/workflows/Continuous%20Integration/badge.svg)](https://github.com/bmitch/Codor/actions)[![codecov](https://camo.githubusercontent.com/e26bd773106e491bdd1ddaf3ef6d362f92172b2aa878d17e3f8e1b4f5a1c8526/68747470733a2f2f636f6465636f762e696f2f67682f626d697463682f436f646f722f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/bmitch/Codor)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/f40adbfe61c9625fd192be524036cc1340268307a4eae3f791cfec1ea7fbe74c/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f626d697463682f436f646f722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/bmitch/Codor/?branch=master)[![Code Climate](https://camo.githubusercontent.com/2ae0b18cb28d36f16fda4110b4729c764b9c98121eb7634b5e232585a8609820/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f626d697463682f436f646f722f6261646765732f6770612e737667)](https://codeclimate.com/github/bmitch/Codor)[![Packagist](https://camo.githubusercontent.com/9caf051404f6ada519b39518f3bf84804ed44ee4d3cdfe4403777efcd96ea23a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f626d697463682f636f646f722e737667)](https://packagist.org/packages/bmitch/codor)[![Packagist](https://camo.githubusercontent.com/ed59fcb6a6b9b349a5fdca230330a9befb452a38688e26a4c3e04dd1608aa3bb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f626d697463682f636f646f722e737667)](https://packagist.org/packages/bmitch/codor/stats)[![License](https://camo.githubusercontent.com/e672527a9bc795ecb5c5c382cdab502fec2ce3768af163abb1a86e199e79d0a5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f626d697463682f636f646f722e737667)](LICENSE.md)
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

[](#)

*Inspired by: *

- [What Is it?](#what-is-it)
- [Compatibility](#compatibility)
- [How to Install?](#how-to-install)
- [How to Use?](#how-to-use)
- [Omitting Sniffs](#omitting-sniffs)
- [Running Specific Sniffs](#running-specific-sniffs)
- [Sniffs Included](#sniffs-included)
- [Customizing Sniffs](#customizing-sniffs)
- [Customizations Available](#customizations-available)
- [Similar Packages](#similar-packages)
- [Contributing](#contributing)
- [License](#license)

What is it?
-----------

[](#what-is-it)

This package is a set of custom Sniffs for the [PHP Code Sniffer](https://github.com/squizlabs/PHP_CodeSniffer) that you can use in your CI build to ensure the ingegrity of your code base.

Compatibility
-------------

[](#compatibility)

- PHP 7.1+ please use v1.0.0 and above.
- PHP 5.6 and below please use any version below v1.0.0.

How to Install?
---------------

[](#how-to-install)

Install via Composer:

```
composer require bmitch/codor --dev

```

How to Use?
-----------

[](#how-to-use)

Create a PHPCS ruleset XML (`codor.xml` or whatever filename you want) file in the root of your project.

```

    Project Coding Standard

```

Then run it with the command:

```
vendor/bin/phpcs --standard=codor.xml src

```

Where `src` is the location of the source code you want to check.

### Omitting Sniffs

[](#omitting-sniffs)

You may not want to run all the sniffs provided so you can specify which sniffs you want to exclude with the `--exclude` flag like:

```
vendor/bin/phpcs --standard=codor.xml --exclude=Codor.ControlStructures.NoElse src

```

(if you want to exclude multiple just separate them with a comma)

### Running Specific Sniffs

[](#running-specific-sniffs)

Or you can also specify which sniffs to specifically run:

```
vendor/bin/phpcs --standard=codor.xml --sniffs=Codor.ControlStructures.NoElse src

```

### Suppressing the sniffs on specific pieces of code

[](#suppressing-the-sniffs-on-specific-pieces-of-code)

Please see the PHPCS documentation:
[https://github.com/squizlabs/PHP\_CodeSniffer/wiki/Advanced-Usage#ignoring-files-and-folders](https://github.com/squizlabs/PHP_CodeSniffer/wiki/Advanced-Usage#ignoring-files-and-folders)

Sniffs Included
---------------

[](#sniffs-included)

### Codor.ControlStructures.NoElse

[](#codorcontrolstructuresnoelse)

Does not allow for any `else` or `elseif` statements.

❌

```
if ($foo) {
    return 'bar';
} else {
    return 'baz';
}
```

✅

```
if ($foo) {
    return 'bar';
}
return 'baz';
```

### Codor.Files.FunctionLength

[](#codorfilesfunctionlength)

Functions/methods must be no more than 20 lines.

❌

```
public function foo()
{
    // more than 20 lines
}
```

✅

```
public function foo()
{
    // no more than 20 lines
}
```

### Codor.Files.FunctionParameter

[](#codorfilesfunctionparameter)

Functions/methods must have no more than 3 parameters.

❌

```
public function foo($bar, $baz, $bop, $portugal)
{
    //
}
```

✅

```
public function foo($bar, $baz, $bop)
{
    //
}
```

### Codor.Files.ReturnNull

[](#codorfilesreturnnull)

Functions/methods must not return `null`.

❌

```
public function getAdapter($bar)
{
    if ($bar === 'baz') {
        return new BazAdapter;
    }
    return null;
}
```

✅

```
public function getAdapter($bar)
{
    if ($bar === 'baz') {
        return new BazAdapter;
    }
    return NullAdapter;
}
```

### Codor.Files.MethodFlagParameter

[](#codorfilesmethodflagparameter)

Functions/methods cannot have parameters that default to a boolean.

❌

```
public function getCustomers($active = true)
{
    if ($active) {
        // Code to get customers from who are active
    }

    // Code to get all customers
}
```

✅

```
public function getAllCustomers()
{
    // Code to get all customers
}

public function getAllActiveCustomers()
{
    // Code to get customers from who are active
}
```

### Codor.Classes.ClassLength

[](#codorclassesclasslength)

Classes must be no more than 200 lines.

❌

```
class ClassTooLong
{
    // More than 200 lines
}
```

✅

```
class ClassNotTooLong
{
    // No more than 200 lines
}
```

### Codor.Classes.ConstructorLoop

[](#codorclassesconstructorloop)

Class constructors must not contain any loops.

❌

```
public function __construct()
{
    for($index = 1; $index < 100; $index++) {
        // foo
    }
}
```

✅

```
public function __construct()
{
    $this->someMethod();
}

private function someMethod()
{
    for($index = 1; $index < 100; $index++) {
        // foo
    }
}
```

### Codor.Classes.Extends

[](#codorclassesextends)

Warns if a class extends another class. Goal is to promote composition over inheritance ([https://en.wikipedia.org/wiki/Composition\_over\_inheritance](https://en.wikipedia.org/wiki/Composition_over_inheritance)).

❌

```
class GasolineCar extends Vehicle
{
    //
}

class GasolineVehicle extends Vehicle
{
    //
}
```

✅

```
class Vehicle
{
    private $fuel;

    public function __construct(FuelInterface $fuel)
    {
        $this->fuel;
    }
}

class Gasoline implements FuelInterface
{

}

$gasolineCar = new Vehicle($gasoline);
```

### Codor.Classes.FinalPrivate

[](#codorclassesfinalprivate)

Final classes should not contain protected methods or variables. Should use private instead.

❌

```
final class Foo
{
    protected $baz;

    protected function bar()
    {
        //
    }
}
```

✅

```
final class Foo
{
    private $baz;

    private function bar()
    {
        //
    }
}
```

### Codor.Classes.NewInstance

[](#codorclassesnewinstance)

Classes should not instantiate objects. Should use dependency injection.

❌

```
class NewInConstructor
{
    private MyClass $myClass;

    public function __construct()
    {
        $this->myClass = new MyClass();
    }
}
```

✅

```
class NewInConstructor
{
    private MyClass $myClass;

    public function __construct(MyClass $myClass)
    {
        $this->myClass = $myClass;
    }
}
```

### Codor.Classes.PropertyDeclaration

[](#codorclassespropertydeclaration)

Produces an error if your class uses undeclared member variables. Only warns if class extends another class.

❌

```
class Foo
{
    private function bar()
    {
        $this->baz = 13;
    }
}
```

✅

```
class Foo
{
    private $baz;

    private function bar()
    {
        $this->baz = 13;
    }
}
```

### Codor.Files.FunctionNameContainsAndOr

[](#codorfilesfunctionnamecontainsandor)

Functions/methods cannot contain "And" or "Or". This could be a sign of a function that does more than one thing.

❌

```
public function validateStringAndUpdateDatabase()
{
    // code to validate string
    // code to update database
}
```

✅

```
public function validateString()
{
    // code to validate string
}

public function updateDatabase()
{
    // code to update database
}
```

### Codor.Files.IndentationLevel

[](#codorfilesindentationlevel)

Functions/methods cannot have more than 2 level of indentation.

❌

```
public function foo($collection)
{
    foreach ($collection as $bar) {
        foreach ($bar as $baz) {
            //
        }
    }
}
```

✅

```
public function foo($collection)
{
    foreach ($collection as $bar) {
        $this->process($bar);
    }
}

private function process($bar)
{
    foreach ($bar as $baz) {
        //
    }
}
```

### Codor.ControlStructures.NestedIf

[](#codorcontrolstructuresnestedif)

Nested if statements are not allowed.

❌

```
public function allowedToDrink($person)
{
    if ($person->age === 19) {
        if ($person->hasValidId()) {
            return true;
        }
    }

    return false;
}
```

✅

```
public function allowedToDrink($person)
{
    if ($person->age !== 19) {
        return false;
    }

    if (! $person->hasValidId()) {
        return false;
    }

    return true;
}
```

### Codor.Syntax.NullCoalescing

[](#codorsyntaxnullcoalescing)

Produces an error if a line contains a ternary operator that could be converted to a Null Coalescing operator.

❌

```
$username = isset($customer['name']) ? $customer['name'] : 'nobody';
```

✅

```
$username = $customer['name'] ?? 'nobody';
```

### Codor.Syntax.LinesAfterMethod

[](#codorsyntaxlinesaftermethod)

Only allows for 1 line between functions/methods. Any more than 1 will produce an error.

❌

```
public function foo()
{
    //
}

public function bar()
{
    //
}
```

✅

```
public function foo()
{
    //
}

public function bar()
{
    //
}
```

### Codor.TypeHints.MixedReturnType

[](#codortypehintsmixedreturntype)

Prevents you from having a `mixed` type returned in a doc block.

❌

```
/**
 * @return mixed
 */
public function foo()
{
    //
}
```

✅

```
/**
 * @return string
 */
public function foo()
{
    //
}
```

Customizing Sniffs
------------------

[](#customizing-sniffs)

Some of the sniff rules can be customized to your liking. For example, if you'd want the `Codor.Files.FunctionLength` to make sure your functions are no more than 30 lines instead of 20, you can do that. Here's an example of a `codor.xml` file with that customization:

```

    Project Coding Standard

```

### Customizations Available

[](#customizations-available)

- `Codor.Files.FunctionLength`
- `maxLength`: The maximum number of lines a function/method can have (default = 20).
- `Codor.Files.FunctionParameter`
- `maxParameters`: The maximum number of parameters a function/method can have (default = 3).
- `Codor.Classes.ClassLength`
- `maxLength`: The maximum number of lines a Class can have (default = 200).
- `Codor.Files.IndentationLevel`
- `indentationLimit`: Cannot have more than or equal to this number of indentations (default = 2).

Similar Packages
----------------

[](#similar-packages)

-
-

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING.md](CONTRIBUTING.md)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

39

—

LowBetter than 84% of packages

Maintenance11

Infrequent updates — may be unmaintained

Popularity42

Moderate usage in the ecosystem

Community17

Small or concentrated contributor base

Maturity69

Established project with proven stability

 Bus Factor1

Top contributor holds 83.4% 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 ~84 days

Recently: every ~422 days

Total

25

Last Release

1476d ago

Major Versions

0.0.11 → 1.0.02017-04-01

PHP version history (2 changes)1.0.0PHP &gt;=7.0.0

1.2.0PHP &gt;=7.1.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/581585b68bc8e4418bfefd6918579de4b277539f1c98a478bf044750eb64ae93?d=identicon)[bmitch](/maintainers/bmitch)

---

Top Contributors

[![bmitch](https://avatars.githubusercontent.com/u/4009957?v=4)](https://github.com/bmitch "bmitch (151 commits)")[![villfa](https://avatars.githubusercontent.com/u/2891564?v=4)](https://github.com/villfa "villfa (24 commits)")[![d35k](https://avatars.githubusercontent.com/u/26274293?v=4)](https://github.com/d35k "d35k (3 commits)")[![kevin-schmitt](https://avatars.githubusercontent.com/u/10809414?v=4)](https://github.com/kevin-schmitt "kevin-schmitt (2 commits)")[![szepeviktor](https://avatars.githubusercontent.com/u/952007?v=4)](https://github.com/szepeviktor "szepeviktor (1 commits)")

---

Tags

clean-codecoding-standardscoding-stylecustomizing-sniffsphpphp-codesniffersniffer

### Embed Badge

![Health badge](/badges/bmitch-codor/health.svg)

```
[![Health](https://phpackages.com/badges/bmitch-codor/health.svg)](https://phpackages.com/packages/bmitch-codor)
```

###  Alternatives

[slevomat/coding-standard

Slevomat Coding Standard for PHP\_CodeSniffer complements Consistence Coding Standard by providing sniffs with additional checks.

1.5k134.0M2.3k](/packages/slevomat-coding-standard)[fig-r/psr2r-sniffer

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

331.3M153](/packages/fig-r-psr2r-sniffer)[youwe/testing-suite

Contains Youwe's default testing packages for php.

13191.0k8](/packages/youwe-testing-suite)[hyva-themes/hyva-coding-standard

A set of Hyvä specific PHP CodeSniffer rules extending the Magento Coding Standard

2927.5k](/packages/hyva-themes-hyva-coding-standard)

PHPackages © 2026

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