Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Rector\Symfony\Tests\Symfony73\Rector\Class_\ConstraintOptionsToNamedArgumentsRector\Fixture;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Validator\Constraints\NotBlank;

class SkipWithTranslateComment extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('name', TextType::class, [
'constraints' => [
new NotBlank(['message' =>
// @Translate
'Name is required.'
]),
],
]);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Rector\Symfony\Tests\Symfony73\Rector\Class_\ConstraintOptionsToNamedArgumentsRector\Fixture;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Validator\Constraints\NotBlank;

class SkipWithTranslateDocblock extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('name', TextType::class, [
'constraints' => [
new NotBlank(['message' => /** @Translate */ 'Name is required.']),
],
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ public function refactor(Node $node): ?Node

$array = $node->args[0]->value;
$namedArgs = [];
$oldTokens = $this->file->getOldTokens();

foreach ($array->items as $item) {
if (! $item instanceof ArrayItem) {
Expand All @@ -130,6 +131,22 @@ public function refactor(Node $node): ?Node
continue;
}

$lastTokenKey = $item->key->getEndTokenPos();
$startTokenValue = $item->value->getStartTokenPos();

while ($lastTokenKey < $startTokenValue) {
++$lastTokenKey;

if (! isset($oldTokens[$lastTokenKey])) {
break;
}

$token = $oldTokens[$lastTokenKey];
if ($token->is([T_DOC_COMMENT, T_COMMENT])) {
return null;
}
}

$arg = new Arg($item->value);
$arg->name = new Identifier($keyValue);

Expand Down