This commit is contained in:
2025-05-12 14:25:25 +02:00
parent ab2db755ef
commit 9e378ca2b7
2719 changed files with 46505 additions and 60181 deletions

View File

@@ -81,7 +81,7 @@ abstract class AbstractVisitor
return \PHP_INT_MAX;
}
private function getStringNamedArguments(Node\Expr\CallLike|Node\Attribute $node, string $argumentName = null, bool $isArgumentNamePattern = false): array
private function getStringNamedArguments(Node\Expr\CallLike|Node\Attribute $node, ?string $argumentName = null, bool $isArgumentNamePattern = false): array
{
$args = $node instanceof Node\Expr\CallLike ? $node->getArgs() : $node->args;
$argumentValues = [];
@@ -119,6 +119,17 @@ abstract class AbstractVisitor
return $node->expr->value;
}
if ($node instanceof Node\Expr\ClassConstFetch) {
try {
$reflection = new \ReflectionClass($node->class->toString());
$constant = $reflection->getReflectionConstant($node->name->toString());
if (false !== $constant && \is_string($constant->getValue())) {
return $constant->getValue();
}
} catch (\ReflectionException) {
}
}
return null;
}
}

View File

@@ -32,6 +32,11 @@ final class ConstraintVisitor extends AbstractVisitor implements NodeVisitor
}
public function enterNode(Node $node): ?Node
{
return null;
}
public function leaveNode(Node $node): ?Node
{
if (!$node instanceof Node\Expr\New_ && !$node instanceof Node\Attribute) {
return null;
@@ -42,7 +47,7 @@ final class ConstraintVisitor extends AbstractVisitor implements NodeVisitor
return null;
}
$parts = $className->parts;
$parts = $className->getParts();
$isConstraintClass = false;
foreach ($parts as $part) {
@@ -100,11 +105,6 @@ final class ConstraintVisitor extends AbstractVisitor implements NodeVisitor
return null;
}
public function leaveNode(Node $node): ?Node
{
return null;
}
public function afterTraverse(array $nodes): ?Node
{
return null;

View File

@@ -25,6 +25,11 @@ final class TransMethodVisitor extends AbstractVisitor implements NodeVisitor
}
public function enterNode(Node $node): ?Node
{
return null;
}
public function leaveNode(Node $node): ?Node
{
if (!$node instanceof Node\Expr\MethodCall && !$node instanceof Node\Expr\FuncCall) {
return null;
@@ -34,12 +39,12 @@ final class TransMethodVisitor extends AbstractVisitor implements NodeVisitor
return null;
}
$name = (string) $node->name;
$name = $node->name instanceof Node\Name ? $node->name->getLast() : (string) $node->name;
if ('trans' === $name || 't' === $name) {
$firstNamedArgumentIndex = $this->nodeFirstNamedArgumentIndex($node);
if (!$messages = $this->getStringArguments($node, 0 < $firstNamedArgumentIndex ? 0 : 'message')) {
if (!$messages = $this->getStringArguments($node, 0 < $firstNamedArgumentIndex ? 0 : 'id')) {
return null;
}
@@ -53,11 +58,6 @@ final class TransMethodVisitor extends AbstractVisitor implements NodeVisitor
return null;
}
public function leaveNode(Node $node): ?Node
{
return null;
}
public function afterTraverse(array $nodes): ?Node
{
return null;

View File

@@ -25,6 +25,11 @@ final class TranslatableMessageVisitor extends AbstractVisitor implements NodeVi
}
public function enterNode(Node $node): ?Node
{
return null;
}
public function leaveNode(Node $node): ?Node
{
if (!$node instanceof Node\Expr\New_) {
return null;
@@ -34,7 +39,7 @@ final class TranslatableMessageVisitor extends AbstractVisitor implements NodeVi
return null;
}
if (!\in_array('TranslatableMessage', $className->parts, true)) {
if (!\in_array('TranslatableMessage', $className->getParts(), true)) {
return null;
}
@@ -53,11 +58,6 @@ final class TranslatableMessageVisitor extends AbstractVisitor implements NodeVi
return null;
}
public function leaveNode(Node $node): ?Node
{
return null;
}
public function afterTraverse(array $nodes): ?Node
{
return null;