Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/workflows/ecs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: ECS

on:
push:
branches: [main]
pull_request:

permissions:
contents: read

jobs:
ecs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5

- uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
tools: composer:v2
coverage: none

- uses: ramsey/composer-install@v3

- run: make ecs

# make ecs applies its fixes, so a dirty working tree means the code was not formatted
- run: git diff --exit-code
83 changes: 82 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,88 @@
# Changelog


## [Unreleased] - 2024-05-21
## [Unreleased]

### Added

- `WhatwedoSets::COMMON`, `::SYMFONY` and `::WORDPRESS` carry the paths to the shipped
sets, so an `ecs.php` references a class constant instead of spelling out
`vendor/whatwedo/php-coding-standard/config/whatwedo-*.php` by hand — passing the file
path keeps working

### Changed

- nine skips and one narrowing configuration are gone, so the rules they held back
now apply as the sets intend: casts are spaced (`(int) $x`), comparisons drop the Yoda
order (`$x === null`, and an existing `null === $x` is rewritten), `$i ++` becomes
`$i++`, broken PHPDoc inline tags are normalised (`@{TAG}` to `{@TAG}`), `@return null`
and `@subpackage` are dropped, a blank line follows the `namespace` statement, and
every operator in a multiline expression moves to the beginning of the continuation
line instead of only `&&` and `||`.
Two of the overrides said nothing to begin with: the skip on `NoExtraBlankLinesFixer`
had no effect, because `PER_CS` narrows that fixer to blank lines between imports and
`NoBlankLineBetweenImportsFixer` already removes those, and the `position` set next to
`only_booleans` was the php-cs-fixer default
- build every set on `SetList::PER_CS`, the PER Coding Style 3.0 successor of PSR-12,
instead of `SetList::PSR_12` — the first run reformats existing code, most visibly by
adding a trailing comma to multiline argument and parameter lists, and further by `fn()`
spacing, `?int` type formatting, `Foo::bar` spacing and single-line empty bodies. Imports
keep being sorted alphabetically and `declare()` parentheses keep being checked, both of
which the PER-CS set leaves to the caller
- the line breaks and the indentation of a method chain are left to the author:
`MethodChainingNewlineFixer` and `MethodChainingIndentationFixer`, which the ECS 13
sets bring along, are skipped, so a short `$this->foo()->bar()` stays on one line
instead of being split into one call per line, and a deliberately wrapped builder
chain keeps its own breaks and indentation
- the Symfony set adds `SetList::DOCTRINE_ANNOTATIONS`, so the indentation, spacing and
array assignments inside Doctrine annotations are formatted — the first run reformats
projects that still carry mapping or validation in docblocks rather than attributes
- drop `SetList::CLEAN_CODE` (imported by `SetList::COMMON` in full) and 17 skips that
targeted rules no longer shipped by any ECS 13 set; the effective checker list is
unchanged
- require PHP 8.2 or newer, up from 7.4. The dependencies still install on 7.4, so this
is a floor set on purpose: the standard is only run and verified on PHP versions that
still receive security support
- update to `symplify/easy-coding-standard ^13.3.2`, which bundles php-cs-fixer 3.95 and
PHP_CodeSniffer 4 — running the whatwedo standard can report additional findings on
code that passed under ECS 12
- allow `kubawerlos/php-cs-fixer-custom-fixers ^3` and `slevomat/coding-standard ^8`
again, the version caps ECS 12 needed are no longer required

### Removed

- the two Squiz commenting sniffs are gone, so `@throws` tags and the style of class
docblocks are no longer checked. `FunctionCommentThrowTagSniff` reads a single method
body and demands a tag for every `throw` it finds there, which on typed code is noisier
and less accurate than PHPStan, who follows the call chain. `ClassCommentSniff` was
registered with its `.Missing` code skipped, so it never asked for a docblock in the
first place and only policed the shape of the ones that exist

### Fixed

- the file header keeps its own copyright. `FileCommentSniff` is hardcoded to Squiz
Pty Ltd: `ecs --fix` rewrote `@copyright 2026 whatwedo GmbH` to
`@copyright 2026 Squiz Pty Ltd (ABN 77 084 670 600)` and asked for
`@author Squiz Pty Ltd <products@squiz.net>`. A file carrying a `/** */` header also
never converged, because the sniff went on reporting `MissingPackageTag`,
`MissingSubpackageTag`, `PackageTagOrder` and `SpacingAfterOpen`, none of them fixable

- `?bool` parameter and return types keep their nullability. `NoNullableBooleanTypeFixer`
is a risky fixer that rewrites `?bool` to `bool` without touching the body, so
`ecs --fix` turned working tri-state code into a `TypeError` at the next call with
`null`. ECS applies risky fixers unconditionally, it has no `--allow-risky` gate, so
the rule is gone instead of being switched off

- enum cases stay at the top of the enum. The element order configured for
`OrderedClassElementsFixer` never listed `case`, and every type the list omits is
sorted to the end, so `ecs --fix` moved the cases of a correctly written enum below
its methods. The own order is gone entirely rather than patched: `PER_CS` configures
the fixer as `order => ['use_trait']`, which sorts trait imports to the top and leaves
every other element where it stands. The cost is that the order of properties,
constants and methods is no longer enforced — only trait imports are
Comment thread
rugbymauri marked this conversation as resolved.
Resolved


## [1.3.0] - 2024-05-21

### Changed

Expand Down
56 changes: 25 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,62 +2,56 @@

# PhpCodingStandard

This project is a set of coding standard rules, which we are using at [whatwedo](https://whatwedo.ch). It's heavily based on [Simplify/EasyCodingStandard](https://github.com/Symplify/EasyCodingStandard).
This project is a set of coding standard rules, which we are using at [whatwedo](https://whatwedo.ch). It's heavily based on
[Simplify/EasyCodingStandard](https://github.com/Symplify/EasyCodingStandard).

## Installation

We suggest to use Composer to install this project:

```
composer require whatwedo/php-coding-standard
composer require --dev whatwedo/php-coding-standard
```


## Usage

### Without custom configuration
You have to create an `ecs.php` file in your own project root directory and reference the set matching your
project type:

You can run the checks without project specific configuration using one of following commands:
* Symfony projects: `WhatwedoSets::SYMFONY`
* WordPress projects: `WhatwedoSets::WORDPRESS`
* Any other PHP project: `WhatwedoSets::COMMON`

```
vendor/bin/ecs check SRC_DIRECTORY --config vendor/whatwedo/php-coding-standard/config/whatwedo-symfony.php # Symfony projects
vendor/bin/ecs check SRC_DIRECTORY --config vendor/whatwedo/php-coding-standard/config/whatwedo-wordpress.php # WordPress projects
vendor/bin/ecs check SRC_DIRECTORY --config vendor/whatwedo/php-coding-standard/config/whatwedo-common.php # Common PHP projects
```


### With custom configuration
The Symfony and the WordPress set both include the common set, so there is no need to reference more than one.

If you want to add additional checkers or exclude files, you have to create an `ecs.php` file in your own project root directory.
Every set builds on [PER Coding Style 3.0](https://www.php-fig.org/per/coding-style/), the successor of
PSR-12. Coming from an older release, expect the first run to reformat existing code, most visibly by
adding a trailing comma to multiline argument and parameter lists. Imports keep being sorted
alphabetically, which PER-CS leaves open.

```php
<?php
declare(strict_types=1);

use Symplify\EasyCodingStandard\Config\ECSConfig;

return static function (ECSConfig $ecsConfig): void {
/*
// Remove rules with $ecsConfig->skip()
$ecsConfig->skip([
SlevomatCodingStandard\Sniffs\Variables\UnusedVariableSniff::class => null,

// Explicitly remove some rules in a specific files
PhpCsFixer\Fixer\FunctionNotation\MethodArgumentSpaceFixer::class => [
__DIR__ . '/PATH/FILE.php'
],
use whatwedo\PhpCodingStandard\Set\WhatwedoSets;

return ECSConfig::configure()
->withPaths([
__DIR__ . '/src',
__DIR__ . '/tests',
])
->withSets([
// Symfony project, see the list above for WordPress and plain PHP projects
WhatwedoSets::SYMFONY,
]);
*/

// This need to come last
$ecsConfig->sets([__DIR__ . '/vendor/whatwedo/php-coding-standard/config/whatwedo-common.php']);
};
```

Then run the following command:

```
vendor/bin/ecs check SRC_DIRECTORY
vendor/bin/ecs check
```

To fix certain issues automatically add `--fix` add the end
Expand All @@ -67,7 +61,7 @@ For other configuration options, check out [Simplify/EasyCodingStandard](https:/

## Dependencies

* PHP >=7.4
* PHP >=8.2
* [Simplify/EasyCodingStandard](https://github.com/Symplify/EasyCodingStandard)
* [kubawerlos/php-cs-fixer-custom-fixers](https://github.com/kubawerlos/php-cs-fixer-custom-fixers)
* [slevomat/coding-standard](https://github.com/slevomat/coding-standard)
Expand Down
20 changes: 6 additions & 14 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,15 @@
"homepage": "https://github.com/whatwedo/PhpCodingStandard",
"authors": [
{
"name": "Felix Imobersteg",
"email": "felix@whatwedo.ch"
},
{
"name": "Marc Wieland",
"email": "marc@whatwedo.ch"
},
{
"name": "Maurizio Monticelli",
"email": "maurizio@whatwedo.ch"
"name": "whatwedo GmbH",
"email": "welove@whatwedo.ch"
}
Comment thread
rugbymauri marked this conversation as resolved.
Resolved
],
"require": {
"php": ">=7.4",
"kubawerlos/php-cs-fixer-custom-fixers": ">=3.32,<3.37.3",
"slevomat/coding-standard": "~8.22.1",
"symplify/easy-coding-standard": "^12.5.23"
"php": ">=8.2",
"kubawerlos/php-cs-fixer-custom-fixers": "^3",
"slevomat/coding-standard": "^8",
"symplify/easy-coding-standard": "^13.3.2"
Comment thread
rugbymauri marked this conversation as resolved.
Resolved
Comment thread
rugbymauri marked this conversation as resolved.
Resolved
},
"autoload": {
"psr-4": {
Expand Down
Loading
Loading