Skip to content

Commit c5b116a

Browse files
authored
Merge pull request #252 from simPod/single-line
Add RequireOneLineDocComment sniff
2 parents 2de6d14 + 5f2650e commit c5b116a

14 files changed

+40
-56
lines changed

lib/Doctrine/ruleset.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,8 @@
419419
</rule>
420420
<!-- Forbid useless @var for constants -->
421421
<rule ref="SlevomatCodingStandard.TypeHints.UselessConstantTypeHint"/>
422+
<!-- Require One Line Doc Comment where there's only 1 annotation present -->
423+
<rule ref="SlevomatCodingStandard.Commenting.RequireOneLineDocComment"/>
422424
<!-- Forbid useless phpDocs for functions -->
423425
<rule ref="SlevomatCodingStandard.Commenting.UselessFunctionDocComment">
424426
<properties>

tests/expected_report.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ tests/input/concatenation_spacing.php 49 0
1212
tests/input/constants-no-lsb.php 2 0
1313
tests/input/constants-var.php 6 0
1414
tests/input/ControlStructures.php 28 0
15-
tests/input/doc-comment-spacing.php 10 0
15+
tests/input/doc-comment-spacing.php 11 0
1616
tests/input/duplicate-assignment-variable.php 1 0
1717
tests/input/EarlyReturn.php 6 0
18-
tests/input/example-class.php 36 0
18+
tests/input/example-class.php 38 0
1919
tests/input/forbidden-comments.php 14 0
2020
tests/input/forbidden-functions.php 6 0
2121
tests/input/inline_type_hint_assertions.php 7 0
@@ -45,9 +45,9 @@ tests/input/use-ordering.php 1 0
4545
tests/input/useless-semicolon.php 2 0
4646
tests/input/UselessConditions.php 20 0
4747
----------------------------------------------------------------------
48-
A TOTAL OF 374 ERRORS AND 0 WARNINGS WERE FOUND IN 41 FILES
48+
A TOTAL OF 377 ERRORS AND 0 WARNINGS WERE FOUND IN 41 FILES
4949
----------------------------------------------------------------------
50-
PHPCBF CAN FIX 310 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
50+
PHPCBF CAN FIX 313 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
5151
----------------------------------------------------------------------
5252

5353

tests/fixed/ControlStructures.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ class ControlStructures
1313
{
1414
private const VERSION = PHP_VERSION;
1515

16-
/**
17-
* @return iterable<int>
18-
*/
16+
/** @return iterable<int> */
1917
public function varAndIfNoSpaceBetween(): iterable
2018
{
2119
$var = 1;
@@ -26,9 +24,7 @@ public function varAndIfNoSpaceBetween(): iterable
2624
yield 0;
2725
}
2826

29-
/**
30-
* @return iterable<int>
31-
*/
27+
/** @return iterable<int> */
3228
public function ifAndYieldSpaceBetween(): iterable
3329
{
3430
if (self::VERSION === 0) {
@@ -38,9 +34,7 @@ public function ifAndYieldSpaceBetween(): iterable
3834
yield 1;
3935
}
4036

41-
/**
42-
* @return iterable<int>
43-
*/
37+
/** @return iterable<int> */
4438
public function ifAndYieldFromSpaceBetween(): iterable
4539
{
4640
if (self::VERSION === 0) {

tests/fixed/UselessConditions.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,7 @@ public function uselessTernaryWithMethod(): bool
119119
return $this->isFalse() ? true : false;
120120
}
121121

122-
/**
123-
* @param string[] $words
124-
*/
122+
/** @param string[] $words */
125123
public function uselessTernaryCheck(array $words): bool
126124
{
127125
return count($words) < 1;

tests/fixed/class-references.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ class Foo
88

99
class Bar extends Foo
1010
{
11-
/**
12-
* @return string[]
13-
*/
11+
/** @return string[] */
1412
public function names(): iterable
1513
{
1614
yield self::class;

tests/fixed/doc-comment-spacing.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,9 @@ public function c(iterable $foo): void
7171
public function d(iterable $foo, iterable $bar): iterable
7272
{
7373
}
74+
75+
/** @param iterable<mixed> $singleAnnotation */
76+
public function e(iterable $singleAnnotation): void
77+
{
78+
}
7479
}

tests/fixed/example-class.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,7 @@ public function getFoo(): ?int
5353
return $this->foo;
5454
}
5555

56-
/**
57-
* @return iterable
58-
*/
56+
/** @return iterable */
5957
public function getIterator(): array
6058
{
6159
assert($this->bar !== null);
@@ -70,9 +68,7 @@ public function isBaz(): bool
7068
return $this->baz;
7169
}
7270

73-
/**
74-
* @throws InvalidArgumentException if this example cannot baz.
75-
*/
71+
/** @throws InvalidArgumentException if this example cannot baz. */
7672
public function mangleBar(int $length): void
7773
{
7874
if (! $this->baz) {

tests/fixed/test-case.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66

77
use PHPUnit\Framework\TestCase as BaseTestCase;
88

9-
/**
10-
* @requires PHP 7.2
11-
*/
9+
/** @requires PHP 7.2 */
1210
final class TestCase extends BaseTestCase
1311
{
1412
/**
@@ -19,9 +17,7 @@ public static function doStuff(): void
1917
{
2018
}
2119

22-
/**
23-
* @before
24-
*/
20+
/** @before */
2521
public function createDependencies(): void
2622
{
2723
}

tests/input/ControlStructures.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ class ControlStructures
1313
{
1414
private const VERSION = PHP_VERSION;
1515

16-
/**
17-
* @return iterable<int>
18-
*/
16+
/** @return iterable<int> */
1917
public function varAndIfNoSpaceBetween(): iterable
2018
{
2119
$var = 1;
@@ -24,9 +22,7 @@ public function varAndIfNoSpaceBetween(): iterable
2422
}
2523
}
2624

27-
/**
28-
* @return iterable<int>
29-
*/
25+
/** @return iterable<int> */
3026
public function ifAndYieldSpaceBetween(): iterable
3127
{
3228
if (self::VERSION === 0) {
@@ -35,9 +31,7 @@ public function ifAndYieldSpaceBetween(): iterable
3531
yield 1;
3632
}
3733

38-
/**
39-
* @return iterable<int>
40-
*/
34+
/** @return iterable<int> */
4135
public function ifAndYieldFromSpaceBetween(): iterable
4236
{
4337
if (self::VERSION === 0) {

tests/input/UselessConditions.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,7 @@ public function uselessTernaryWithMethod(): bool
151151
return $this->isFalse() ? true : false;
152152
}
153153

154-
/**
155-
* @param string[] $words
156-
*/
154+
/** @param string[] $words */
157155
public function uselessTernaryCheck(array $words): bool
158156
{
159157
return count($words) >= 1 ? false : true;

0 commit comments

Comments
 (0)