Browse Source

Allow phpdoc_line_span to ignore certain types

Jeffrey Angenent 3 years ago
parent
commit
c0d4cec38d

+ 3 - 3
doc/rules/phpdoc/phpdoc_line_span.rst

@@ -13,7 +13,7 @@ Configuration
 
 Whether const blocks should be single or multi line
 
-Allowed values: ``'multi'``, ``'single'``
+Allowed values: ``'multi'``, ``'single'``, ``null``
 
 Default value: ``'multi'``
 
@@ -22,7 +22,7 @@ Default value: ``'multi'``
 
 Whether property doc blocks should be single or multi line
 
-Allowed values: ``'multi'``, ``'single'``
+Allowed values: ``'multi'``, ``'single'``, ``null``
 
 Default value: ``'multi'``
 
@@ -31,7 +31,7 @@ Default value: ``'multi'``
 
 Whether method doc blocks should be single or multi line
 
-Allowed values: ``'multi'``, ``'single'``
+Allowed values: ``'multi'``, ``'single'``, ``null``
 
 Default value: ``'multi'``
 

+ 6 - 5
src/Fixer/Phpdoc/PhpdocLineSpanFixer.php

@@ -78,15 +78,15 @@ final class PhpdocLineSpanFixer extends AbstractFixer implements WhitespacesAwar
     {
         return new FixerConfigurationResolver([
             (new FixerOptionBuilder('const', 'Whether const blocks should be single or multi line'))
-                ->setAllowedValues(['single', 'multi'])
+                ->setAllowedValues(['single', 'multi', null])
                 ->setDefault('multi')
                 ->getOption(),
             (new FixerOptionBuilder('property', 'Whether property doc blocks should be single or multi line'))
-                ->setAllowedValues(['single', 'multi'])
+                ->setAllowedValues(['single', 'multi', null])
                 ->setDefault('multi')
                 ->getOption(),
             (new FixerOptionBuilder('method', 'Whether method doc blocks should be single or multi line'))
-                ->setAllowedValues(['single', 'multi'])
+                ->setAllowedValues(['single', 'multi', null])
                 ->setDefault('multi')
                 ->getOption(),
         ]);
@@ -101,12 +101,13 @@ final class PhpdocLineSpanFixer extends AbstractFixer implements WhitespacesAwar
                 continue;
             }
 
+            $type = $element['type'];
             $docIndex = $this->getDocBlockIndex($tokens, $index);
             $doc = new DocBlock($tokens[$docIndex]->getContent());
 
-            if ('multi' === $this->configuration[$element['type']]) {
+            if ('multi' === $this->configuration[$type]) {
                 $doc->makeMultiLine(WhitespacesAnalyzer::detectIndent($tokens, $docIndex), $this->whitespacesConfig->getLineEnding());
-            } else {
+            } elseif ('single' === $this->configuration[$type]) {
                 $doc->makeSingleLine();
             }
 

+ 54 - 0
tests/Fixer/Phpdoc/PhpdocLineSpanFixerTest.php

@@ -419,6 +419,60 @@ class Bar
 }
 ',
             ],
+            'It does not change method doc blocks if configured to do so' => [
+                '<?php
+
+class Foo
+{
+    /** @return mixed */
+    public function bar() {}
+
+    /**
+     * @return void
+     */
+    public function baz() {}
+}',
+                null,
+                [
+                    'method' => null,
+                ],
+            ],
+            'It does not change property doc blocks if configured to do so' => [
+                '<?php
+
+class Foo
+{
+    /**
+     * @var int
+     */
+    public $foo;
+
+    /** @var mixed */
+    public $bar;
+}',
+                null,
+                [
+                    'property' => null,
+                ],
+            ],
+            'It does not change const doc blocks if configured to do so' => [
+                '<?php
+
+class Foo
+{
+    /**
+     * @var int
+     */
+    public const FOO = 1;
+
+    /** @var mixed */
+    public const BAR = null;
+}',
+                null,
+                [
+                    'const' => null,
+                ],
+            ],
         ];
     }