Skip to content

Commit

Permalink
Upgrade everything to its newest version, use PSR-12
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Guth committed Apr 16, 2024
1 parent aadd000 commit f8c1b3a
Show file tree
Hide file tree
Showing 18 changed files with 515 additions and 595 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@
<!-- There is always Unreleased section on the top. Subsections (Added, Changed, Fixed, Removed) should be added as needed. -->

## Unreleased
- Lock PHP support to 8.0+
- Update to slevomat/coding-standard ^8.0
- Update to squizlabs/php_codesniffer ^3.9
- Update to symplify/easy-coding-standard ^12.1
- Move coding standard declarations from `ecs-7.4.php` and `ecs-8.0.php` to `ecs.php` and remove the former files
- Change deprecated rules to new ones
- Add new `ecs-8.2.php` coding standard declaration file for PHP 8.2+.
- Add new `ecs-8.3.php` coding standard declaration file for PHP 8.3+.

## 3.3.1 - 2022-05-23
- Lock `symplify/easy-coding-standard` to <10.2.4 because of backward incompatibilities introduced in its bugfix releases.
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

PHP coding standard used in [LMC](https://www.lmc.eu/en/) projects.

Standard is based on [PSR-2](https://www.php-fig.org/psr/psr-2/) and adds various checks to make sure the code is readable,
does follow the same conventions and does not contain common mistakes.
Standard is based on [PSR-12](https://www.php-fig.org/psr/psr-12/) (from version 4.0, before it was PSR-2) and adds
various checks to make sure the code is readable, does follow the same conventions and does not contain common mistakes.

We use [EasyCodingStandard] to define and execute checks created for both [PHP-CS-Fixer] and [PHP_CodeSniffer].

Expand All @@ -27,12 +27,12 @@ use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigura
return static function (ContainerConfigurator $containerConfigurator): void {
$containerConfigurator->import(__DIR__ . '/vendor/lmc/coding-standard/ecs.php');

// Be default only checks compatible with PHP 7.3 are enabled.
// Be default only checks compatible with PHP 8.0 are enabled.
// Depending on the lowest PHP version your project need to support, you can enable additional checks for PHP 7.4, 8.0 or 8.1.


// Import one of ecs-7.4.php, ecs-8.0.php or ecs-8.1.php. Use only one file (for the highest possible PHP version).
//$containerConfigurator->import(__DIR__ . '/vendor/lmc/coding-standard/ecs-7.4.php');
// Import one of ecs-8.1.php, ecs-8.2.php or ecs-8.3.php. Use only one file (for the highest possible PHP version).
//$containerConfigurator->import(__DIR__ . '/vendor/lmc/coding-standard/ecs-8.3.php');
};
```

Expand Down
57 changes: 57 additions & 0 deletions UPGRADE-4.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Upgrading from 3.x to 4.0

### 1. Update dependency in composer.json
In require-dev section change the version constraint:

```diff
- "lmc/coding-standard": "^3.3",
+ "lmc/coding-standard": "^4.0",
```

Then run `composer update`.

### 2. Configuration updates

Configuration now uses ECSConfig class instead of ContainerConfigurator. Update your `ecs.php` to use the new configuration style:

```diff
-use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
-
-return static function (ContainerConfigurator $containerConfigurator): void {
+use Symplify\EasyCodingStandard\Config\ECSConfig;
+
+return ECSConfig::configure()
```

Rules are now set using `ECSConfig::configure()->withRules([])` or `ECSConfig::configure()->withConfiguredRule()` instead of `$services->set()`.
Skiping tests is now done using `ECSConfig::configure()->withSkip()` instead of `$parameters->set(Option::SKIP, ...)`.
Imports are now done using `ECSConfig::configure()->withSets()` instead of `$containerConfigurator->import()`.

See [ECS documentation](https://github.com/easy-coding-standard/easy-coding-standard/tree/main?tab=readme-ov-file#configure) for more configuration options and examples.

### 3. Remove imports of `ecs-7.4.php` and/or `ecs-8.0.php` from your `ecs.php`
```diff
->withSets(__DIR__ . '/vendor/lmc/coding-standard/ecs.php')
- ->withSets(__DIR__ . '/vendor/lmc/coding-standard/ecs-7.4.php')
- ->withSets(__DIR__ . '/vendor/lmc/coding-standard/ecs-8.0.php')
->withSets(__DIR__ . '/vendor/lmc/coding-standard/ecs-8.1.php')
```

### 4. Sanity check
Besides running your code style checks, you can ensure all predefined LMC checks are loaded as well, by running:

```sh
vendor/bin/ecs list-checkers
```

The result should end with something like:
```
41 checkers from PHP_CodeSniffer:
...
147 checkers from PHP-CS-Fixer:
...
2 checkers are skipped:
...
```

(or some close number, depending on your custom code-style settings).
16 changes: 8 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
}
],
"require": {
"php": "^7.3 || ^8.0",
"php": "^8.0",
"friendsofphp/php-cs-fixer": "^3.0",
"nette/utils": "^3.2",
"slevomat/coding-standard": "^6.4.1 || ^7.0",
"squizlabs/php_codesniffer": "^3.6",
"symplify/easy-coding-standard": "^10.0 <10.2.4"
"slevomat/coding-standard": "^8.0",
"squizlabs/php_codesniffer": "^3.9",
"symplify/easy-coding-standard": "^12.1"
},
"require-dev": {
"ergebnis/composer-normalize": "^2.13.2",
Expand Down Expand Up @@ -54,16 +54,16 @@
"@test"
],
"analyze": [
"vendor/bin/ecs check src/ tests/ ecs.php ecs-7.4.php ecs-8.0.php ecs-8.1.php --ansi",
"vendor/bin/ecs check-markdown README.md --ansi",
"vendor/bin/ecs check src/ tests/ ecs.php ecs-8.1.php ecs-8.2.php ecs-8.3.php --ansi",
"vendor/bin/ecs check README.md --ansi",
"vendor/bin/phpstan analyze -c phpstan.neon --ansi"
],
"fix": [
"@composer normalize",
"vendor/bin/ecs check ./src/ ./tests/ ecs.php ecs-7.4.php ecs-8.0.php ecs-8.1.php --ansi --fix"
"vendor/bin/ecs check ./src/ ./tests/ ecs.php ecs-8.1.php ecs-8.2.php ecs-8.3.php --ansi --fix"
],
"lint": [
"vendor/bin/parallel-lint -j 10 -e php ./src ./tests ecs.php ecs-7.4.php ecs-8.0.php ecs-8.1.php",
"vendor/bin/parallel-lint -j 10 -e php ./src ./tests ecs.php ecs-8.1.php ecs-8.2.php ecs-8.3.php",
"@composer validate",
"@composer normalize --dry-run"
],
Expand Down
17 changes: 0 additions & 17 deletions ecs-7.4.php

This file was deleted.

93 changes: 0 additions & 93 deletions ecs-8.0.php

This file was deleted.

15 changes: 2 additions & 13 deletions ecs-8.1.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
<?php declare(strict_types=1);

use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\EasyCodingStandard\Config\ECSConfig;

return static function (ContainerConfigurator $containerConfigurator): void {
$containerConfigurator->import(__DIR__ . '/ecs-8.0.php');

// class with constants only -> enum
// @see https://www.php.net/releases/8.1/en.php#enumerations

// readonly properties
// @see https://www.php.net/releases/8.1/en.php#readonly_properties

// first-class callable
// @see https://www.php.net/releases/8.1/en.php#first_class_callable_syntax
};
return ECSConfig::configure();
6 changes: 6 additions & 0 deletions ecs-8.2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php declare(strict_types=1);

use Symplify\EasyCodingStandard\Config\ECSConfig;

return ECSConfig::configure()
->withSets([__DIR__ . '/ecs-8.1.php']);
6 changes: 6 additions & 0 deletions ecs-8.3.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php declare(strict_types=1);

use Symplify\EasyCodingStandard\Config\ECSConfig;

return ECSConfig::configure()
->withSets([__DIR__ . '/ecs-8.2.php']);
Loading

0 comments on commit f8c1b3a

Please sign in to comment.