Warning
This package is deprecated. Use Easy Coding Standard (ECS) instead, where these rules and coding standard work out of the box—no extra setup needed.
Coding standard rules for clean, consistent, and readable PHP code. No configuration needed—just install and let it handle the rest.
They run best with ECS.
composer require symplify/coding-standard symplify/easy-coding-standard --dev- Register in
ecs.phpconfig:
# ecs.php
use Symplify\EasyCodingStandard\Config\ECSConfig;
return ECSConfig::configure()
->withPreparedSets(symplify: true);- And run:
# dry-run without changes
vendor/bin/ecs
# apply changes
vendor/bin/ecs --fixIndexed PHP array item has to have one line per item
-$value = ['simple' => 1, 'easy' => 2];
+$value = ['simple' => 1,
+'easy' => 2];Indexed PHP array opener [ and closer ] must be on own line
-$items = [1 => 'Hey'];
+$items = [
+1 => 'Hey'
+];Strict type declaration has to be followed by empty line
declare(strict_types=1);
+
namespace App;Array items, method parameters, method call arguments, new arguments should be on same/standalone line to fit line length.
🔧 configure it!
-function some($veryLong, $superLong, $oneMoreTime)
-{
+function some(
+ $veryLong,
+ $superLong,
+ $oneMoreTime
+) {
}
-function another(
- $short,
- $now
-) {
+function another($short, $now) {
}Each chain method call must be on own line
-$someClass->firstCall()->secondCall();
+$someClass->firstCall()
+->secondCall();Single-task rules that each fix one kind of @param/@return/@var malform. They are registered together in the docblock set and all handle the @phpstan- and @psalm- prefixed variants of these tags.
Add a missing variable name to a @param annotation
/**
- * @param string
+ * @param string $name
*/
function getPerson($name)
{
}Add a missing variable name to an inline @var annotation
-/** @var int */
+/** @var int $value */
$value = 1000;Use a double asterisk /** doc block for an inline @var comment
-/* @var int $variable */
+/** @var int $variable */
$variable = 5;Fix a typo in the @param variable name to match the real argument
/**
* @param string $one
- * @param string $twoTypo
+ * @param string $two
*/
function anotherFunction(string $one, string $two)
{
}Remove a dead @param line that has only a name and no type
/**
* @param string $name
- * @param $age
*/
function withDeadParam(string $name, $age)
{
}Remove the reference & from a @param variable name
/**
- * @param string &$name
+ * @param string $name
*/
function paramReference($name)
{
}Remove a superfluous variable name from a @return annotation
/**
- * @return int $value
+ * @return int
*/
function function1(): int
{
}Remove a superfluous variable name from a property @var annotation
/**
- * @var string $property
+ * @var string
*/
private $property;Collapse a multi-line inline @var doc block into a single line
-/**
- * @var int $value
- */
+/** @var int $value */
$value = 1000;Reorder switched type and variable name in @param/@var annotation
/**
- * @param $a string
- * @param $b string|null
+ * @param string $a
+ * @param string|null $b
*/
function test($a, string $b = null): string
{
}Remove docblock descriptions which duplicate their property name
/**
- * @var string $name
+ * @var string
*/
private $name;Remove docblock descriptions which duplicate their method name
/**
- * Get name
*
* @return string
*/
function getName()
{
}Remove "Created by PhpStorm" annotations
-/**
- * Created by PhpStorm.
- * User: ...
- * Date: 17/10/17
- * Time: 8:50 AM
- */
class SomeClass
{
}Remove useless PHPStorm-generated @todo comments, redundant "Class XY" or "gets service" comments etc.
-/**
- * class SomeClass
- */
class SomeClass
{
- /**
- * SomeClass Constructor.
- */
public function __construct()
{
- // TODO: Change the autogenerated stub
- // TODO: Implement whatever() method.
}
}It also removes "Class representing XY" comments:
-/**
- * Class representing TeamPlayer
- */
class TeamPlayer
{
}Comments that only repeat the class name are removed:
-/**
- * TeamPlayer
- */
class TeamPlayer
{
}As well as the default doc block generated by the Doctrine ORM:
-/**
- * This class was generated by the Doctrine ORM. Add your own custom
- * repository methods below.
- */
class SomeRepository
{
}Add space after nowdoc and heredoc keyword, to prevent bugs on PHP 7.2 and lower, see https://laravel-news.com/flexible-heredoc-and-nowdoc-coming-to-php-7-3
$values = [
<<<RECTIFY
Some content
-RECTIFY,
+RECTIFY
+,
1000
];Constructor param should be on a standalone line to ease git diffs on new dependency
final class PromotedProperties
{
- public function __construct(int $age, string $name)
- {
+ public function __construct(
+ int $age,
+ string $name
+ ) {
}
}Indexed arrays must have 1 item per line
-$friends = [1 => 'Peter', 2 => 'Paul'];
+$friends = [
+ 1 => 'Peter',
+ 2 => 'Paul'
+];Promoted property should be on standalone line
final class PromotedProperties
{
- public function __construct(public int $age, private string $name)
- {
+ public function __construct(
+ public int $age,
+ private string $name
+ ) {
}
}