Skip to content

ObjectTypedPropertyFromJMSSerializerAttributeTypeRector incorrectly assumes valid FQCN #9570

@buffcode

Description

@buffcode

Bug Report

Subject Details
Rector version last dev-main
Installed as composer dependency

Minimal PHP Code Causing Issue

See https://getrector.com/demo/1edb0df3-3b60-46ae-95b2-9ea6edb11c15

<?php

use JMS\Serializer\Annotation as JMS;

final class DemoFile
{
    #[JMS\Type('DoctrineDocumentReference')]
    protected $dynamicRef;

}

Responsible rules

  • ObjectTypedPropertyFromJMSSerializerAttributeTypeRector

Expected Behavior

Rector should only replace the property type with DoctrineDocumentReference, if that class can actually be resolved.

I our project we have a custom JMS Subscribing Handler that defines the JMS type and returns a dynamic type (based on what has been serialized before).

Sample code:

class DoctrineReferenceHandler implements SubscribingHandlerInterface
{
    private const CLASS_FIELD = 'class';
    private const ID_FIELD    = 'id';

    public static function getSubscribingMethods(): array
    {
        return [
            [
                'direction' => GraphNavigatorInterface::DIRECTION_SERIALIZATION,
                'format'    => 'json',
                'type'      => 'DoctrineDocumentReference',
                'method'    => 'serialize',
            ],
            [
                'direction' => GraphNavigatorInterface::DIRECTION_DESERIALIZATION,
                'format'    => 'json',
                'type'      => 'DoctrineDocumentReference',
                'method'    => 'deserialize',
            ],
        ];
    }

   // ...
}

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions