Skip to content

Commit 883e76c

Browse files
committed
Add the SetList class
1 parent aeb28f2 commit 883e76c

8 files changed

+95
-47
lines changed

README.md

+42-10
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ This package includes the [EasyCodingStandard][1] configuration for [Contao][2].
1010

1111
## Installation
1212

13-
You can install the package with Composer:
13+
Add the package to your Contao installation via Composer:
1414

15-
```
16-
composer require contao/easy-coding-standard
15+
```bash
16+
composer require contao/easy-coding-standard --dev
1717
```
1818

1919
## Usage
@@ -25,20 +25,52 @@ Create a file named `ecs.php` in the root directory of your project.
2525

2626
declare(strict_types=1);
2727

28+
use Contao\EasyCodingStandard\Set\SetList;
2829
use Symplify\EasyCodingStandard\Config\ECSConfig;
2930

30-
return static function (ECSConfig $ecsConfig): void {
31-
$ecsConfig->sets([__DIR__.'/vendor/contao/easy-coding-standard/config/contao.php']);
32-
31+
return ECSConfig::configure()
32+
->withSets([SetList::CONTAO])
3333
// Adjust the configuration according to your needs.
34-
};
34+
;
3535
```
3636

3737
Then run the script like this:
3838

39+
```bash
40+
vendor/bin/ecs check
3941
```
40-
vendor/bin/ecs check src tests
41-
```
42+
43+
## What's inside?
44+
45+
The package contains the following custom fixers:
46+
47+
| Class | Description |
48+
| --- | --- |
49+
| [`AssertEqualsFixer`](src/Fixer/AssertEqualsFixer.php) | Replaces `asserEquals()` with `assertSame()` in unit tests unless the method is used to compare two objects. |
50+
| [`CaseCommentIndentationFixer`](src/Fixer/CaseCommentIndentationFixer.php) | Fixes the comment indentation before a `case` statement. |
51+
| [`ChainedMethodBlockFixer`](src/Fixer/ChainedMethodBlockFixer.php) | Adds an empty line after a block of chained method calls. |
52+
| [`CommentLengthFixer`](src/Fixer/CommentLengthFixer.php) | Adjusts the length of comments regardless of their indentation so that each line is about 80 characters long. |
53+
| [`ExpectsWithCallbackFixer`](src/Fixer/ExpectsWithCallbackFixer.php) | Adjusts the indentation of `$this->callback()` calls inside the `with()` method of a unit test. |
54+
| [`FindByPkFixer`](src/Fixer/FindByPkFixer.php) | Replaces `findByPk()` calls with `findById()`. |
55+
| [`FunctionCallWithMultilineArrayFixer`](src/Fixer/FunctionCallWithMultilineArrayFixer.php) | Fixes the indentation of function calls with multi-line array arguments. |
56+
| [`InlinePhpdocCommentFixer`](src/Fixer/InlinePhpdocCommentFixer.php) | Ensures that inline phpDoc comments are not converted to regular comments. |
57+
| [`IsArrayNotEmptyFixer`](src/Fixer/IsArrayNotEmptyFixer.php) | Fixes the order of `isset()` and `empty()` calls in conjunction with `is_array()` checks. |
58+
| [`MockMethodChainingIndentationFixer`](src/Fixer/MockMethodChainingIndentationFixer.php) | Fixes the indentation of chained mock methods. |
59+
| [`MultiLineIfIndentationFixer`](src/Fixer/MultiLineIfIndentationFixer.php) | Fixes the indentation of multi-line if statements. |
60+
| [`MultiLineLambdaFunctionArgumentsFixer`](src/Fixer/MultiLineLambdaFunctionArgumentsFixer.php) | Fixes the indentation of multi-line lambda function arguments. |
61+
| [`NoExpectsThisAnyFixer`](src/Fixer/NoExpectsThisAnyFixer.php) | Removes the explicit `any()` assertion in unit tests. |
62+
| [`NoLineBreakBetweenMethodArgumentsFixer`](src/Fixer/NoLineBreakBetweenMethodArgumentsFixer.php) | Fixes the indentation of method declarations. |
63+
| [`NoSemicolonAfterShortEchoTagFixer`](src/Fixer/NoSemicolonAfterShortEchoTagFixer.php) | Removes the semicolon after short echo tag instructions. |
64+
| [`SingleLineConfigureCommandFixer`](src/Fixer/SingleLineConfigureCommandFixer.php) | Fixes the indentation of Symfony command arguments and options. |
65+
| [`TypeHintOrderFixer`](src/Fixer/TypeHintOrderFixer.php) | Fixes the type hint order in method declarations. |
66+
67+
The package contains the following custom sniffs:
68+
69+
| Class | Description |
70+
| --- | --- |
71+
| [`ContaoFrameworkClassAliasSniff`](src/Sniffs/ContaoFrameworkClassAliasSniff.php) | Prevents using aliased Contao classes instead of their originals. |
72+
| [`SetDefinitionCommandSniff`](src/Sniffs/SetDefinitionCommandSniff.php) | Prevents using the `setDefinition()` method in Symfony commands. |
73+
| [`UseSprintfInExceptionsSniff`](src/Sniffs/UseSprintfInExceptionsSniff.php) | Prevents using string interpolation in exception messages. |
4274

4375
## License
4476

@@ -50,4 +82,4 @@ Visit the [support page][3] to learn about the available support options.
5082

5183
[1]: https://github.com/Symplify/EasyCodingStandard
5284
[2]: https://contao.org
53-
[3]: https://contao.org/en/support.html
85+
[3]: https://to.contao.org/support

composer.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"symplify/easy-coding-standard": "^12.1"
1717
},
1818
"require-dev": {
19-
"contao/rector": "^1.0",
19+
"contao/rector": "^1.2",
2020
"phpunit/phpunit": "^9.5"
2121
},
2222
"autoload": {
@@ -37,11 +37,11 @@
3737
"scripts": {
3838
"all": [
3939
"@rector",
40-
"@cs-fixer",
40+
"@ecs",
4141
"@unit-tests"
4242
],
43-
"cs-fixer": "vendor/bin/ecs check config src tests --fix --ansi",
44-
"rector": "vendor/bin/rector --ansi",
45-
"unit-tests": "vendor/bin/phpunit --colors=always"
43+
"ecs": "vendor/bin/ecs check --fix",
44+
"rector": "vendor/bin/rector",
45+
"unit-tests": "vendor/bin/phpunit"
4646
}
4747
}

ecs.php

+17-1
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,30 @@
22

33
declare(strict_types=1);
44

5+
/*
6+
* This file is part of Contao.
7+
*
8+
* (c) Leo Feyer
9+
*
10+
* @license LGPL-3.0-or-later
11+
*/
12+
513
use Contao\EasyCodingStandard\Fixer\CommentLengthFixer;
614
use Contao\EasyCodingStandard\Fixer\FindByPkFixer;
15+
use Contao\EasyCodingStandard\Set\SetList;
716
use PhpCsFixer\Fixer\Comment\HeaderCommentFixer;
817
use SlevomatCodingStandard\Sniffs\Namespaces\ReferenceUsedNamesOnlySniff;
918
use Symplify\EasyCodingStandard\Config\ECSConfig;
1019

1120
return ECSConfig::configure()
12-
->withSets([__DIR__.'/config/contao.php'])
21+
->withSets([SetList::CONTAO])
22+
->withPaths([
23+
__DIR__.'/config',
24+
__DIR__.'/src',
25+
__DIR__.'/tests',
26+
__DIR__.'/ecs.php',
27+
__DIR__.'/rector.php',
28+
])
1329
->withSkip([
1430
CommentLengthFixer::class => [
1531
'config/contao.php',

phpunit.xml.dist

+9-15
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
3-
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
5-
colors="true"
6-
bootstrap="tests/bootstrap.php"
7-
>
8-
<php>
9-
<ini name="error_reporting" value="-1" />
10-
</php>
11-
12-
<testsuites>
13-
<testsuite name="contao/easy-coding-standard">
14-
<directory>./tests</directory>
15-
</testsuite>
16-
</testsuites>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd" colors="true" bootstrap="vendor/autoload.php">
3+
<php>
4+
<ini name="error_reporting" value="-1" />
5+
</php>
6+
<testsuites>
7+
<testsuite name="contao/easy-coding-standard">
8+
<directory>./tests</directory>
9+
</testsuite>
10+
</testsuites>
1711
</phpunit>

rector.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@
1010
* @license LGPL-3.0-or-later
1111
*/
1212

13+
use Contao\Rector\Set\SetList;
1314
use Rector\Config\RectorConfig;
1415

1516
return RectorConfig::configure()
16-
->withSets([__DIR__.'/vendor/contao/rector/config/contao.php'])
17+
->withSets([SetList::CONTAO])
1718
->withPaths([
1819
__DIR__.'/config',
1920
__DIR__.'/src',

src/Fixer/ExpectsWithCallbackFixer.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ public function isCandidate(Tokens $tokens): bool
7777
}
7878

7979
/**
80-
* Must run after MultiLineLambdaFunctionArgumentsFixer, MultilineWhitespaceBeforeSemicolonsFixer.
80+
* Must run after MultiLineLambdaFunctionArgumentsFixer,
81+
* MultilineWhitespaceBeforeSemicolonsFixer.
8182
*/
8283
public function getPriority(): int
8384
{

src/Set/SetList.php

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of Contao.
7+
*
8+
* (c) Leo Feyer
9+
*
10+
* @license LGPL-3.0-or-later
11+
*/
12+
13+
namespace Contao\EasyCodingStandard\Set;
14+
15+
final class SetList
16+
{
17+
public const CONTAO = __DIR__.'/../../config/contao.php';
18+
}

tests/bootstrap.php

-14
This file was deleted.

0 commit comments

Comments
 (0)