mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-05 19:00:49 +00:00
[TriggerExtractor] add simple string message resolving
This commit is contained in:
parent
58e920b461
commit
d0eb865626
|
@ -48,7 +48,7 @@ final class TriggerExtractor
|
|||
|
||||
foreach ($files as $file) {
|
||||
$nodes = $this->parser->parseFile($file->getRealPath());
|
||||
// this completes parent & child nodes and types
|
||||
// this completes parent & child nodes, types and classses
|
||||
$this->standaloneTraverseNodeTraverser->traverse($nodes);
|
||||
$this->mainNodeTraverser->traverse($nodes);
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace Rector\TriggerExtractor;
|
||||
|
||||
use Exception;
|
||||
use Nette\Utils\Strings;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\BinaryOp\Concat;
|
||||
use PhpParser\Node\Scalar\MagicConst\Method;
|
||||
|
@ -11,6 +12,10 @@ use PhpParser\Node\Stmt\ClassMethod;
|
|||
|
||||
final class TriggerMessageResolver
|
||||
{
|
||||
/**
|
||||
* Probably resolve by recursion, similar too
|
||||
* @see \Rector\NodeTypeResolver\NodeVisitor\TypeResolver::__construct()
|
||||
*/
|
||||
public function resolve(Node $node): string
|
||||
{
|
||||
$message = '';
|
||||
|
@ -31,7 +36,8 @@ final class TriggerMessageResolver
|
|||
}
|
||||
|
||||
if ($node instanceof String_) {
|
||||
return $node->value;
|
||||
$message = $node->value; // complet class to local methods
|
||||
return $this->completeClassToLocalMethods($message, $node->getAttribute('class'));
|
||||
}
|
||||
|
||||
throw new Exception(sprintf(
|
||||
|
@ -52,4 +58,24 @@ final class TriggerMessageResolver
|
|||
|
||||
return $parentNode;
|
||||
}
|
||||
|
||||
private function completeClassToLocalMethods(string $message, string $class): string
|
||||
{
|
||||
$completeMessage = '';
|
||||
$words = explode(' ', $message);
|
||||
|
||||
foreach ($words as $word) {
|
||||
// is method()
|
||||
if (Strings::endsWith($word, '()') && strlen($word) > 2) {
|
||||
// doesn't include class in the beggning
|
||||
if (! Strings::startsWith($word, $class)) {
|
||||
$word = $class . '::' . $word;
|
||||
}
|
||||
}
|
||||
|
||||
$completeMessage .= ' ' . $word;
|
||||
}
|
||||
|
||||
return trim($completeMessage);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user