diff --git a/README.md b/README.md index 5ad1b465..678d63c7 100644 --- a/README.md +++ b/README.md @@ -26,4 +26,232 @@ composer require symplify/easy-coding-standard --dev ## Rules Overview -- [Rules Overview](/docs/rules_overview.md) + +# 12 Rules Overview + +## ArrayListItemNewlineFixer + +Indexed PHP array item has to have one line per item + +- class: [`Symplify\CodingStandard\Fixer\ArrayNotation\ArrayListItemNewlineFixer`](../src/Fixer/ArrayNotation/ArrayListItemNewlineFixer.php) + +```diff +-$value = ['simple' => 1, 'easy' => 2]; ++$value = ['simple' => 1, ++'easy' => 2]; +``` + +
+ +## ArrayOpenerAndCloserNewlineFixer + +Indexed PHP array opener [ and closer ] must be on own line + +- class: [`Symplify\CodingStandard\Fixer\ArrayNotation\ArrayOpenerAndCloserNewlineFixer`](../src/Fixer/ArrayNotation/ArrayOpenerAndCloserNewlineFixer.php) + +```diff +-$items = [1 => 'Hey']; ++$items = [ ++1 => 'Hey' ++]; +``` + +
+ +## BlankLineAfterStrictTypesFixer + +Strict type declaration has to be followed by empty line + +- class: [`Symplify\CodingStandard\Fixer\Strict\BlankLineAfterStrictTypesFixer`](../src/Fixer/Strict/BlankLineAfterStrictTypesFixer.php) + +```diff + declare(strict_types=1); ++ + namespace App; +``` + +
+ +## LineLengthFixer + +Array items, method parameters, method call arguments, new arguments should be on same/standalone line to fit line length. + +:wrench: **configure it!** + +- class: [`Symplify\CodingStandard\Fixer\LineLength\LineLengthFixer`](../src/Fixer/LineLength/LineLengthFixer.php) + +```diff +-function some($veryLong, $superLong, $oneMoreTime) +-{ ++function some( ++ $veryLong, ++ $superLong, ++ $oneMoreTime ++) { + } + +-function another( +- $short, +- $now +-) { ++function another($short, $now) { + } +``` + +
+ +## MethodChainingNewlineFixer + +Each chain method call must be on own line + +- class: [`Symplify\CodingStandard\Fixer\Spacing\MethodChainingNewlineFixer`](../src/Fixer/Spacing/MethodChainingNewlineFixer.php) + +```diff +-$someClass->firstCall()->secondCall(); ++$someClass->firstCall() ++->secondCall(); +``` + +
+ +## ParamReturnAndVarTagMalformsFixer + +Fixes @param, @return, `@var` and inline `@var` annotations broken formats + +- class: [`Symplify\CodingStandard\Fixer\Commenting\ParamReturnAndVarTagMalformsFixer`](../src/Fixer/Commenting/ParamReturnAndVarTagMalformsFixer.php) + +```diff + /** +- * @param string ++ * @param string $name + */ + function getPerson($name) + { + } +``` + +
+ +## RemovePHPStormAnnotationFixer + +Remove "Created by PhpStorm" annotations + +- class: [`Symplify\CodingStandard\Fixer\Annotation\RemovePHPStormAnnotationFixer`](../src/Fixer/Annotation/RemovePHPStormAnnotationFixer.php) + +```diff +-/** +- * Created by PhpStorm. +- * User: ... +- * Date: 17/10/17 +- * Time: 8:50 AM +- */ + class SomeClass + { + } +``` + +
+ +## RemoveUselessDefaultCommentFixer + +Remove useless PHPStorm-generated `@todo` comments, redundant "Class XY" or "gets service" comments etc. + +- class: [`Symplify\CodingStandard\Fixer\Commenting\RemoveUselessDefaultCommentFixer`](../src/Fixer/Commenting/RemoveUselessDefaultCommentFixer.php) + +```diff +-/** +- * class SomeClass +- */ + class SomeClass + { +- /** +- * SomeClass Constructor. +- */ + public function __construct() + { +- // TODO: Change the autogenerated stub +- // TODO: Implement whatever() method. + } + } +``` + +
+ +## SpaceAfterCommaHereNowDocFixer + +Add space after nowdoc and heredoc keyword, to prevent bugs on PHP 7.2 and lower, see https://laravel-news.com/flexible-heredoc-and-nowdoc-coming-to-php-7-3 + +- class: [`Symplify\CodingStandard\Fixer\Spacing\SpaceAfterCommaHereNowDocFixer`](../src/Fixer/Spacing/SpaceAfterCommaHereNowDocFixer.php) + +```diff + $values = [ + << + +## StandaloneLineConstructorParamFixer + +Constructor param should be on a standalone line to ease git diffs on new dependency + +- class: [`Symplify\CodingStandard\Fixer\Spacing\StandaloneLineConstructorParamFixer`](../src/Fixer/Spacing/StandaloneLineConstructorParamFixer.php) + +```diff + final class PromotedProperties + { +- public function __construct(int $age, string $name) +- { ++ public function __construct( ++ int $age, ++ string $name ++ ) { + } + } +``` + +
+ +## StandaloneLineInMultilineArrayFixer + +Indexed arrays must have 1 item per line + +- class: [`Symplify\CodingStandard\Fixer\ArrayNotation\StandaloneLineInMultilineArrayFixer`](../src/Fixer/ArrayNotation/StandaloneLineInMultilineArrayFixer.php) + +```diff +-$friends = [1 => 'Peter', 2 => 'Paul']; ++$friends = [ ++ 1 => 'Peter', ++ 2 => 'Paul' ++]; +``` + +
+ +## StandaloneLinePromotedPropertyFixer + +Promoted property should be on standalone line + +- class: [`Symplify\CodingStandard\Fixer\Spacing\StandaloneLinePromotedPropertyFixer`](../src/Fixer/Spacing/StandaloneLinePromotedPropertyFixer.php) + +```diff + final class PromotedProperties + { +- public function __construct(public int $age, private string $name) +- { ++ public function __construct( ++ public int $age, ++ private string $name ++ ) { + } + } +``` + +
+ + diff --git a/composer.json b/composer.json index dee3ba20..26eafafd 100644 --- a/composer.json +++ b/composer.json @@ -5,17 +5,17 @@ "require": { "php": ">=8.2", "nette/utils": "^3.2", - "friendsofphp/php-cs-fixer": "^3.49", - "symplify/rule-doc-generator-contracts": "^11.1" + "friendsofphp/php-cs-fixer": "^3.59", + "symplify/rule-doc-generator-contracts": "^11.2" }, "require-dev": { - "symplify/easy-coding-standard": "^12.1", - "squizlabs/php_codesniffer": "^3.8.1", + "symplify/easy-coding-standard": "^12.3", + "squizlabs/php_codesniffer": "^3.10.1", "phpunit/phpunit": "^10.5", - "symplify/rule-doc-generator": "^12.0", - "phpstan/extension-installer": "^1.3", - "phpstan/phpstan": "^1.10.58", - "rector/rector": "^1.0", + "symplify/rule-doc-generator": "^12.2.2", + "phpstan/extension-installer": "^1.4", + "phpstan/phpstan": "^1.11", + "rector/rector": "^1.1", "symplify/phpstan-extensions": "^11.4", "tomasvotruba/class-leak": "^0.2", "tracy/tracy": "^2.10" diff --git a/phpstan.neon b/phpstan.neon index c9126f00..fab7d8d6 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -21,6 +21,9 @@ parameters: - '#Constant T_OPEN_CURLY_BRACKET|T_START_NOWDOC not found#' - '#Method Symplify\\CodingStandard\\TokenRunner\\Traverser\\ArrayBlockInfoFinder\:\:reverseTokens\(\) should return array but returns array#' + # unused generics + - '#Class (.*?) implements generic interface PhpCsFixer\\Fixer\\ConfigurableFixerInterface but does not specify its types\: TFixerInputConfig, TFixerComputedConfig#' + # false positive - message: '#Parameter \#1 \$sequence of method PhpCsFixer\\Tokenizer\\Tokens\:\:findSequence\(\) expects non\-empty\-array, array given#' diff --git a/tests/Issues/config/line_length_parentheses.php b/tests/Issues/config/line_length_parentheses.php index 124a20cd..a2cd1bd8 100644 --- a/tests/Issues/config/line_length_parentheses.php +++ b/tests/Issues/config/line_length_parentheses.php @@ -15,4 +15,4 @@ 'anonymous_class' => false, 'named_class' => false, ]); -}; \ No newline at end of file +};