Skip to content

Commit

Permalink
render docs directly to README
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Jun 28, 2024
1 parent af40328 commit 3be2f0e
Show file tree
Hide file tree
Showing 4 changed files with 241 additions and 10 deletions.
230 changes: 229 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,232 @@ composer require symplify/easy-coding-standard --dev

## Rules Overview

- [Rules Overview](/docs/rules_overview.md)
<!-- ruledoc-start -->
# 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];
```

<br>

## 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'
+];
```

<br>

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

<br>

## 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) {
}
```

<br>

## 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();
```

<br>

## 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)
{
}
```

<br>

## 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
{
}
```

<br>

## 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.
}
}
```

<br>

## 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 = [
<<<RECTIFY
Some content
-RECTIFY,
+RECTIFY
+,
1000
];
```

<br>

## 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
+ ) {
}
}
```

<br>

## 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'
+];
```

<br>

## 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
+ ) {
}
}
```

<br>

<!-- ruledoc-end -->
16 changes: 8 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 3 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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<PhpCsFixer\\Tokenizer\\Token> but returns array<int, PhpCsFixer\\Tokenizer\\Token\|null>#'

# 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<int, array\{0\: int, 1\?\: string\}\|PhpCsFixer\\Tokenizer\\Token\|string>, array<PhpCsFixer\\Tokenizer\\Token> given#'
Expand Down
2 changes: 1 addition & 1 deletion tests/Issues/config/line_length_parentheses.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
'anonymous_class' => false,
'named_class' => false,
]);
};
};

0 comments on commit 3be2f0e

Please sign in to comment.