rectorphp / rector

Instant Upgrades and Automated Refactoring of any PHP 5.3+ code
https://getrector.com
MIT License
8.67k stars 682 forks source link

Incorrect behavior of AnnotationToAttributeRector #6484

Closed romainallanot closed 3 years ago

romainallanot commented 3 years ago

Bug Report

Subject Details
Rector version v0.11.8
Installed as composer dependency

Quotes in arrays are not removed.

Minimal PHP Code Causing Issue

See https://getrector.org/demo/df58f840-a218-4f37-bd1a-f48771bed3bc

<?php

use ApiPlatform\Core\Annotation\ApiResource;
use Doctrine\ORM\Mapping as ORM;

/**
 * Book.
 *
 * @ApiResource(collectionOperations={}, itemOperations={
 *     "get",
 *     "get_by_isbn"={"method"="GET", "path"="/books/by_isbn/{isbn}.{_format}", "requirements"={"isbn"=".+"}, "identifiers"="isbn"}
 * })
 * @ORM\Entity
 */
class Book
{}

Responsible rules

Expected Behavior

Remove quotes in arrays as below

#[ApiResource(collectionOperations: [], itemOperations: ['get', 'get_by_isbn' => ['method' => 'GET', 'path' => '/books/by_isbn/{isbn}.{_format}', 'requirements' => ['isbn' => '.+'], 'identifiers' => 'isbn']])]
TomasVotruba commented 3 years ago

Thank you for your report and demo link!

Could you send a failing test case in a pull-request, so we have it covered in Rector? Here is step by step tutorial how to add it: https://github.com/rectorphp/rector/blob/master/docs/how_to_add_test_for_rector_rule.md

romainallanot commented 3 years ago

@TomasVotruba I have a fix if you want, I can send it tomorrow.

samsonasik commented 3 years ago

@romainallanot Thank you for the fix