Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kubawerlos/php-cs-fixer-custom-fixers
A set of custom fixers for PHP CS Fixer
https://github.com/kubawerlos/php-cs-fixer-custom-fixers
code-standards code-style php php-cs-fixer static-analysis
Last synced: 12 days ago
JSON representation
A set of custom fixers for PHP CS Fixer
- Host: GitHub
- URL: https://github.com/kubawerlos/php-cs-fixer-custom-fixers
- Owner: kubawerlos
- License: mit
- Created: 2018-05-21T20:06:07.000Z (over 6 years ago)
- Default Branch: main
- Last Pushed: 2024-10-12T11:16:37.000Z (about 1 month ago)
- Last Synced: 2024-10-14T11:09:23.628Z (29 days ago)
- Topics: code-standards, code-style, php, php-cs-fixer, static-analysis
- Language: PHP
- Homepage:
- Size: 2.38 MB
- Stars: 210
- Watchers: 7
- Forks: 19
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# PHP CS Fixer: custom fixers
[![Latest stable version](https://img.shields.io/packagist/v/kubawerlos/php-cs-fixer-custom-fixers.svg?label=current%20version)](https://packagist.org/packages/kubawerlos/php-cs-fixer-custom-fixers)
[![PHP version](https://img.shields.io/packagist/php-v/kubawerlos/php-cs-fixer-custom-fixers.svg)](https://php.net)
[![License](https://img.shields.io/github/license/kubawerlos/php-cs-fixer-custom-fixers.svg)](LICENSE)
![Tests](https://img.shields.io/badge/tests-3546-brightgreen.svg)
[![Downloads](https://img.shields.io/packagist/dt/kubawerlos/php-cs-fixer-custom-fixers.svg)](https://packagist.org/packages/kubawerlos/php-cs-fixer-custom-fixers)[![CI status](https://github.com/kubawerlos/php-cs-fixer-custom-fixers/actions/workflows/ci.yaml/badge.svg)](https://github.com/kubawerlos/php-cs-fixer-custom-fixers/actions/workflows/ci.yaml)
[![Code coverage](https://img.shields.io/coveralls/github/kubawerlos/php-cs-fixer-custom-fixers/main.svg)](https://coveralls.io/github/kubawerlos/php-cs-fixer-custom-fixers?branch=main)
[![Mutation testing badge](https://img.shields.io/endpoint?style=flat&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fkubawerlos%2Fphp-cs-fixer-custom-fixers%2Fmain)](https://dashboard.stryker-mutator.io/reports/github.com/kubawerlos/php-cs-fixer-custom-fixers/main)
[![Psalm type coverage](https://shepherd.dev/github/kubawerlos/php-cs-fixer-custom-fixers/coverage.svg)](https://shepherd.dev/github/kubawerlos/php-cs-fixer-custom-fixers)A set of custom fixers for [PHP CS Fixer](https://github.com/FriendsOfPHP/PHP-CS-Fixer).
## Installation
PHP CS Fixer: custom fixers can be installed by running:
```bash
composer require --dev kubawerlos/php-cs-fixer-custom-fixers
```## Usage
In your PHP CS Fixer configuration register fixers and use them:
```diff
registerCustomFixers(new PhpCsFixerCustomFixers\Fixers())
->setRules([
'@PSR2' => true,
'array_syntax' => ['syntax' => 'short'],
+ PhpCsFixerCustomFixers\Fixer\NoLeadingSlashInGlobalNamespaceFixer::name() => true,
+ PhpCsFixerCustomFixers\Fixer\PhpdocNoSuperfluousParamFixer::name() => true,
]);
```
:warning: When PHP CS Fixer is installed via [`php-cs-fixer/shim`](https://github.com/PHP-CS-Fixer/shim) package,
requiring bootstrap may be needed to load `PhpCsFixerCustomFixers` classes:
```php
require __DIR__ . '/vendor/kubawerlos/php-cs-fixer-custom-fixers/bootstrap.php';
```## Fixers
#### CommentSurroundedBySpacesFixer
Comments must be surrounded by spaces.
```diff
addSql("UPDATE t1 SET col1 = col1 + 1");
}
public function down(Schema $schema)
{
- // this down() migration is auto-generated, please modify it to your needs
$this->addSql("UPDATE t1 SET col1 = col1 - 1");
}
}
```#### NoDuplicatedArrayKeyFixer
There must be no duplicate array keys.
Configuration options:
- `ignore_expressions` (`bool`): whether to keep duplicated expressions (as they might return different values) or not; defaults to `true`
```diff
1,
"bar" => 2,
"foo" => 3,
];
```#### NoDuplicatedImportsFixer
There must be no duplicate `use` statements.
```diff
0;
+$isEmpty = $string === '';
+$isNotEmpty = $string !== '';
```#### NumericLiteralSeparatorFixer
Numeric literals must have configured separators.
DEPRECATED: use `numeric_literal_separator` instead.
Configuration options:
- `binary` (`bool`, `null`): whether add, remove or ignore separators in binary numbers.; defaults to `false`
- `decimal` (`bool`, `null`): whether add, remove or ignore separators in decimal numbers.; defaults to `false`
- `float` (`bool`, `null`): whether add, remove or ignore separators in float numbers.; defaults to `false`
- `hexadecimal` (`bool`, `null`): whether add, remove or ignore separators in hexadecimal numbers.; defaults to `false`
- `octal` (`bool`, `null`): whether add, remove or ignore separators in octal numbers.; defaults to `false`
```diff
markTestSkipped();
- return;
}
}
```#### PhpdocArrayStyleFixer
Generic array style should be used in PHPDoc.
DEPRECATED: use `phpdoc_array_type` instead.
```diff
*/
function foo() { return [1, 2]; }
```#### PhpdocNoIncorrectVarAnnotationFixer
The `@var` annotations must be used correctly in code.
```diff
+ * @param list
*/
function foo($x) {}
```#### PhpdocTypesCommaSpacesFixer
PHPDoc types commas must not be preceded by a whitespace, and must be succeeded by a single whitespace.
```diff
- */
+ */
```#### PhpdocTypesTrimFixer
PHPDoc types must be trimmed.
```diff
bar = $bar;
+ public function __construct(private string $bar) {
}
}
```#### ReadonlyPromotedPropertiesFixer
Promoted properties must be declared as read-only.
*Risky: when property is written.*
```diff
bar();
+$foo = new Foo();
+echo $foo->bar();
```#### SingleSpaceBeforeStatementFixer
Statements not preceded by a line break must be preceded by a single space.
```diff