Skip to content
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
composer.lock
vendor
/.idea
48 changes: 46 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,52 @@
# Changelog

## v2.0.0 - December 2024

## [Unreleased] - 2024-05-21
This version is a major release and includes breaking changes.
Adjust your configuration, apply the fixes and review code for the new version.

### PER Coding Style 2.0
PER Coding Style 2.0 (https://www.php-fig.org/per/coding-style/) was introduced.
This leads to some adjustments in the code which most probably can be autofixed with `ecs check --fix`.
Review your code after running the fixer.

Rules applied to the set can be found here: https://cs.symfony.com/doc/ruleSets/PER-CS2.0.html. This is the base from which we make our own small adjustments.
"Concat Space" for example, is a rule which has already been applied to the Symfony rule set in the past, which we enforce in the standard everywhere.

### Unify rule sets
Removed `whatwedo-wordpress.php` and `whatwedo-symfony.php` in favor of `whatwedo-common.php`. If you have used `whatwedo-symfony.php` or `whatwedo-wordpress.php`, you have to switch to `whatwedo-common.php` in the config.

### Update ECS Configuration
Update your configuration (`ecs.php`) to the new version and adjust to your preferences. See our example file in the root of this repository.

### Enforce types via PHP instead of DocBlocks
`PhpdocToReturnTypeFixer` and `PhpdocToParamTypeFixer` will enforce the types in the PHP code instead of the DocBlocks.
If you don't use PHPStan or similar for static type checking, that could be a problem for you since those types can be wrong. You can disable these fixers in your local configuration if you can't migrate them properly for now.

## Technical

### Changed
- Unify rule sets (https://github.com/whatwedo/PhpCodingStandard/issues/17)
- Minor update to `symplify/easy-coding-standard 12.4`

### Added
- DynamicSet `@PER-CS2.0` was added to the configuration (https://github.com/whatwedo/PhpCodingStandard/issues/19)
- Add `MultilinePromotedPropertiesFixer` (https://github.com/whatwedo/PhpCodingStandard/issues/27)
- Add `MultilinePromotedPropertiesFixer` (https://github.com/whatwedo/PhpCodingStandard/issues/27)
- Add `PhpdocToReturnTypeFixer` and `PhpdocToParamTypeFixer`
- `NoDoctrineMigrationsGeneratedCommentFixer` is now part of the default configuration (https://github.com/whatwedo/PhpCodingStandard/issues/16)
- `ConcatSpaceFixer` => `'spacing' => 'one'` was added (https://github.com/whatwedo/PhpCodingStandard/issues/15)

### Removed
- Remove deprecated `NoTrailingCommaInListCallFixer`
- `ConcatSpaceFixer` => `'spacing' => 'none'` was replaced with `'spacing' => 'one'` for projects with the Symfony rule set in place
- `AssignmentInConditionSniff` is skipped

---

## v1.2.5 - March 2024

### Changed

- update to `symplify/easy-coding-standard ^12`
- Update to `symplify/easy-coding-standard ^12`
- Dump Fixer added
23 changes: 14 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# 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).
It's based on PER Coding Style 2.0 (https://www.php-fig.org/per/coding-style/).

## Installation

Expand All @@ -20,26 +21,24 @@ composer require whatwedo/php-coding-standard
You can run the checks without project specific configuration using one of following commands:

```
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
vendor/bin/ecs check SRC_DIRECTORY --config vendor/whatwedo/php-coding-standard/config/whatwedo-common.php
```


### With custom configuration

If you want to add additional checkers or exclude files, you have to create an `ecs.php` file in your own project root directory.
But we suggest to create an `ecs.php` file in your own project root directory.
There's a sample configuration file in the root of this repository.

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

use Symplify\EasyCodingStandard\Config\ECSConfig;

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

// Explicitly remove some rules in a specific files
Expand All @@ -50,7 +49,7 @@ return static function (ECSConfig $ecsConfig): void {
*/

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

Expand All @@ -72,6 +71,12 @@ For other configuration options, check out [Simplify/EasyCodingStandard](https:/
* [kubawerlos/php-cs-fixer-custom-fixers](https://github.com/kubawerlos/php-cs-fixer-custom-fixers)
* [slevomat/coding-standard](https://github.com/slevomat/coding-standard)

## Contributing

Feel free to contribute to this project. We are always open for suggestions and improvements.

Don't forget to check adjustments within this project with the coding standards as well.
Run `make ecs` to check for coding standard violations and fix them.

## License

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
"require": {
"php": ">=7.4",
"kubawerlos/php-cs-fixer-custom-fixers": "^3.0",
"slevomat/coding-standard": "^8.5",
"symplify/easy-coding-standard": "^12.1"
"slevomat/coding-standard": "^8.15",
"symplify/easy-coding-standard": "^12.4"
},
"autoload": {
"psr-4": {
Expand Down
19 changes: 15 additions & 4 deletions config/whatwedo-common.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
use PhpCsFixer\Fixer\CastNotation\CastSpacesFixer;
use PhpCsFixer\Fixer\ClassNotation\FinalInternalClassFixer;
use PhpCsFixer\Fixer\ClassNotation\OrderedClassElementsFixer;
use PhpCsFixer\Fixer\ControlStructure\NoTrailingCommaInListCallFixer;
use PhpCsFixer\Fixer\ControlStructure\YodaStyleFixer;
use PhpCsFixer\Fixer\FunctionNotation\PhpdocToParamTypeFixer;
use PhpCsFixer\Fixer\FunctionNotation\PhpdocToReturnTypeFixer;
use PhpCsFixer\Fixer\LanguageConstruct\IsNullFixer;
use PhpCsFixer\Fixer\NamespaceNotation\BlankLineAfterNamespaceFixer;
use PhpCsFixer\Fixer\Operator\ConcatSpaceFixer;
use PhpCsFixer\Fixer\Operator\IncrementStyleFixer;
use PhpCsFixer\Fixer\Operator\NotOperatorWithSuccessorSpaceFixer;
use PhpCsFixer\Fixer\Operator\OperatorLinebreakFixer;
Expand All @@ -36,6 +38,8 @@
use PhpCsFixer\Fixer\Whitespace\BlankLineBeforeStatementFixer;
use PhpCsFixer\Fixer\Whitespace\MethodChainingIndentationFixer;
use PhpCsFixer\Fixer\Whitespace\NoExtraBlankLinesFixer;
use PhpCsFixerCustomFixers\Fixer\MultilinePromotedPropertiesFixer;
use PhpCsFixerCustomFixers\Fixer\NoDoctrineMigrationsGeneratedCommentFixer;
use PhpCsFixerCustomFixers\Fixer\NoImportFromGlobalNamespaceFixer;
use PhpCsFixerCustomFixers\Fixer\NoNullableBooleanTypeFixer;
use PhpCsFixerCustomFixers\Fixer\NoPhpStormGeneratedCommentFixer;
Expand All @@ -55,6 +59,7 @@
$ecsConfig->sets([SetList::CLEAN_CODE]);
$ecsConfig->sets([SetList::COMMON]);
$ecsConfig->sets([SetList::PSR_12]);
$ecsConfig->dynamicSets(['@PER-CS2.0']);

$ecsConfig->rule(ValidClassNameSniff::class);
$ecsConfig->rule(ClassCommentSniff::class);
Expand Down Expand Up @@ -84,23 +89,29 @@
$ecsConfig->rule(PhpdocSelfAccessorFixer::class);
$ecsConfig->rule(PhpdocVarAnnotationCorrectOrderFixer::class);
$ecsConfig->rule(ForbiddenAnnotationsSniff::class);
$ecsConfig->rule(AssignmentInConditionSniff::class);
$ecsConfig->rule(DeadCatchSniff::class);
$ecsConfig->rule(UseFromSameNamespaceSniff::class);
$ecsConfig->rule(MultilinePromotedPropertiesFixer::class);
$ecsConfig->rule(DumpFixer::class);

$ecsConfig->ruleWithConfiguration(OperatorLinebreakFixer::class, [
'only_booleans' => true,
'position' => 'beginning',
]);
$ecsConfig->rule(PhpdocToReturnTypeFixer::class);
$ecsConfig->rule(PhpdocToParamTypeFixer::class);
$ecsConfig->rule(NoDoctrineMigrationsGeneratedCommentFixer::class);

// https://github.com/whatwedo/PhpCodingStandard/issues/15
$ecsConfig->ruleWithConfiguration(ConcatSpaceFixer::class, [
'spacing' => 'one',
]);

$ecsConfig->skip([
AssignmentInConditionSniff::class => null,
InlineControlStructureSniff::class => null,
ScopeIndentSniff::class => null,
ScopeClosingBraceSniff::class => null,
CastSpacesFixer::class => null,
NoTrailingCommaInListCallFixer::class => null,
YodaStyleFixer::class => null,
IsNullFixer::class => null,
BlankLineAfterNamespaceFixer::class => null,
Expand Down
15 changes: 0 additions & 15 deletions config/whatwedo-symfony.php

This file was deleted.

9 changes: 0 additions & 9 deletions config/whatwedo-wordpress.php

This file was deleted.

14 changes: 14 additions & 0 deletions ecs.example.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

declare(strict_types=1);

use Symplify\EasyCodingStandard\Config\ECSConfig;

return static function (ECSConfig $config): void {
$config->paths([
'src',
'tests',
]);
$config->skip([]);
$config->import('vendor/whatwedo/php-coding-standard/config/whatwedo-common.php');
};
4 changes: 4 additions & 0 deletions ecs.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<?php

/*
* This file is used to check the coding standards itself in this project.
*/

declare(strict_types=1);

use Symplify\EasyCodingStandard\Config\ECSConfig;
Expand Down
16 changes: 0 additions & 16 deletions ecs.php.symfony.dist

This file was deleted.

2 changes: 1 addition & 1 deletion src/Fixer/DumpFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function getDefinition(): FixerDefinitionInterface
{
return new FixerDefinition(
'Removes dump/var_dump statements, which shouldn\'t be in production ever.',
[new CodeSample("<?php\nvar_dump(false);")]
[new CodeSample("<?php\nvar_dump(false);")],
);
}

Expand Down