/easy-coding-standard

EasyCodingStandard configurations for Contao

Primary LanguagePHP

EasyCodingStandard configurations for Contao

This package includes the EasyCodingStandard configuration for Contao.

Installation

Add the package to your Contao installation via Composer:

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

Usage

Create a file named ecs.php in the root directory of your project.

<?php

declare(strict_types=1);

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

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

Then run the script like this:

vendor/bin/ecs check

What's inside?

The package contains the following custom fixers:

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

The package contains the following custom sniffs:

Class Description
ContaoFrameworkClassAliasSniff Prevents using aliased Contao classes instead of their originals.
SetDefinitionCommandSniff Prevents using the setDefinition() method in Symfony commands.
UseSprintfInExceptionsSniff Prevents using string interpolation in exception messages.

License

Contao is licensed under the terms of the LGPLv3.

Getting support

Visit the support page to learn about the available support options.