Skip to content

Commit

Permalink
Feat: Add PhpdocAlignFixer (part of #94)
Browse files Browse the repository at this point in the history
  • Loading branch information
OndraM committed May 6, 2024
1 parent 75c1154 commit de4a9b3
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
3 changes: 3 additions & 0 deletions ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -497,6 +498,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->...`)
Expand Down
13 changes: 13 additions & 0 deletions tests/Integration/Fixtures/Basic.correct.php.inc
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,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;
}
}
14 changes: 14 additions & 0 deletions tests/Integration/Fixtures/Basic.wrong.php.inc
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,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;
}
}

0 comments on commit de4a9b3

Please sign in to comment.