Skip to content

Commit

Permalink
fixup! 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 f8c1b3a commit 9f52274
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 46 deletions.
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +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+
- 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+.
- 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
80 changes: 41 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

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

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
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;

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

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 7.4, 8.0 or 8.1.
// 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).
//$containerConfigurator->import(__DIR__ . '/vendor/lmc/coding-standard/ecs-8.3.php');
};
//->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
3 changes: 2 additions & 1 deletion UPGRADE-4.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ Rules are now set using `ECSConfig::configure()->withRules([])` or `ECSConfig::c
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.
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
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"nette/utils": "^3.2",
"slevomat/coding-standard": "^8.0",
"squizlabs/php_codesniffer": "^3.9",
"symplify/easy-coding-standard": "^12.1"
"symplify/easy-coding-standard": "^12.1.4"
},
"require-dev": {
"ergebnis/composer-normalize": "^2.13.2",
Expand Down
2 changes: 0 additions & 2 deletions ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -459,8 +459,6 @@
->withConfiguredRule(OperatorSpacingSniff::class, ['ignoreNewlines' => true])
// PHP arrays should be declared using the configured syntax
->withConfiguredRule(ArraySyntaxFixer::class, ['syntax' => 'short'])
// The body of each structure MUST be enclosed by braces. Braces should be properly placed
->withConfiguredRule(BracesFixer::class, ['allow_single_line_closure' => true, 'allow_single_line_anonymous_class_with_empty_body' => true])
// Class, trait and interface elements must be separated with one or none blank line
->withConfiguredRule(ClassAttributesSeparationFixer::class, ['elements' => ['method' => 'one']])
// Visibility MUST be declared on all properties, methods and class constants
Expand Down

0 comments on commit 9f52274

Please sign in to comment.