[Php80] Handle double quoted sql statement annotation on AnnotationToAttributeRector (#1516)

* Add test with SQL in nested annotation argument

* update fixture namespace

* Closes #1515 Fixes https://github.com/rectorphp/rector/issues/6859

* [ci-review] Rector Rectify

* clean up

* clean up

Co-authored-by: Jacob Thomason <jacob@thomason.xxx>
Co-authored-by: GitHub Action <action@github.com>
This commit is contained in:
Abdul Malik Ikhsan 2021-12-18 17:10:03 +07:00 committed by GitHub
parent 0c26b042ab
commit 4e0a1ce694
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 46 additions and 1 deletions

View File

@ -117,7 +117,10 @@ final class PlainValueParser
// keep the last ")"
$tokenIterator->tryConsumeTokenType(Lexer::TOKEN_PHPDOC_EOL);
$tokenIterator->consumeTokenType(Lexer::TOKEN_CLOSE_PARENTHESES);
if ($tokenIterator->currentTokenValue() === ')') {
$tokenIterator->consumeTokenType(Lexer::TOKEN_CLOSE_PARENTHESES);
}
// keep original name to differentiate between short and FQN class
$identifierTypeNode = new IdentifierTypeNode($annotationShortName);

View File

@ -0,0 +1,40 @@
<?php
namespace Rector\Tests\Php80\Rector\Class_\AnnotationToAttributeRector\FixturePhp81;
use Rector\Tests\Php80\Rector\Class_\AnnotationToAttributeRector\Source\GenericAnnotation;
/**
* @GenericAnnotation(filters={
* @GenericAnnotation(sql="
* $this.id IN(
* SELECT id
* FROM foo
* WHERE bar = 'baz'
* )"
* )
* })
*/
class SqlStatement
{
}
?>
-----
<?php
namespace Rector\Tests\Php80\Rector\Class_\AnnotationToAttributeRector\FixturePhp81;
use Rector\Tests\Php80\Rector\Class_\AnnotationToAttributeRector\Source\GenericAnnotation;
#[GenericAnnotation(filters: [new GenericAnnotation(sql: '
$this.id IN(
SELECT id
FROM foo
WHERE bar = \'baz\'
)')])]
class SqlStatement
{
}
?>

View File

@ -6,6 +6,7 @@ use Rector\Core\Configuration\Option;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\Php80\Rector\Class_\AnnotationToAttributeRector;
use Rector\Php80\ValueObject\AnnotationToAttribute;
use Rector\Tests\Php80\Rector\Class_\AnnotationToAttributeRector\Source\GenericAnnotation;
use Rector\Tests\Php80\Rector\Class_\AnnotationToAttributeRector\SourcePhp81\All;
use Rector\Tests\Php80\Rector\Class_\AnnotationToAttributeRector\SourcePhp81\Length;
use Rector\Tests\Php80\Rector\Class_\AnnotationToAttributeRector\SourcePhp81\NotNull;
@ -25,6 +26,7 @@ return static function (ContainerConfigurator $containerConfigurator): void {
new AnnotationToAttribute(Length::class),
new AnnotationToAttribute(NotNull::class),
new AnnotationToAttribute(NotNumber::class),
new AnnotationToAttribute(GenericAnnotation::class),
],
]);
};