diff --git a/src/WebimpressCodingStandard/Helper/MethodsTrait.php b/src/WebimpressCodingStandard/Helper/MethodsTrait.php index e96d2f77..2f4fe0d2 100644 --- a/src/WebimpressCodingStandard/Helper/MethodsTrait.php +++ b/src/WebimpressCodingStandard/Helper/MethodsTrait.php @@ -399,6 +399,11 @@ private function isType(string $tag, string $type) : bool return true; } - return (bool) preg_match('/^((?:\\\\?[a-z0-9]+)+(?:\[\])*)(\|(?:\\\\?[a-z0-9]+)+(?:\[\])*)*$/i', $type); + $classRegexp = '\\\\?[a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff]*'; + + return (bool) preg_match( + '/^((?:' . $classRegexp . ')+(?:\[\])*)(\|(?:' . $classRegexp . ')+(?:\[\])*)*$/i', + $type + ); } } diff --git a/src/WebimpressCodingStandard/Sniffs/Functions/ParamSniff.php b/src/WebimpressCodingStandard/Sniffs/Functions/ParamSniff.php index 78fa389d..02aee55d 100644 --- a/src/WebimpressCodingStandard/Sniffs/Functions/ParamSniff.php +++ b/src/WebimpressCodingStandard/Sniffs/Functions/ParamSniff.php @@ -10,7 +10,6 @@ use function array_filter; use function array_merge; -use function count; use function current; use function explode; use function implode; @@ -321,7 +320,6 @@ private function checkParam( } } - $count = count($types); $break = false; foreach ($types as $key => $type) { $lower = strtolower($type); diff --git a/test/Sniffs/Commenting/TagWithTypeUnitTest.inc b/test/Sniffs/Commenting/TagWithTypeUnitTest.inc index 5e6567da..5b1cb82c 100644 --- a/test/Sniffs/Commenting/TagWithTypeUnitTest.inc +++ b/test/Sniffs/Commenting/TagWithTypeUnitTest.inc @@ -2,9 +2,17 @@ namespace MyNamespace\Test; -class TagWithType { +class TagWithType +{ + /** @var \Property_Type */ + public $className; + /** - * @throws \Exception + * @param \Param_Type $param + * @return \Return_Type + * @throws \Exception_Name */ - public function test() {} + public function test(\Param_Type $param) : \Return_Type + { + } } diff --git a/test/Sniffs/Functions/ParamUnitTest.1.inc b/test/Sniffs/Functions/ParamUnitTest.1.inc index 0525d05d..7d537fab 100644 --- a/test/Sniffs/Functions/ParamUnitTest.1.inc +++ b/test/Sniffs/Functions/ParamUnitTest.1.inc @@ -137,5 +137,10 @@ class FunctionParam /** * @param int,string $a */ - public function invalidType($a); + abstract public function invalidType($a); + + /** + * @param Other_Param $Foo + */ + public function withUnderscore(With_Underscore $a, $foo = null) {} } diff --git a/test/Sniffs/Functions/ParamUnitTest.php b/test/Sniffs/Functions/ParamUnitTest.php index c238710f..54fc62dc 100644 --- a/test/Sniffs/Functions/ParamUnitTest.php +++ b/test/Sniffs/Functions/ParamUnitTest.php @@ -27,6 +27,7 @@ protected function getErrorList(string $testFile = '') : array 98 => 1, 130 => 1, 135 => 1, + 143 => 2, ]; } diff --git a/test/Sniffs/Functions/ReturnTypeUnitTest.inc b/test/Sniffs/Functions/ReturnTypeUnitTest.inc index 7ad47c6a..208cae43 100644 --- a/test/Sniffs/Functions/ReturnTypeUnitTest.inc +++ b/test/Sniffs/Functions/ReturnTypeUnitTest.inc @@ -254,4 +254,17 @@ abstract class FunctionCommentReturn { return $this->thisParent(); } + + public function withReturnType($a): \Return_Type + { + return $a; + } + + /** + * @return \Return_Type + */ + public function withDocBlock($a) + { + return $a; + } }