Skip to content

Commit

Permalink
Add the SetList class
Browse files Browse the repository at this point in the history
  • Loading branch information
leofeyer committed Apr 4, 2024
1 parent aeb28f2 commit 883e76c
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 47 deletions.
52 changes: 42 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ This package includes the [EasyCodingStandard][1] configuration for [Contao][2].

## Installation

You can install the package with Composer:
Add the package to your Contao installation via Composer:

```
composer require contao/easy-coding-standard
```bash
composer require contao/easy-coding-standard --dev
```

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

declare(strict_types=1);

use Contao\EasyCodingStandard\Set\SetList;
use Symplify\EasyCodingStandard\Config\ECSConfig;

return static function (ECSConfig $ecsConfig): void {
$ecsConfig->sets([__DIR__.'/vendor/contao/easy-coding-standard/config/contao.php']);

return ECSConfig::configure()
->withSets([SetList::CONTAO])
// Adjust the configuration according to your needs.
};
;
```

Then run the script like this:

```bash
vendor/bin/ecs check
```
vendor/bin/ecs check src tests
```

## What's inside?

The package contains the following custom fixers:

| Class | Description |
| --- | --- |
| [`AssertEqualsFixer`](src/Fixer/AssertEqualsFixer.php) | Replaces `asserEquals()` with `assertSame()` in unit tests unless the method is used to compare two objects. |
| [`CaseCommentIndentationFixer`](src/Fixer/CaseCommentIndentationFixer.php) | Fixes the comment indentation before a `case` statement. |
| [`ChainedMethodBlockFixer`](src/Fixer/ChainedMethodBlockFixer.php) | Adds an empty line after a block of chained method calls. |
| [`CommentLengthFixer`](src/Fixer/CommentLengthFixer.php) | Adjusts the length of comments regardless of their indentation so that each line is about 80 characters long. |
| [`ExpectsWithCallbackFixer`](src/Fixer/ExpectsWithCallbackFixer.php) | Adjusts the indentation of `$this->callback()` calls inside the `with()` method of a unit test. |
| [`FindByPkFixer`](src/Fixer/FindByPkFixer.php) | Replaces `findByPk()` calls with `findById()`. |
| [`FunctionCallWithMultilineArrayFixer`](src/Fixer/FunctionCallWithMultilineArrayFixer.php) | Fixes the indentation of function calls with multi-line array arguments. |
| [`InlinePhpdocCommentFixer`](src/Fixer/InlinePhpdocCommentFixer.php) | Ensures that inline phpDoc comments are not converted to regular comments. |
| [`IsArrayNotEmptyFixer`](src/Fixer/IsArrayNotEmptyFixer.php) | Fixes the order of `isset()` and `empty()` calls in conjunction with `is_array()` checks. |
| [`MockMethodChainingIndentationFixer`](src/Fixer/MockMethodChainingIndentationFixer.php) | Fixes the indentation of chained mock methods. |
| [`MultiLineIfIndentationFixer`](src/Fixer/MultiLineIfIndentationFixer.php) | Fixes the indentation of multi-line if statements. |
| [`MultiLineLambdaFunctionArgumentsFixer`](src/Fixer/MultiLineLambdaFunctionArgumentsFixer.php) | Fixes the indentation of multi-line lambda function arguments. |
| [`NoExpectsThisAnyFixer`](src/Fixer/NoExpectsThisAnyFixer.php) | Removes the explicit `any()` assertion in unit tests. |
| [`NoLineBreakBetweenMethodArgumentsFixer`](src/Fixer/NoLineBreakBetweenMethodArgumentsFixer.php) | Fixes the indentation of method declarations. |
| [`NoSemicolonAfterShortEchoTagFixer`](src/Fixer/NoSemicolonAfterShortEchoTagFixer.php) | Removes the semicolon after short echo tag instructions. |
| [`SingleLineConfigureCommandFixer`](src/Fixer/SingleLineConfigureCommandFixer.php) | Fixes the indentation of Symfony command arguments and options. |
| [`TypeHintOrderFixer`](src/Fixer/TypeHintOrderFixer.php) | Fixes the type hint order in method declarations. |

The package contains the following custom sniffs:

| Class | Description |
| --- | --- |
| [`ContaoFrameworkClassAliasSniff`](src/Sniffs/ContaoFrameworkClassAliasSniff.php) | Prevents using aliased Contao classes instead of their originals. |
| [`SetDefinitionCommandSniff`](src/Sniffs/SetDefinitionCommandSniff.php) | Prevents using the `setDefinition()` method in Symfony commands. |
| [`UseSprintfInExceptionsSniff`](src/Sniffs/UseSprintfInExceptionsSniff.php) | Prevents using string interpolation in exception messages. |

## License

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

[1]: https://github.com/Symplify/EasyCodingStandard
[2]: https://contao.org
[3]: https://contao.org/en/support.html
[3]: https://to.contao.org/support
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"symplify/easy-coding-standard": "^12.1"
},
"require-dev": {
"contao/rector": "^1.0",
"contao/rector": "^1.2",
"phpunit/phpunit": "^9.5"
},
"autoload": {
Expand All @@ -37,11 +37,11 @@
"scripts": {
"all": [
"@rector",
"@cs-fixer",
"@ecs",
"@unit-tests"
],
"cs-fixer": "vendor/bin/ecs check config src tests --fix --ansi",
"rector": "vendor/bin/rector --ansi",
"unit-tests": "vendor/bin/phpunit --colors=always"
"ecs": "vendor/bin/ecs check --fix",
"rector": "vendor/bin/rector",
"unit-tests": "vendor/bin/phpunit"
}
}
18 changes: 17 additions & 1 deletion ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,30 @@

declare(strict_types=1);

/*
* This file is part of Contao.
*
* (c) Leo Feyer
*
* @license LGPL-3.0-or-later
*/

use Contao\EasyCodingStandard\Fixer\CommentLengthFixer;
use Contao\EasyCodingStandard\Fixer\FindByPkFixer;
use Contao\EasyCodingStandard\Set\SetList;
use PhpCsFixer\Fixer\Comment\HeaderCommentFixer;
use SlevomatCodingStandard\Sniffs\Namespaces\ReferenceUsedNamesOnlySniff;
use Symplify\EasyCodingStandard\Config\ECSConfig;

return ECSConfig::configure()
->withSets([__DIR__.'/config/contao.php'])
->withSets([SetList::CONTAO])
->withPaths([
__DIR__.'/config',
__DIR__.'/src',
__DIR__.'/tests',
__DIR__.'/ecs.php',
__DIR__.'/rector.php',
])
->withSkip([
CommentLengthFixer::class => [
'config/contao.php',
Expand Down
24 changes: 9 additions & 15 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
colors="true"
bootstrap="tests/bootstrap.php"
>
<php>
<ini name="error_reporting" value="-1" />
</php>

<testsuites>
<testsuite name="contao/easy-coding-standard">
<directory>./tests</directory>
</testsuite>
</testsuites>
<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">
<php>
<ini name="error_reporting" value="-1" />
</php>
<testsuites>
<testsuite name="contao/easy-coding-standard">
<directory>./tests</directory>
</testsuite>
</testsuites>
</phpunit>
3 changes: 2 additions & 1 deletion rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
* @license LGPL-3.0-or-later
*/

use Contao\Rector\Set\SetList;
use Rector\Config\RectorConfig;

return RectorConfig::configure()
->withSets([__DIR__.'/vendor/contao/rector/config/contao.php'])
->withSets([SetList::CONTAO])
->withPaths([
__DIR__.'/config',
__DIR__.'/src',
Expand Down
3 changes: 2 additions & 1 deletion src/Fixer/ExpectsWithCallbackFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ public function isCandidate(Tokens $tokens): bool
}

/**
* Must run after MultiLineLambdaFunctionArgumentsFixer, MultilineWhitespaceBeforeSemicolonsFixer.
* Must run after MultiLineLambdaFunctionArgumentsFixer,
* MultilineWhitespaceBeforeSemicolonsFixer.
*/
public function getPriority(): int
{
Expand Down
18 changes: 18 additions & 0 deletions src/Set/SetList.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

/*
* This file is part of Contao.
*
* (c) Leo Feyer
*
* @license LGPL-3.0-or-later
*/

namespace Contao\EasyCodingStandard\Set;

final class SetList
{
public const CONTAO = __DIR__.'/../../config/contao.php';
}
14 changes: 0 additions & 14 deletions tests/bootstrap.php

This file was deleted.

0 comments on commit 883e76c

Please sign in to comment.