Back to Php Cs Fixer

Rule ``phpdoc_line_span``

doc/rules/phpdoc/phpdoc_line_span.rst

3.95.13.0 KB
Original Source

========================= Rule phpdoc_line_span

Changes doc blocks from single to multi line, or reversed.

Warning

This rule is CONFIGURABLE


You can configure this rule using the following options: ``case``, ``class``,
``const``, ``function``, ``method``, ``other``, ``property``, ``trait_import``.

Configuration
-------------

``case``
~~~~~~~~

Whether enum case doc blocks should be single or multi line.

Allowed values: ``'multi'``, ``'single'`` and ``null``

Default value: ``'multi'``

``class``
~~~~~~~~~

Whether class/interface/enum/trait blocks should be single or multi line.

Allowed values: ``'multi'``, ``'single'`` and ``null``

Default value: ``'multi'``

``const``
~~~~~~~~~

Whether const blocks should be single or multi line.

Allowed values: ``'multi'``, ``'single'`` and ``null``

Default value: ``'multi'``

``function``
~~~~~~~~~~~~

Whether function declaration doc blocks should be single or multi line.

Allowed values: ``'multi'``, ``'single'`` and ``null``

Default value: ``'multi'``

``method``
~~~~~~~~~~

Whether method doc blocks should be single or multi line.

Allowed values: ``'multi'``, ``'single'`` and ``null``

Default value: ``'multi'``

``other``
~~~~~~~~~

Whether blocks for other code lines should be single or multi line.

Allowed values: ``'multi'``, ``'single'`` and ``null``

Default value: ``null``

``property``
~~~~~~~~~~~~

Whether property doc blocks should be single or multi line.

Allowed values: ``'multi'``, ``'single'`` and ``null``

Default value: ``'multi'``

``trait_import``
~~~~~~~~~~~~~~~~

Whether trait usage blocks should be single or multi line.

Allowed values: ``'multi'``, ``'single'`` and ``null``

Default value: ``null``

Examples
--------

Example #1
~~~~~~~~~~

*Default* configuration.

.. code-block:: diff

   --- Original
   +++ New
    <?php

    class Foo{
   -    /** @var bool */
   +    /**
   +     * @var bool
   +     */
        public $var;
    }

Example #2
~~~~~~~~~~

With configuration: ``['property' => 'single']``.

.. code-block:: diff

   --- Original
   +++ New
    <?php

    class Foo{
   -    /**
   -    * @var bool
   -    */
   +    /** @var bool */
        public $var;
    }

Example #3
~~~~~~~~~~

With configuration: ``['function' => 'multi']``.

.. code-block:: diff

   --- Original
   +++ New
    <?php

   -/** Description of foo function. */
   +/**
   + * Description of foo function.
   + */
    function foo(): void {}

Example #4
~~~~~~~~~~

With configuration: ``['other' => 'single']``.

.. code-block:: diff

   --- Original
   +++ New
    <?php
   -/**
   - * @var string
   - */
   +/** @var string */
    $var = foo();

References
----------

- Fixer class: `PhpCsFixer\\Fixer\\Phpdoc\\PhpdocLineSpanFixer <./../../../src/Fixer/Phpdoc/PhpdocLineSpanFixer.php>`_
- Test class: `PhpCsFixer\\Tests\\Fixer\\Phpdoc\\PhpdocLineSpanFixerTest <./../../../tests/Fixer/Phpdoc/PhpdocLineSpanFixerTest.php>`_

The test class defines officially supported behaviour. Each test case is a part of our backward compatibility promise.