rectorphp / rector

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

Could not to remove positional value from annotation #8752

Closed pincher2012 closed 1 week ago

pincher2012 commented 1 month ago

Bug Report

Subject Details
Rector version v1.2.1

Could not remove positional parameter from DoctrineAnnotationTagValueNode by int index, because AbstractValuesAwareNode::removeValue have string type.

Minimal PHP Code Causing Issue

/**
 * @OA\Schema(
 *     schema="ContentBlockTreeResponseDTO",
 *     @OA\Property(property="id", type="integer"),
 * )
 */
class SchemaWithUnnamedParameterDto
{
}
foreach ($doctrineTagValueNode->getValues() as $value) {
    $doctrineTagValueNode->removeValue($key);
}
TypeError: Rector\BetterPhpDocParser\ValueObject\PhpDoc\DoctrineAnnotation\AbstractValuesAwareNode::removeValue(): Argument #1 ($desiredKey) must be of type string, int given

Expected Behaviour

I have ability to remove annotation positional value

samsonasik commented 1 month ago

Could you create failing test case for it, basically, create a reproducible test like this one https://github.com/rectorphp/rector-src/tree/main/tests/Issues/PartialValueDocblockUpdate , that's are:

  1. Source have custom rule example,
  2. Fixture for expected input and output,
  3. config for config to load for custom rule,
  4. test class for it.
pincher2012 commented 1 month ago

@samsonasik I create test cases in my fork. Should I create PR?

samsonasik commented 1 month ago

yes please 👍

TomasVotruba commented 1 week ago

Closing as answered in https://github.com/rectorphp/rector-src/pull/6172 :+1: