From 0fe0f17ee95173666d9e83db8a5229bc9b0bbb7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Machulda?= Date: Mon, 6 May 2024 23:54:15 +0200 Subject: [PATCH] Feat: Add PhpdocAlignFixer (part of #94) --- ecs.php | 3 +++ tests/Integration/Fixtures/Basic.correct.php.inc | 13 +++++++++++++ tests/Integration/Fixtures/Basic.wrong.php.inc | 14 ++++++++++++++ 3 files changed, 30 insertions(+) diff --git a/ecs.php b/ecs.php index 1c4627e..4573c36 100644 --- a/ecs.php +++ b/ecs.php @@ -102,6 +102,7 @@ use PhpCsFixer\Fixer\Phpdoc\NoEmptyPhpdocFixer; use PhpCsFixer\Fixer\Phpdoc\NoSuperfluousPhpdocTagsFixer; use PhpCsFixer\Fixer\Phpdoc\PhpdocAddMissingParamAnnotationFixer; +use PhpCsFixer\Fixer\Phpdoc\PhpdocAlignFixer; use PhpCsFixer\Fixer\Phpdoc\PhpdocIndentFixer; use PhpCsFixer\Fixer\Phpdoc\PhpdocNoAccessFixer; use PhpCsFixer\Fixer\Phpdoc\PhpdocNoEmptyReturnFixer; @@ -499,6 +500,8 @@ 'allow_unused_params' => false, // whether param annotation without actual signature is allowed 'remove_inheritdoc' => true, // remove @inheritDoc tags ]) + // All items of the given PHPDoc tags must be left-aligned. + ->withConfiguredRule(PhpdocAlignFixer::class, ['align' => 'left']) // Order phpdoc tags by value. ->withConfiguredRule(PhpdocOrderByValueFixer::class, ['annotations' => ['covers', 'group', 'throws']]) // Calls to `PHPUnit\Framework\TestCase` static methods must all be of the same type (`$this->...`) diff --git a/tests/Integration/Fixtures/Basic.correct.php.inc b/tests/Integration/Fixtures/Basic.correct.php.inc index 660849a..53347a4 100644 --- a/tests/Integration/Fixtures/Basic.correct.php.inc +++ b/tests/Integration/Fixtures/Basic.correct.php.inc @@ -77,4 +77,17 @@ class Basic 'third' => 'bat', ]; } + + /** + * Very well documented method. + * It tests PhpdocAlignFixer, NoSuperfluousPhpdocTagsFixer and possibly other Phpdoc rules. + * @param int|float $second Second parameter does have a comment, unlike the first one. + * @param string|null $third Third parameter is optional and has a default value. + * @throws \Exception + * @return mixed There is also information about return type. + */ + public function veryWellDocumented(string $first, int|float $second, ?string $third = '3rd'): mixed + { + return $first . $third; + } } diff --git a/tests/Integration/Fixtures/Basic.wrong.php.inc b/tests/Integration/Fixtures/Basic.wrong.php.inc index fbe5470..3d1e53d 100644 --- a/tests/Integration/Fixtures/Basic.wrong.php.inc +++ b/tests/Integration/Fixtures/Basic.wrong.php.inc @@ -74,4 +74,18 @@ class Basic 'third' => 'bat', ]; } + + /** + * Very well documented method. + * It tests PhpdocAlignFixer, NoSuperfluousPhpdocTagsFixer and possibly other Phpdoc rules. + * @param string $first + * @throws \Exception + * @param int|float $second Second parameter does have a comment, unlike the first one. + * @param string|null $third Third parameter is optional and has a default value. + * @return mixed There is also information about return type. + */ + public function veryWellDocumented(string $first, int|float $second, ?string $third = '3rd'): mixed + { + return $first . $third; + } }