diff --git a/CHANGELOG.md b/CHANGELOG.md index cc2d2389..b7dbf92d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -55,6 +55,8 @@ All notable changes to this project will be documented in this file, in reverse - [#18](https://github.com/webimpress/coding-standard/pull/18) `Commenting\DocComment` - fixes requiring content straight after doc-block - allows empty line when next content is another doc-block +- [#19](https://github.com/webimpress/coding-standard/pull/19) `Commenting\DocComment` - fixes issue with doc-block after colon (for example in switch statement) - empty line is no longer required before doc-block in that case + ## 1.0.2 - 2019-05-12 ### Added diff --git a/src/WebimpressCodingStandard/Sniffs/Commenting/DocCommentSniff.php b/src/WebimpressCodingStandard/Sniffs/Commenting/DocCommentSniff.php index 45eb39b6..8c921bb9 100644 --- a/src/WebimpressCodingStandard/Sniffs/Commenting/DocCommentSniff.php +++ b/src/WebimpressCodingStandard/Sniffs/Commenting/DocCommentSniff.php @@ -23,6 +23,7 @@ use function substr; use function trim; +use const T_COLON; use const T_DOC_COMMENT_CLOSE_TAG; use const T_DOC_COMMENT_OPEN_TAG; use const T_DOC_COMMENT_STAR; @@ -189,6 +190,7 @@ private function checkBeforeOpen(File $phpcsFile, int $commentStart) : void T_OPEN_PARENTHESIS, T_OPEN_SHORT_ARRAY, T_OPEN_TAG, + T_COLON, ], true) ) { $error = 'Missing blank line before doc comment'; diff --git a/test/Sniffs/Commenting/DocCommentUnitTest.inc b/test/Sniffs/Commenting/DocCommentUnitTest.inc index 4f94e727..498aadcc 100644 --- a/test/Sniffs/Commenting/DocCommentUnitTest.inc +++ b/test/Sniffs/Commenting/DocCommentUnitTest.inc @@ -274,7 +274,7 @@ class Foo ]; } - public function docCommentInFunctionCall() : callable + public function docCommentInFunctionCall() : void { $this->getName( /** @@ -287,6 +287,25 @@ class Foo ); } + public function docCommentInSwitch(string $a) + { + switch ($a) { + case 'foo': + /** @var string $var */ + $var = $this->getName(); + + return $var[0]; + default: + /** + * @param int[] $a + * @return int + */ + return static function (array $a) { + return PHP_INT_MAX; + }; + } + } + /** * FIRST DOC-BLOCK COMMENT */ diff --git a/test/Sniffs/Commenting/DocCommentUnitTest.inc.fixed b/test/Sniffs/Commenting/DocCommentUnitTest.inc.fixed index 01f6c224..41e7f799 100644 --- a/test/Sniffs/Commenting/DocCommentUnitTest.inc.fixed +++ b/test/Sniffs/Commenting/DocCommentUnitTest.inc.fixed @@ -276,7 +276,7 @@ $c = 'xyz'; ]; } - public function docCommentInFunctionCall() : callable + public function docCommentInFunctionCall() : void { $this->getName( /** @@ -289,6 +289,25 @@ $c = 'xyz'; ); } + public function docCommentInSwitch(string $a) + { + switch ($a) { + case 'foo': + /** @var string $var */ + $var = $this->getName(); + + return $var[0]; + default: + /** + * @param int[] $a + * @return int + */ + return static function (array $a) { + return PHP_INT_MAX; + }; + } + } + /** * FIRST DOC-BLOCK COMMENT */