Rule phpdoc_align
¶
All items of the given PHPDoc tags must be either left-aligned or (by default) aligned vertically.
Configuration¶
align
¶
How comments should be aligned.
Allowed values: 'left'
and 'vertical'
Default value: 'vertical'
spacing
¶
Spacing between tag, hint, comment, signature, etc. You can set same spacing for
all tags using a positive integer or different spacings for different tags using
an associative array of positive integers ['tagA' => spacingForA, 'tagB' =>
spacingForB]
. If you want to define default spacing to more than 1 space use
_default
key in config array, e.g.: ['tagA' => spacingForA, 'tagB' =>
spacingForB, '_default' => spacingForAllOthers]
.
Allowed types: int
and array<string, int>
Default value: 1
Examples¶
Example #1¶
Default configuration.
--- Original
+++ New
<?php
/**
- * @param EngineInterface $templating
- * @param string $format
- * @param int $code an HTTP response status code
- * @param bool $debug
- * @param mixed &$reference a parameter passed by reference
+ * @param EngineInterface $templating
+ * @param string $format
+ * @param int $code an HTTP response status code
+ * @param bool $debug
+ * @param mixed &$reference a parameter passed by reference
*
* @return Foo description foo
*
- * @throws Foo description foo
+ * @throws Foo description foo
* description foo
*
*/
Example #2¶
With configuration: ['align' => 'vertical']
.
--- Original
+++ New
<?php
/**
- * @param EngineInterface $templating
- * @param string $format
- * @param int $code an HTTP response status code
- * @param bool $debug
- * @param mixed &$reference a parameter passed by reference
+ * @param EngineInterface $templating
+ * @param string $format
+ * @param int $code an HTTP response status code
+ * @param bool $debug
+ * @param mixed &$reference a parameter passed by reference
*
* @return Foo description foo
*
- * @throws Foo description foo
+ * @throws Foo description foo
* description foo
*
*/
Example #3¶
With configuration: ['align' => 'left']
.
--- Original
+++ New
<?php
/**
- * @param EngineInterface $templating
- * @param string $format
- * @param int $code an HTTP response status code
- * @param bool $debug
- * @param mixed &$reference a parameter passed by reference
+ * @param EngineInterface $templating
+ * @param string $format
+ * @param int $code an HTTP response status code
+ * @param bool $debug
+ * @param mixed &$reference a parameter passed by reference
*
* @return Foo description foo
*
- * @throws Foo description foo
+ * @throws Foo description foo
* description foo
*
*/
Example #4¶
With configuration: ['align' => 'left', 'spacing' => 2]
.
--- Original
+++ New
<?php
/**
- * @param EngineInterface $templating
- * @param string $format
- * @param int $code an HTTP response status code
- * @param bool $debug
- * @param mixed &$reference a parameter passed by reference
+ * @param EngineInterface $templating
+ * @param string $format
+ * @param int $code an HTTP response status code
+ * @param bool $debug
+ * @param mixed &$reference a parameter passed by reference
*
- * @return Foo description foo
+ * @return Foo description foo
*
- * @throws Foo description foo
- * description foo
+ * @throws Foo description foo
+ * description foo
*
*/
Example #5¶
With configuration: ['align' => 'left', 'spacing' => ['param' => 2]]
.
--- Original
+++ New
<?php
/**
- * @param EngineInterface $templating
- * @param string $format
- * @param int $code an HTTP response status code
- * @param bool $debug
- * @param mixed &$reference a parameter passed by reference
+ * @param EngineInterface $templating
+ * @param string $format
+ * @param int $code an HTTP response status code
+ * @param bool $debug
+ * @param mixed &$reference a parameter passed by reference
*
* @return Foo description foo
*
- * @throws Foo description foo
+ * @throws Foo description foo
* description foo
*
*/
Rule sets¶
The rule is part of the following rule sets:
References¶
Fixer class: PhpCsFixer\Fixer\Phpdoc\PhpdocAlignFixer
Test class: PhpCsFixer\Tests\Fixer\Phpdoc\PhpdocAlignFixerTest
The test class defines officially supported behaviour. Each test case is a part of our backward compatibility promise.