Skip to content

Commit

Permalink
Add RequireOneLineDocComment sniff
Browse files Browse the repository at this point in the history
This reduces vertical space in code. Same as it's already done for `@var` annotations as

```php
/**
 * @var mixed
 */
```

```php
/** @var mixed */
```

is now done for other annotations

```php
/**
 * @param mixed $param
 */
```

```php
/** @param mixed $param */
```
  • Loading branch information
simPod committed May 7, 2021
1 parent 2de6d14 commit 5f2650e
Show file tree
Hide file tree
Showing 14 changed files with 40 additions and 56 deletions.
2 changes: 2 additions & 0 deletions lib/Doctrine/ruleset.xml
Expand Up @@ -419,6 +419,8 @@
</rule>
<!-- Forbid useless @var for constants -->
<rule ref="SlevomatCodingStandard.TypeHints.UselessConstantTypeHint"/>
<!-- Require One Line Doc Comment where there's only 1 annotation present -->
<rule ref="SlevomatCodingStandard.Commenting.RequireOneLineDocComment"/>
<!-- Forbid useless phpDocs for functions -->
<rule ref="SlevomatCodingStandard.Commenting.UselessFunctionDocComment">
<properties>
Expand Down
8 changes: 4 additions & 4 deletions tests/expected_report.txt
Expand Up @@ -12,10 +12,10 @@ tests/input/concatenation_spacing.php 49 0
tests/input/constants-no-lsb.php 2 0
tests/input/constants-var.php 6 0
tests/input/ControlStructures.php 28 0
tests/input/doc-comment-spacing.php 10 0
tests/input/doc-comment-spacing.php 11 0
tests/input/duplicate-assignment-variable.php 1 0
tests/input/EarlyReturn.php 6 0
tests/input/example-class.php 36 0
tests/input/example-class.php 38 0
tests/input/forbidden-comments.php 14 0
tests/input/forbidden-functions.php 6 0
tests/input/inline_type_hint_assertions.php 7 0
Expand Down Expand Up @@ -45,9 +45,9 @@ tests/input/use-ordering.php 1 0
tests/input/useless-semicolon.php 2 0
tests/input/UselessConditions.php 20 0
----------------------------------------------------------------------
A TOTAL OF 374 ERRORS AND 0 WARNINGS WERE FOUND IN 41 FILES
A TOTAL OF 377 ERRORS AND 0 WARNINGS WERE FOUND IN 41 FILES
----------------------------------------------------------------------
PHPCBF CAN FIX 310 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
PHPCBF CAN FIX 313 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------


12 changes: 3 additions & 9 deletions tests/fixed/ControlStructures.php
Expand Up @@ -13,9 +13,7 @@ class ControlStructures
{
private const VERSION = PHP_VERSION;

/**
* @return iterable<int>
*/
/** @return iterable<int> */
public function varAndIfNoSpaceBetween(): iterable
{
$var = 1;
Expand All @@ -26,9 +24,7 @@ public function varAndIfNoSpaceBetween(): iterable
yield 0;
}

/**
* @return iterable<int>
*/
/** @return iterable<int> */
public function ifAndYieldSpaceBetween(): iterable
{
if (self::VERSION === 0) {
Expand All @@ -38,9 +34,7 @@ public function ifAndYieldSpaceBetween(): iterable
yield 1;
}

/**
* @return iterable<int>
*/
/** @return iterable<int> */
public function ifAndYieldFromSpaceBetween(): iterable
{
if (self::VERSION === 0) {
Expand Down
4 changes: 1 addition & 3 deletions tests/fixed/UselessConditions.php
Expand Up @@ -119,9 +119,7 @@ public function uselessTernaryWithMethod(): bool
return $this->isFalse() ? true : false;
}

/**
* @param string[] $words
*/
/** @param string[] $words */
public function uselessTernaryCheck(array $words): bool
{
return count($words) < 1;
Expand Down
4 changes: 1 addition & 3 deletions tests/fixed/class-references.php
Expand Up @@ -8,9 +8,7 @@ class Foo

class Bar extends Foo
{
/**
* @return string[]
*/
/** @return string[] */
public function names(): iterable
{
yield self::class;
Expand Down
5 changes: 5 additions & 0 deletions tests/fixed/doc-comment-spacing.php
Expand Up @@ -71,4 +71,9 @@ public function c(iterable $foo): void
public function d(iterable $foo, iterable $bar): iterable
{
}

/** @param iterable<mixed> $singleAnnotation */
public function e(iterable $singleAnnotation): void
{
}
}
8 changes: 2 additions & 6 deletions tests/fixed/example-class.php
Expand Up @@ -53,9 +53,7 @@ public function getFoo(): ?int
return $this->foo;
}

/**
* @return iterable
*/
/** @return iterable */
public function getIterator(): array
{
assert($this->bar !== null);
Expand All @@ -70,9 +68,7 @@ public function isBaz(): bool
return $this->baz;
}

/**
* @throws InvalidArgumentException if this example cannot baz.
*/
/** @throws InvalidArgumentException if this example cannot baz. */
public function mangleBar(int $length): void
{
if (! $this->baz) {
Expand Down
8 changes: 2 additions & 6 deletions tests/fixed/test-case.php
Expand Up @@ -6,9 +6,7 @@

use PHPUnit\Framework\TestCase as BaseTestCase;

/**
* @requires PHP 7.2
*/
/** @requires PHP 7.2 */
final class TestCase extends BaseTestCase
{
/**
Expand All @@ -19,9 +17,7 @@ public static function doStuff(): void
{
}

/**
* @before
*/
/** @before */
public function createDependencies(): void
{
}
Expand Down
12 changes: 3 additions & 9 deletions tests/input/ControlStructures.php
Expand Up @@ -13,9 +13,7 @@ class ControlStructures
{
private const VERSION = PHP_VERSION;

/**
* @return iterable<int>
*/
/** @return iterable<int> */
public function varAndIfNoSpaceBetween(): iterable
{
$var = 1;
Expand All @@ -24,9 +22,7 @@ public function varAndIfNoSpaceBetween(): iterable
}
}

/**
* @return iterable<int>
*/
/** @return iterable<int> */
public function ifAndYieldSpaceBetween(): iterable
{
if (self::VERSION === 0) {
Expand All @@ -35,9 +31,7 @@ public function ifAndYieldSpaceBetween(): iterable
yield 1;
}

/**
* @return iterable<int>
*/
/** @return iterable<int> */
public function ifAndYieldFromSpaceBetween(): iterable
{
if (self::VERSION === 0) {
Expand Down
4 changes: 1 addition & 3 deletions tests/input/UselessConditions.php
Expand Up @@ -151,9 +151,7 @@ public function uselessTernaryWithMethod(): bool
return $this->isFalse() ? true : false;
}

/**
* @param string[] $words
*/
/** @param string[] $words */
public function uselessTernaryCheck(array $words): bool
{
return count($words) >= 1 ? false : true;
Expand Down
4 changes: 1 addition & 3 deletions tests/input/class-references.php
Expand Up @@ -8,9 +8,7 @@ class Foo

class Bar extends Foo
{
/**
* @return string[]
*/
/** @return string[] */
public function names(): iterable
{
yield __CLASS__;
Expand Down
7 changes: 7 additions & 0 deletions tests/input/doc-comment-spacing.php
Expand Up @@ -67,4 +67,11 @@ public function c(iterable $foo): void
public function d(iterable $foo, iterable $bar): iterable
{
}

/**
* @param iterable<mixed> $singleAnnotation
*/
public function e(iterable $singleAnnotation): void
{
}
}
4 changes: 1 addition & 3 deletions tests/input/test-case.php
Expand Up @@ -21,9 +21,7 @@ static public function doStuff() : void
{
}

/**
* @before
*/
/** @before */
public function createDependencies()
{
}
Expand Down
14 changes: 7 additions & 7 deletions tests/php-compatibility.patch
Expand Up @@ -3,11 +3,11 @@ index fd5432c..233e24d 100644
--- a/tests/expected_report.txt
+++ b/tests/expected_report.txt
@@ -15,7 +15,7 @@ tests/input/ControlStructures.php 28 0
tests/input/doc-comment-spacing.php 10 0
tests/input/doc-comment-spacing.php 11 0
tests/input/duplicate-assignment-variable.php 1 0
tests/input/EarlyReturn.php 6 0
-tests/input/example-class.php 36 0
+tests/input/example-class.php 39 0
-tests/input/example-class.php 38 0
+tests/input/example-class.php 41 0
tests/input/forbidden-comments.php 14 0
tests/input/forbidden-functions.php 6 0
tests/input/inline_type_hint_assertions.php 7 0
Expand All @@ -34,11 +34,11 @@ index fd5432c..233e24d 100644
tests/input/useless-semicolon.php 2 0
tests/input/UselessConditions.php 20 0
----------------------------------------------------------------------
-A TOTAL OF 374 ERRORS AND 0 WARNINGS WERE FOUND IN 41 FILES
+A TOTAL OF 383 ERRORS AND 0 WARNINGS WERE FOUND IN 41 FILES
-A TOTAL OF 377 ERRORS AND 0 WARNINGS WERE FOUND IN 41 FILES
+A TOTAL OF 386 ERRORS AND 0 WARNINGS WERE FOUND IN 41 FILES
----------------------------------------------------------------------
-PHPCBF CAN FIX 310 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
+PHPCBF CAN FIX 319 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
-PHPCBF CAN FIX 313 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
+PHPCBF CAN FIX 322 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------


Expand Down

0 comments on commit 5f2650e

Please sign in to comment.