pedrotroller / php-cs-custom-fixer
PHP-CS-FIXER : my custom fixers
Package info
github.com/PedroTroller/PhpCSFixer-Custom-Fixers
pkg:composer/pedrotroller/php-cs-custom-fixer
Requires
- php: ^8.3
- friendsofphp/php-cs-fixer: ^3.87
Requires (Dev)
- phpspec/phpspec: ^8.0
- sebastian/diff: ^4.0
- twig/twig: ^3.3
- webmozart/assert: ^1.10
Suggests
None
Provides
None
Conflicts
None
Replaces
None
- dev-master / 3.x-dev
- v2.35.0
- v2.34.0
- v2.33.2
- v2.33.1
- v2.33.0
- v2.32.3
- v2.32.2
- v2.32.1
- v2.32.0
- v2.31.0
- v2.30.0
- v2.29.0
- v2.28.0
- v2.27.0
- v2.26.0
- v2.25.1
- v2.25.0
- v2.24.1
- v2.24.0
- v2.23.2
- v2.23.1
- v2.23.0
- v2.22.0
- v2.21.0
- v2.20.0
- v2.19.1
- v2.19.0
- v2.18.1
- v2.18.0
- v2.17.1
- v2.17.0
- v2.16.1
- v2.16.0
- v2.15.4
- v2.15.3
- v2.15.2
- v2.15.1
- v2.15.0
- v2.14.0
- v2.13.1
- v2.13.0
- v2.12.1
- v2.12.0
- v2.11.1
- v2.11.0
- v2.10.2
- v2.10.1
- v2.10.0
- v2.9.1
- v2.9.0
- v2.8.0
- v2.7.0
- v2.6.3
- v2.6.2
- v2.6.1
- v2.6.0
- v2.5.0
- v2.4.0
- v2.3.1
- v2.3.0
- v2.2.2
- v2.2.1
- v2.2.0
- v2.1.2
- v2.1.1
- v2.1
- v2.0
- v1.6.0
- v1.5.0
- v1.4.0
- v1.3.3
- v1.3.2
- v1.3.1
- v1.3.0
- v1.2.1
- v1.2.0
- v1.1.0
- v1.0.0
- dev-feat/force-for-construct
- dev-chore/strict-function-calls
- dev-chore/strict-all-rules
- dev-chore/strict-disallowed-empty
- dev-chore/strict-booleans-in-conditions
- dev-chore/strict-no-variable-variables
- dev-chore/strict-useless-cast
- dev-chore/strict-overwrite-variables-with-loop
- dev-chore/strict-numeric-operands-in-arithmetic-operators
- dev-chore/strict-dynamic-call-on-static-method
- dev-chore/strict-disallowed-short-ternary
- dev-chore/strict-switch-conditions-matching-type
- dev-chore/strict-array-filter
- dev-chore/strict-require-parent-constructor-call
- dev-chore/strict-matching-inherited-method-names
- dev-chore/strict-illegal-constructor-method-call
- dev-chore/strict-disallowed-loose-comparison
- dev-chore/strict-disallowed-implicit-array-creation
- dev-chore/strict-disallowed-backtick
- dev-chore/strict-closure-uses-this
- dev-chore/strict-booleans-in-loop-conditions
- dev-chore/phpstan-strict-rules
- dev-chore/phpstan-extensions
- dev-chore/phpstan-level-max
- dev-chore/phpstan-level-8
- dev-chore/ci-check-make-fix
- dev-chore/rector
- dev-chore/phpstan-level-7
- dev-chore/phpstan-level-6
- dev-chore/phpstan-level-5
- dev-chore/phpstan-level-3
- dev-chore/phpstan-level-4
- dev-chore/phpstan-level-2
- dev-feat/phpstan-ci
- dev-feat/ruleset-factory-coverage
- dev-chore/github-actions
- dev-chore/docker-dev-env
- dev-fix/incompatibility-with-single_line_empty_body
- dev-phpstan
- dev-feature/trigger-deprecation
This package is auto-updated.
Last update: 2026-10-09 16:02:57 UTC
README
Installation
composer require pedrotroller/php-cs-custom-fixer --dev
Configuration
// .php_cs.dist <?php $config = PhpCsFixer\Config::create() // ... ->registerCustomFixers(new PedroTroller\CS\Fixer\Fixers()) // ... ; return $config;
Fixers
PedroTroller/order_behat_steps
Step definition methods in Behat contexts MUST BE ordered by annotation and method name.
Available options
instanceof(optional): Parent class or interface of your behat context classes.- default:
Behat\Behat\Context\Context
- default:
Configuration examples
// .php_cs.dist <?php $config = new PhpCsFixer\Config(); // ... $config->setRules( [ // ... 'PedroTroller/order_behat_steps' => true, // ... ] ); $config->registerCustomFixers(new PedroTroller\CS\Fixer\Fixers()); // ... return $config;
OR using my rule list builder.
// .php_cs.dist <?php $config = new PhpCsFixer\Config(); // ... $config->setRules( PedroTroller\CS\Fixer\RuleSetFactory::create() ->enable('PedroTroller/order_behat_steps') ->getRules() ); $config->registerCustomFixers(new PedroTroller\CS\Fixer\Fixers()); // ... return $config;
Fixes
--- Original // 80 chars +++ New // @@ @@ // } // // /** // - * @Then the response should be received // + * @BeforeScenario // */ // - public function theResponseShouldBeReceived() // + public function reset() // { // // ... // } // // /** // - * @When a demo scenario sends a request to :path // + * @Given I am on the homepage // */ // - public function aDemoScenarioSendsARequestTo($path) // + public function iAmOnTheHomepage() // { // // ... // } // // /** // - * @Given I am on the homepage // + * @When a demo scenario sends a request to :path // */ // - public function iAmOnTheHomepage() // + public function aDemoScenarioSendsARequestTo($path) // { // // ... // } // // /** // - * @BeforeScenario // + * @Then the response should be received // */ // - public function reset() // + public function theResponseShouldBeReceived() // { // // ... // } // } // //
Configuration examples
// .php_cs.dist <?php $config = new PhpCsFixer\Config(); // ... $config->setRules( [ // ... 'PedroTroller/order_behat_steps' => [ 'instanceof' => [ 'Behat\Behat\Context\Context' ] ], // ... ] ); $config->registerCustomFixers(new PedroTroller\CS\Fixer\Fixers()); // ... return $config;
OR using my rule list builder.
// .php_cs.dist <?php $config = new PhpCsFixer\Config(); // ... $config->setRules( PedroTroller\CS\Fixer\RuleSetFactory::create() ->enable('PedroTroller/order_behat_steps', [ 'instanceof' => [ 'Behat\Behat\Context\Context' ] ]) ->getRules() ); $config->registerCustomFixers(new PedroTroller\CS\Fixer\Fixers()); // ... return $config;
Fixes
--- Original // 80 chars +++ New // @@ @@ // } // // /** // - * @Then the response should be received // + * @BeforeScenario // */ // - public function theResponseShouldBeReceived() // + public function reset() // { // // ... // } // // /** // - * @When a demo scenario sends a request to :path // + * @Given I am on the homepage // */ // - public function aDemoScenarioSendsARequestTo($path) // + public function iAmOnTheHomepage() // { // // ... // } // // /** // - * @Given I am on the homepage // + * @When a demo scenario sends a request to :path // */ // - public function iAmOnTheHomepage() // + public function aDemoScenarioSendsARequestTo($path) // { // // ... // } // // /** // - * @BeforeScenario // + * @Then the response should be received // */ // - public function reset() // + public function theResponseShouldBeReceived() // { // // ... // } // } // //
PedroTroller/ordered_with_getter_and_setter_first
Class/interface/trait methods MUST BE ordered (accessors at the beginning of the class, ordered following properties order).
Configuration examples
// .php_cs.dist <?php $config = new PhpCsFixer\Config(); // ... $config->setRules( [ // ... 'PedroTroller/ordered_with_getter_and_setter_first' => true, // ... ] ); $config->registerCustomFixers(new PedroTroller\CS\Fixer\Fixers()); // ... return $config;
OR using my rule list builder.
// .php_cs.dist <?php $config = new PhpCsFixer\Config(); // ... $config->setRules( PedroTroller\CS\Fixer\RuleSetFactory::create() ->enable('PedroTroller/ordered_with_getter_and_setter_first') ->getRules() ); $config->registerCustomFixers(new PedroTroller\CS\Fixer\Fixers()); // ... return $config;
Fixes
--- Original // 80 chars +++ New // @@ @@ // } // } // // - public function setFirstName($firstName) // + public function getIdentifier() // { // - $this->firstName = $firstName; // + return $this->identifier; // } // // - public function setName($name) // + public function getName() // { // - $this->name = $name; // + return $this->name; // } // // - public function isEnabled() // + public function setName($name) // { // - return $this->enabled; // + $this->name = $name; // } // // - public function getName() // + public function getFirstName() // { // - return $this->name; // + return $this->firstName; // } // // - public function getIdentifier() // + public function setFirstName($firstName) // { // - return $this->identifier; // + $this->firstName = $firstName; // } // // - public function getFirstName() // + public function isEnabled() // { // - return $this->firstName; // + return $this->enabled; // } // // public function enable() // //
PedroTroller/exceptions_punctuation
Exception messages MUST ends by ".", "…", "?" or "!".
Risky: will change the exception message.
Configuration examples
// .php_cs.dist <?php $config = new PhpCsFixer\Config(); // ... $config->setRules( [ // ... 'PedroTroller/exceptions_punctuation' => true, // ... ] ); $config->registerCustomFixers(new PedroTroller\CS\Fixer\Fixers()); // ... return $config;
OR using my rule list builder.
// .php_cs.dist <?php $config = new PhpCsFixer\Config(); // ... $config->setRules( PedroTroller\CS\Fixer\RuleSetFactory::create() ->enable('PedroTroller/exceptions_punctuation') ->getRules() ); $config->registerCustomFixers(new PedroTroller\CS\Fixer\Fixers()); // ... return $config;
Fixes
--- Original // 80 chars +++ New // @@ @@ // class MyClass { // public function fun1() // { // - throw new \Exception('This is the message'); // + throw new \Exception('This is the message.'); // } // // public function fun2($data) // { // - throw new LogicException(sprintf('This is the %s', 'message')); // + throw new LogicException(sprintf('This is the %s.', 'message')); // } // } // //
PedroTroller/forbidden_functions
Prohibited functions MUST BE commented on as prohibited
Available options
-
comment(optional): The prohibition message to put in the comment- default:
@TODO remove this line
- default:
-
functions(optional): The function names to be marked how prohibited- default:
var_dump,dump,die
- default:
Configuration examples
// .php_cs.dist <?php $config = new PhpCsFixer\Config(); // ... $config->setRules( [ // ... 'PedroTroller/forbidden_functions' => [ 'comment' => 'YOLO' ], // ... ] ); $config->registerCustomFixers(new PedroTroller\CS\Fixer\Fixers()); // ... return $config;
OR using my rule list builder.
// .php_cs.dist <?php $config = new PhpCsFixer\Config(); // ... $config->setRules( PedroTroller\CS\Fixer\RuleSetFactory::create() ->enable('PedroTroller/forbidden_functions', [ 'comment' => 'YOLO' ]) ->getRules() ); $config->registerCustomFixers(new PedroTroller\CS\Fixer\Fixers()); // ... return $config;
Fixes
--- Original // 80 chars +++ New // @@ @@ // class MyClass { // public function fun() // { // - var_dump('this is a var_dump'); // + var_dump('this is a var_dump'); // YOLO // // $this->dump($this); // // //
Configuration examples
// .php_cs.dist <?php $config = new PhpCsFixer\Config(); // ... $config->setRules( [ // ... 'PedroTroller/forbidden_functions' => [ 'comment' => 'NEIN NEIN NEIN !!!', 'functions' => [ 'var_dump', 'var_export' ] ], // ... ] ); $config->registerCustomFixers(new PedroTroller\CS\Fixer\Fixers()); // ... return $config;
OR using my rule list builder.
// .php_cs.dist <?php $config = new PhpCsFixer\Config(); // ... $config->setRules( PedroTroller\CS\Fixer\RuleSetFactory::create() ->enable('PedroTroller/forbidden_functions', [ 'comment' => 'NEIN NEIN NEIN !!!', 'functions' => [ 'var_dump', 'var_export' ] ]) ->getRules() ); $config->registerCustomFixers(new PedroTroller\CS\Fixer\Fixers()); // ... return $config;
Fixes
--- Original // 80 chars +++ New // @@ @@ // class MyClass { // public function fun() // { // - var_dump('this is a var_dump'); // + var_dump('this is a var_dump'); // NEIN NEIN NEIN !!! // // $this->dump($this); // // - return var_export($this); // + return var_export($this); // NEIN NEIN NEIN !!! // } // // public function dump($data) // //
PedroTroller/line_break_between_method_arguments
If the declaration of a method is too long, the arguments of this method MUST BE separated (one argument per line)
Available options
-
automatic-argument-merge(optional): If both conditions are met (the line is not too long and there are not too many arguments), then the arguments are put back inline- default:
true
- default:
-
force-for-construct(optional): If true, the __construct method arguments will always be split into several lines- default:
false
- default:
-
inline-attributes(optional): In the case of a split, the declaration of the attributes of the arguments of the method will be on the same line as the arguments themselves- default:
false
- default:
-
max-args(optional): The maximum number of arguments allowed with splitting the arguments into several lines (usefalseto disable this feature)- default:
3
- default:
-
max-length(optional): The maximum number of characters allowed with splitting the arguments into several lines- default:
120
- default:
Configuration examples
// .php_cs.dist <?php $config = new PhpCsFixer\Config(); // ... $config->setRules( [ // ... 'PedroTroller/line_break_between_method_arguments' => [ 'max-args' => 4, 'max-length' => 120, 'automatic-argument-merge' => true, 'inline-attributes' => true, 'force-for-construct' => false ], // ... ] ); $config->registerCustomFixers(new PedroTroller\CS\Fixer\Fixers()); // ... return $config;
OR using my rule list builder.
// .php_cs.dist <?php $config = new PhpCsFixer\Config(); // ... $config->setRules( PedroTroller\CS\Fixer\RuleSetFactory::create() ->enable('PedroTroller/line_break_between_method_arguments', [ 'max-args' => 4, 'max-length' => 120, 'automatic-argument-merge' => true, 'inline-attributes' => true, 'force-for-construct' => false ]) ->getRules() ); $config->registerCustomFixers(new PedroTroller\CS\Fixer\Fixers()); // ... return $config;
Fixes
--- Original // 80 chars +++ New // @@ @@ // return; // } // // - public function fun2($arg1, array $arg2 = [], \ArrayAccess $arg3 = null, bool $bool = true, \Iterator $thisLastArgument = null) - { // + public function fun2( // + $arg1, // + array $arg2 = [], // + \ArrayAccess $arg3 = null, // + bool $bool = true, // + \Iterator $thisLastArgument = null // + ) { // return; // } // // - public function fun3( // - $arg1, // - array $arg2 = [] // - ) { // + public function fun3($arg1, array $arg2 = []) // + { // return; // } // } // //
Configuration examples
// .php_cs.dist <?php $config = new PhpCsFixer\Config(); // ... $config->setRules( [ // ... 'PedroTroller/line_break_between_method_arguments' => [ 'max-args' => false, 'max-length' => 120, 'automatic-argument-merge' => true, 'inline-attributes' => true, 'force-for-construct' => false ], // ... ] ); $config->registerCustomFixers(new PedroTroller\CS\Fixer\Fixers()); // ... return $config;
OR using my rule list builder.
// .php_cs.dist <?php $config = new PhpCsFixer\Config(); // ... $config->setRules( PedroTroller\CS\Fixer\RuleSetFactory::create() ->enable('PedroTroller/line_break_between_method_arguments', [ 'max-args' => false, 'max-length' => 120, 'automatic-argument-merge' => true, 'inline-attributes' => true, 'force-for-construct' => false ]) ->getRules() ); $config->registerCustomFixers(new PedroTroller\CS\Fixer\Fixers()); // ... return $config;
Fixes
--- Original // 80 chars +++ New // @@ @@ // return; // } // // - public function fun2($arg1, array $arg2 = [], \ArrayAccess $arg3 = null, bool $bool = true, \Iterator $thisLastArgument = null) - { // + public function fun2( // + $arg1, // + array $arg2 = [], // + \ArrayAccess $arg3 = null, // + bool $bool = true, // + \Iterator $thisLastArgument = null // + ) { // return; // } // // - public function fun3( // - $arg1, // - array $arg2 = [] // - ) { // + public function fun3($arg1, array $arg2 = []) // + { // return; // } // } // //
PedroTroller/line_break_between_statements
Each statement (in, for, foreach, ...) MUST BE separated by an empty line
Configuration examples
// .php_cs.dist <?php $config = new PhpCsFixer\Config(); // ... $config->setRules( [ // ... 'PedroTroller/line_break_between_statements' => true, // ... ] ); $config->registerCustomFixers(new PedroTroller\CS\Fixer\Fixers()); // ... return $config;
OR using my rule list builder.
// .php_cs.dist <?php $config = new PhpCsFixer\Config(); // ... $config->setRules( PedroTroller\CS\Fixer\RuleSetFactory::create() ->enable('PedroTroller/line_break_between_statements') ->getRules() ); $config->registerCustomFixers(new PedroTroller\CS\Fixer\Fixers()); // ... return $config;
Fixes
--- Original // 80 chars +++ New // @@ @@ // do { // // ... // } while (true); // + // foreach (['foo', 'bar'] as $str) { // // ... // } // + // if (true === false) { // // ... // } // - // // while (true) { // // ... // //
PedroTroller/comment_line_to_phpdoc_block
Classy elements (method, property, ...) comments MUST BE a PhpDoc block
Configuration examples
// .php_cs.dist <?php $config = new PhpCsFixer\Config(); // ... $config->setRules( [ // ... 'PedroTroller/comment_line_to_phpdoc_block' => true, // ... ] ); $config->registerCustomFixers(new PedroTroller\CS\Fixer\Fixers()); // ... return $config;
OR using my rule list builder.
// .php_cs.dist <?php $config = new PhpCsFixer\Config(); // ... $config->setRules( PedroTroller\CS\Fixer\RuleSetFactory::create() ->enable('PedroTroller/comment_line_to_phpdoc_block') ->getRules() ); $config->registerCustomFixers(new PedroTroller\CS\Fixer\Fixers()); // ... return $config;
Fixes
--- Original // 80 chars +++ New // @@ @@ // */ // private $name; // // - // @var string | null // + /** // + * @var string | null // + */ // private $value; // // /** // @@ @@ // $this->name = $name; // } // // - // Get the name // - // // - // @return string // + /** // + * Get the name // + * // + * @return string // + */ // public function getName() // { // return $this->name; // } // // - // Get the value // - // @return null | string // + /** // + * Get the value // + * @return null | string // + */ // public function getValue() // { // return $this->value; // } // // - // Set the value // - // - // @param string $value // + /** // + * Set the value // + * @param string $value // + */ // public function setValue($value) // { // $this->value = $value; // } // } // //
PedroTroller/useless_code_after_return
All return that are not accessible (i.e. following another return) MUST BE deleted
Configuration examples
// .php_cs.dist <?php $config = new PhpCsFixer\Config(); // ... $config->setRules( [ // ... 'PedroTroller/useless_code_after_return' => true, // ... ] ); $config->registerCustomFixers(new PedroTroller\CS\Fixer\Fixers()); // ... return $config;
OR using my rule list builder.
// .php_cs.dist <?php $config = new PhpCsFixer\Config(); // ... $config->setRules( PedroTroller\CS\Fixer\RuleSetFactory::create() ->enable('PedroTroller/useless_code_after_return') ->getRules() ); $config->registerCustomFixers(new PedroTroller\CS\Fixer\Fixers()); // ... return $config;
Fixes
--- Original // 80 chars +++ New // @@ @@ // */ // public function fun1(Model\User $user, Model\Address $address = null) { // return; // - // - $user->setName('foo'); // - // - return $this; // } // // /** // @@ @@ // switch ($this->status) { // case 1: // return $this->name; // - break; // default: // return $this; // - return $this; // } // } // // @@ @@ // */ // public function buildCallable() // { // - return function () { return true; return false; }; // + return function () { return true; }; // } // } // //
PedroTroller/doctrine_migrations
Unnecessary empty methods (getDescription(), up(), down()) and comments MUST BE removed from Doctrine migrations
Available options
instanceof(optional): The parent class of which Doctrine migrations extend- default:
Doctrine\Migrations\AbstractMigration
- default:
Configuration examples
// .php_cs.dist <?php $config = new PhpCsFixer\Config(); // ... $config->setRules( [ // ... 'PedroTroller/doctrine_migrations' => true, // ... ] ); $config->registerCustomFixers(new PedroTroller\CS\Fixer\Fixers()); // ... return $config;
OR using my rule list builder.
// .php_cs.dist <?php $config = new PhpCsFixer\Config(); // ... $config->setRules( PedroTroller\CS\Fixer\RuleSetFactory::create() ->enable('PedroTroller/doctrine_migrations') ->getRules() ); $config->registerCustomFixers(new PedroTroller\CS\Fixer\Fixers()); // ... return $config;
Fixes
--- Original // 80 chars +++ New // @@ @@ // use Doctrine\DBAL\Schema\Schema; // use Doctrine\Migrations\AbstractMigration; // // -/** // - * Auto-generated Migration: Please modify to your needs! // - */ // final class Version20190323095102 extends AbstractMigration // { // - public function getDescription() // - { // - return ''; // - } // // public function up(Schema $schema) // { // - // this up() migration is auto-generated, please modify it to your needs// $this->abortIf('mysql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\'.'); // $this->addSql('CREATE TABLE admin (identifier CHAR(36) NOT NULL COMMENT \'(DC2Type:guid)\', PRIMARY KEY(identifier)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB'); @@ @@ // // public function down(Schema $schema) // { // - // this down() migration is auto-generated, please modify it to your needs $this->abortIf('mysql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\'.'); // $this->addSql('DROP TABLE admin'); // } // } // //
Configuration examples
// .php_cs.dist <?php $config = new PhpCsFixer\Config(); // ... $config->setRules( [ // ... 'PedroTroller/doctrine_migrations' => [ 'instanceof' => [ 'Doctrine\Migrations\AbstractMigration' ] ], // ... ] ); $config->registerCustomFixers(new PedroTroller\CS\Fixer\Fixers()); // ... return $config;
OR using my rule list builder.
// .php_cs.dist <?php $config = new PhpCsFixer\Config(); // ... $config->setRules( PedroTroller\CS\Fixer\RuleSetFactory::create() ->enable('PedroTroller/doctrine_migrations', [ 'instanceof' => [ 'Doctrine\Migrations\AbstractMigration' ] ]) ->getRules() ); $config->registerCustomFixers(new PedroTroller\CS\Fixer\Fixers()); // ... return $config;
Fixes
--- Original // 80 chars +++ New // @@ @@ // use Doctrine\DBAL\Schema\Schema; // use Doctrine\Migrations\AbstractMigration; // // -/** // - * Auto-generated Migration: Please modify to your needs! // - */ // final class Version20190323095102 extends AbstractMigration // { // - public function getDescription() // - { // - return ''; // - } // // public function up(Schema $schema) // { // - // this up() migration is auto-generated, please modify it to your needs// $this->abortIf('mysql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\'.'); // $this->addSql('CREATE TABLE admin (identifier CHAR(36) NOT NULL COMMENT \'(DC2Type:guid)\', PRIMARY KEY(identifier)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB'); @@ @@ // // public function down(Schema $schema) // { // - // this down() migration is auto-generated, please modify it to your needs $this->abortIf('mysql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\'.'); // $this->addSql('DROP TABLE admin'); // } // } // //
PedroTroller/phpspec
Phpspec scenario functions MUST NOT have a return type declaration.
Phpspec scenario functions MUST NOT have a scope.
The methods of the phpspec specification classes MUST BE sorted (let, letGo, its_, it_, getMatchers and the rest of the methods)
Lambda functions MUST NOT have a static scope.
Available options
instanceof(optional): Parent classes of your spec classes.- default:
PhpSpec\ObjectBehavior
- default:
Configuration examples
// .php_cs.dist <?php $config = new PhpCsFixer\Config(); // ... $config->setRules( [ // ... 'PedroTroller/phpspec' => true, // ... ] ); $config->registerCustomFixers(new PedroTroller\CS\Fixer\Fixers()); // ... return $config;
OR using my rule list builder.
// .php_cs.dist <?php $config = new PhpCsFixer\Config(); // ... $config->setRules( PedroTroller\CS\Fixer\RuleSetFactory::create() ->enable('PedroTroller/phpspec') ->getRules() ); $config->registerCustomFixers(new PedroTroller\CS\Fixer\Fixers()); // ... return $config;
Fixes
--- Original // 80 chars +++ New // @@ @@ // class TheSpec extends ObjectBehavior // { // // - function letGo($file) { // + function let($file) { // return; // } // // - private function thePrivateMethod() { // + function letGo($file) { // return; // } // // - public function itIsNotASpec($file) { // + function it_is_a_spec($file) { // return; // } // // - public function it_is_a_spec($file) { // + function its_other_function($file) { // return; // } // // - public function let($file) { // + private function thePrivateMethod() { // return; // } // // - public function its_other_function($file) { // + public function itIsNotASpec($file) { // return; // } // } // //
Configuration examples
// .php_cs.dist <?php $config = new PhpCsFixer\Config(); // ... $config->setRules( [ // ... 'PedroTroller/phpspec' => [ 'instanceof' => [ 'PhpSpec\ObjectBehavior' ] ], // ... ] ); $config->registerCustomFixers(new PedroTroller\CS\Fixer\Fixers()); // ... return $config;
OR using my rule list builder.
// .php_cs.dist <?php $config = new PhpCsFixer\Config(); // ... $config->setRules( PedroTroller\CS\Fixer\RuleSetFactory::create() ->enable('PedroTroller/phpspec', [ 'instanceof' => [ 'PhpSpec\ObjectBehavior' ] ]) ->getRules() ); $config->registerCustomFixers(new PedroTroller\CS\Fixer\Fixers()); // ... return $config;
Fixes
--- Original // 80 chars +++ New // @@ @@ // class TheSpec extends ObjectBehavior // { // // - function letGo($file) { // + function let($file) { // return; // } // // - private function thePrivateMethod() { // + function letGo($file) { // return; // } // // - public function itIsNotASpec($file) { // + function it_is_a_spec($file) { // return; // } // // - public function it_is_a_spec($file) { // + function its_other_function($file) { // return; // } // // - public function let($file) { // + private function thePrivateMethod() { // return; // } // // - public function its_other_function($file) { // + public function itIsNotASpec($file) { // return; // } // } // //
Contributions
Before to create a pull request to submit your contributon, you must:
- run tests and be sure nothing is broken
- rebuilt the documentation
How to run tests
composer tests
How to rebuild the documentation
bin/doc > README.md
Development with Docker
No local PHP is needed: everything runs in Docker through make. Requirements: Docker with Compose, and GNU make.
Run make to list the available commands:
help Show this help
test Run the test suite in a fresh image (PHP_VERSION=x.y, DEPENDENCIES=lowest)
stan Run PHPStan in a fresh image (PHP_VERSION=x.y, DEPENDENCIES=lowest)
readme Regenerate README.md from bin/doc.twig (FRESH=1 to re-resolve vendor)
readme-check Fail if README.md is not up to date (FRESH=1 to re-resolve vendor)
lint Check coding standards, dry run as in CI
fix Run rector-fix then cs-fix
cs-fix Fix coding standards in place
rector-fix Apply Rector refactorings in place
update-php Align the minimum PHP version with php.net, then run fix, readme and test
make test and make stan run in an image that contains the code and its dependencies, rebuilt on each call. The other commands work on your working copy, always on the minimum supported PHP version. That version is set once, in .env.
vendor/ is installed on your machine the first time, then again whenever composer.json changes. There is no lock file, so it can fall behind what CI resolves: make readme-check FRESH=1 (or rm -rf vendor) resolves the dependencies again before the check.
README.md is generated: edit bin/doc.twig, then run make readme.
Updating the minimum PHP version
The minimum PHP version follows the oldest PHP version php.net still supports, and CI fails when it falls behind. To update it:
- Fork the repository and clone your fork.
- Run
make update-php: it reads the supported versions from php.net, updatesPHP_MIN_VERSIONin.envand thephpconstraint incomposer.json, then runsmake fix,make readmeandmake test. - If
git statusshows changes, commit them and open a pull request with afeat:title (for examplefeat: drop support of php 8.2). If nothing changed, the minimum PHP version is already up to date.