Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade everything to its newest version, use PSR-12, support PHP 8.3 #82

Merged
merged 2 commits into from
Apr 18, 2024
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
6 changes: 3 additions & 3 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ jobs:

strategy:
matrix:
php-version: ['7.3', '7.4', '8.0', '8.1']
php-version: ['8.0', '8.1', '8.2', '8.3']
dependencies: ['']
include:
- { php-version: '7.3', dependencies: '--prefer-lowest --prefer-stable' }
- { php-version: '8.0', dependencies: '--prefer-lowest --prefer-stable' }

name: PHP ${{ matrix.php-version }} ${{ matrix.dependencies }}

Expand Down Expand Up @@ -55,7 +55,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
php-version: '8.3'
extensions: mbstring, intl
tools: composer:v2

Expand Down
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
- Require PHP ^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
90 changes: 46 additions & 44 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/) 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 @@ -22,18 +22,27 @@ composer require --dev lmc/coding-standard
```php
<?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__ . '/vendor/lmc/coding-standard/ecs.php');

// Be default only checks compatible with PHP 7.3 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');
};
return ECSConfig::configure()
->withSets(
[
__DIR__ . '/vendor/lmc/coding-standard/ecs.php',
]
);

// 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 8.1, 8.2 and 8.3.


// 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).
//->withSets(
// [
// __DIR__ . '/vendor/lmc/coding-standard/ecs.php',
// __DIR__ . '/vendor/lmc/coding-standard/ecs-8.3.php',
// ]
//);
```

2. Run the check command (for `src/` and `tests/` directories):
Expand Down Expand Up @@ -71,21 +80,18 @@ Be aware you must add these settings **after** import of the base LMC code-style

use PHP_CodeSniffer\Standards\Generic\Sniffs\Files\LineLengthSniff;
use PhpCsFixer\Fixer\PhpUnit\PhpUnitTestAnnotationFixer;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

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

$services = $containerConfigurator->services();
use Symplify\EasyCodingStandard\Config\ECSConfig;

return ECSConfig::configure()
->withSets(
[
__DIR__ . '/vendor/lmc/coding-standard/ecs.php',
]
)
// Enforce line-length to 120 characters
$services->set(LineLengthSniff::class)
->property('absoluteLineLimit', 120);

->withConfiguredRule(LineLengthSniff::class, ['absoluteLineLimit' => 120])
// Tests must have @test annotation
$services->set(PhpUnitTestAnnotationFixer::class)
->call('configure', [['style' => 'annotation']]);
};
->withConfiguredRule(PhpUnitTestAnnotationFixer::class, ['style' => 'annotation']);
```

See [EasyCodingStandard docs](https://github.com/symplify/easy-coding-standard#configuration) for more configuration options.
Expand All @@ -102,28 +108,24 @@ Unlike adding/modifying checks, skips must be added **before** import of the bas

use PHP_CodeSniffer\Standards\Generic\Sniffs\PHP\ForbiddenFunctionsSniff;
use PHP_CodeSniffer\Standards\Squiz\Sniffs\Arrays\ArrayDeclarationSniff;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\EasyCodingStandard\ValueObject\Option;

return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();

$parameters->set(
Option::SKIP,
use Symplify\EasyCodingStandard\Config\ECSConfig;

return ECSConfig::configure()
->withSkip([
// Ignore specific check only in specific files
ForbiddenFunctionsSniff::class => [__DIR__ . '/src-tests/bootstrap.php'],
// Disable check entirely
ArrayDeclarationSniff::class,
// Skip one file
__DIR__ . '/file/to/be/skipped.php',
// Skip entire directory
__DIR__ . '/ignored/directory/*',
])
->withSets(
[
// Ignore specific check only in specific files
ForbiddenFunctionsSniff::class => [__DIR__ . '/src-tests/bootstrap.php'],
// Disable check entirely
ArrayDeclarationSniff::class,
// Skip one file
__DIR__ . '/file/to/be/skipped.php',
// Skip entire directory
__DIR__ . '/ignored/directory/*',
__DIR__ . '/vendor/lmc/coding-standard/ecs.php',
]
);

$containerConfigurator->import(__DIR__ . '/vendor/lmc/coding-standard/ecs.php');
};
```

See [EasyCodingStandard docs](https://github.com/symplify/easy-coding-standard#configuration) for more configuration options.
Expand Down
58 changes: 58 additions & 0 deletions UPGRADE-4.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# 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()`.
D0L1K marked this conversation as resolved.
Show resolved Hide resolved

See [ECS documentation](https://github.com/easy-coding-standard/easy-coding-standard/tree/main?tab=readme-ov-file#configure) for more configuration options
Examples of configurations can be seen [here](https://tomasvotruba.com/blog/new-in-ecs-simpler-config)

### 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).
17 changes: 8 additions & 9 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.4"
},
"require-dev": {
D0L1K marked this conversation as resolved.
Show resolved Hide resolved
"ergebnis/composer-normalize": "^2.13.2",
Expand All @@ -24,7 +24,7 @@
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan": "^1.3.0",
"phpstan/phpstan-phpunit": "^1.0.0",
"phpunit/phpunit": "^9.5.2"
"phpunit/phpunit": "^9.6.19"
},
"prefer-stable": true,
"autoload": {
Expand Down Expand Up @@ -55,16 +55,15 @@
"@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/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();
D0L1K marked this conversation as resolved.
Show resolved Hide resolved
Loading
Loading