Skip to content

Commit

Permalink
Fix match static method name in annotation (#446)
Browse files Browse the repository at this point in the history
  • Loading branch information
zingimmick committed Jul 19, 2021
1 parent 10e545f commit 75c06ea
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/NodeCollector/StaticAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ private function hasStaticAnnotation(string $methodName, ClassReflection $classR
return false;
}

// @see https://regex101.com/r/7Zkej2/1
return (bool) Strings::match(
$resolvedPhpDocBlock->getPhpDocString(),
'#@method\s*static\s*(.*?)\b' . $methodName . '\b#'
'#@method\s*static\s*((([\w\|\\\\]+)|\$this)*+(\[\])*)*\s+\b' . $methodName . '\b#'
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Rector\Tests\Php70\Rector\MethodCall\ThisCallOnStaticMethodToStaticCallRector\Fixture;

/**
* @method static static create($parameters) some description with parameters
*/
trait SkipStringNotMethodNameInAnnotation
{
public function run()
{
$this->parameters();
}

public function parameters(): void
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace Rector\Tests\Php70\Rector\MethodCall\ThisCallOnStaticMethodToStaticCallRector\Fixture;

/**
* @method static static staticReturnStatic()
* @method static static|StaticMethodInAnnotation|string[]|$this staticReturnMixed()
* @method static withoutReturnType()
* @method static withoutParameters
* @method StaticMethodInAnnotation|static returnStatic
*/
trait StaticMethodInAnnotation
{
public function run()
{
$this->staticReturnStatic();
$this->staticReturnMixed();
$this->withoutReturnType();
$this->withoutParameters();
$this->returnStatic();
}
}

?>
-----
<?php

namespace Rector\Tests\Php70\Rector\MethodCall\ThisCallOnStaticMethodToStaticCallRector\Fixture;

/**
* @method static static staticReturnStatic()
* @method static static|StaticMethodInAnnotation|string[]|$this staticReturnMixed()
* @method static withoutReturnType()
* @method static withoutParameters
* @method StaticMethodInAnnotation|static returnStatic
*/
trait StaticMethodInAnnotation
{
public function run()
{
static::staticReturnStatic();
static::staticReturnMixed();
static::withoutReturnType();
static::withoutParameters();
$this->returnStatic();
}
}

?>

0 comments on commit 75c06ea

Please sign in to comment.