Skip to content

Commit

Permalink
Merge pull request #9 from asispts/comment
Browse files Browse the repository at this point in the history
Disallow one-line property doc comment
  • Loading branch information
asispts authored May 10, 2023
2 parents bcc57c8 + a984bae commit c093a88
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 7 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added
- Disallow one-line property doc comment rule (#7)

### Fixed
- Fix PSR12 FileHeader incorrect order
- Fix PSR12 FileHeader incorrect order (#6)

## [1.0] - 2023-04-21
Initial release
Expand Down
1 change: 1 addition & 0 deletions RULES.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,4 @@ $arr = array(); // not allowedgit a
34. Detect unused variables
35. Detect unused function parameters
36. Detect unused inherited variables passed to a closure
37. Disallow one-line property doc comment
1 change: 1 addition & 0 deletions ptscs/ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@
<rule ref="SlevomatCodingStandard.Variables.UnusedVariable" />
<rule ref="SlevomatCodingStandard.Functions.UnusedParameter" />
<rule ref="SlevomatCodingStandard.Functions.UnusedInheritedVariablePassedToClosure" />
<rule ref="SlevomatCodingStandard.Commenting.DisallowOneLinePropertyDocComment" />


<!--++++++++++++++++++++++++++++++++++++
Expand Down
26 changes: 26 additions & 0 deletions tests/Sniffs/Slevomat/DisallowOneLinePropertyDocCommentTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php declare(strict_types=1);

namespace Ptscs\Tests\Sniffs\Slevomat;

use Iterator;
use Ptscs\Tests\SniffTestCase;
use Ptscs\Tests\Utils\ErrorData;

final class DisallowOneLinePropertyDocCommentTest extends SniffTestCase
{
protected function setUp(): void
{
parent::setUp();
$this->appendExclude('Squiz.Classes.ClassFileName.NoMatch');
}

public static function provideTestData(): Iterator
{
yield[
[
// phpcs:ignore Generic.Files.LineLength.TooLong
new ErrorData(7, 'SlevomatCodingStandard.Commenting.DisallowOneLinePropertyDocComment.OneLinePropertyComment'),
],
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php declare(strict_types=1);

namespace App;

final class Foobar
{
/**
* @var string
*/
public $name;

public function __invoke()
{
/** @var string */
$foobar = 'Should not format this doc comment';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php declare(strict_types=1);

namespace App;

final class Foobar
{
/** @var string */
public $name;

public function __invoke()
{
/** @var string */
$foobar = 'Should not format this doc comment';
}
}
12 changes: 9 additions & 3 deletions tests/Sniffs/Squiz/_data/ClassProperty.php.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ class Class1
}
class Class2
{
/** @doc */
/**
* doc comment
*/
private $var1;
}
class Class3
Expand All @@ -18,14 +20,18 @@ class Class3
}
class Class4
{
/** docs */
/**
* doc comment
*/
#[attribute]
private $var1;
}
class Class5
{
#[attribute]

/** docs */
/**
* doc comment
*/
private $var1;
}
6 changes: 3 additions & 3 deletions tests/Sniffs/Squiz/_data/ClassProperty.php.inc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Class1
}
class Class2
{
/** @doc */
/** doc comment */


private $var1;
Expand All @@ -24,7 +24,7 @@ class Class3
}
class Class4
{
/** docs */
/** doc comment */


#[attribute]
Expand All @@ -37,7 +37,7 @@ class Class5
#[attribute]


/** docs */
/** doc comment */


private $var1;
Expand Down

0 comments on commit c093a88

Please sign in to comment.