Skip to content

Commit

Permalink
Merge pull request #21 from webimpress/hotfix/class-name-with-underscore
Browse files Browse the repository at this point in the history
Fixes regular expression to check class name
  • Loading branch information
michalbundyra committed May 15, 2019
2 parents 75affdf + 2255ec9 commit 5cce95f
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 7 deletions.
7 changes: 6 additions & 1 deletion src/WebimpressCodingStandard/Helper/MethodsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}
}
2 changes: 0 additions & 2 deletions src/WebimpressCodingStandard/Sniffs/Functions/ParamSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

use function array_filter;
use function array_merge;
use function count;
use function current;
use function explode;
use function implode;
Expand Down Expand Up @@ -321,7 +320,6 @@ private function checkParam(
}
}

$count = count($types);
$break = false;
foreach ($types as $key => $type) {
$lower = strtolower($type);
Expand Down
14 changes: 11 additions & 3 deletions test/Sniffs/Commenting/TagWithTypeUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
}
}
7 changes: 6 additions & 1 deletion test/Sniffs/Functions/ParamUnitTest.1.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
}
1 change: 1 addition & 0 deletions test/Sniffs/Functions/ParamUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ protected function getErrorList(string $testFile = '') : array
98 => 1,
130 => 1,
135 => 1,
143 => 2,
];
}

Expand Down
13 changes: 13 additions & 0 deletions test/Sniffs/Functions/ReturnTypeUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit 5cce95f

Please sign in to comment.