Skip to content

ImportFullyQualifiedNamesRector breaks Doctrine annotations #2110

@gnutix

Description

@gnutix
Subject Details
PHP version PHP 7.3.9-1+ubuntu18.04.1+deb.sury.org+1 (cli) (built: Sep 2 2019 12:54:24) ( NTS )
Full Command vendor/bin/rector --dry-run process src/Entity/Page/Template.php

Current Behaviour

I've noticed two more errors when running ImportFullyQualifiedNamesRector on our codebase :

  1. inverseJoinColumns -> @ORM\JoinColumn -> name is modified to match the one in joinColumns -> @ORM\JoinColumn -> name (which is wrong, it should be different)
  2. The indentation is broken and the doc block's * characters are missing
Rector dev-master@c378a44
Config file: rector.yaml

 3/3 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%

1 file with changes
===================

1) src/Entity/Page/Template.php

    ---------- begin diff ----------
--- Original
+++ New
@@ -34,14 +34,16 @@
     private $name;

     /**
-     * @var Area[]|Collection
-     *
-     * @ORM\ManyToMany(targetEntity="Area", cascade={"remove", "persist"}, inversedBy="templates")
-     * @ORM\JoinTable(name="page_template_area",
-     *      joinColumns={@ORM\JoinColumn(name="template_id", referencedColumnName="id", onDelete="CASCADE")},
-     *      inverseJoinColumns={@ORM\JoinColumn(name="area_id", referencedColumnName="id")}
-     * )
-     */
+    * @var Area[]|Collection
+    *
+    * @ORM\ManyToMany(targetEntity="Area", cascade={"remove", "persist"}, inversedBy="templates")
+    * @ORM\JoinTable(name="page_template_area", joinColumns={
+        @ORM\JoinColumn(name="template_id", referencedColumnName="id", onDelete="CASCADE")
+    }, inverseJoinColumns={
+        @ORM\JoinColumn(name="template_id", referencedColumnName="id")
+    }
+    )
+    */
     private $areas;

     /**
    ----------- end diff -----------

Applied rectors:

 * Rector\CodingStyle\Rector\Namespace_\ImportFullyQualifiedNamesRector

With rector.yaml as follow :

services:
    Rector\CodingStyle\Rector\Namespace_\ImportFullyQualifiedNamesRector: ~

And Template.php as follow :

<?php

declare(strict_types=1);

namespace App\Entity\Page;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;

/**
 * Template
 *
 * @ORM\Table(name="page_template")
 * @ORM\Entity()
 */
class Template
{
    /**
     * @var int
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @var string
     *
     * @ORM\Column(name="name", type="string", length=255, unique=true)
     */
    private $name;

    /**
     * @ORM\ManyToOne(targetEntity="Site")
     * @ORM\JoinColumn(name="site_id", referencedColumnName="id", onDelete="CASCADE")
     */
    private $site;

    public function __construct()
    {
        $this->areas = new ArrayCollection();
    }

    public function getId(): ?int
    {
        return $this->id;
    }

    public function setName(?string $name): self
    {
        $this->name = $name;

        return $this;
    }

    public function getName(): ?string
    {
        return $this->name;
    }

    public function addArea(Area $area): self
    {
        $this->areas[] = $area;

        return $this;
    }

    public function removeArea(Area $area): self
    {
        $this->areas->removeElement($area);

        return $this;
    }

    /**
     * @return Area[]|Collection
     */
    public function getAreas()
    {
        return $this->areas;
    }
}

I've tried adding the Template.php file as a test case on ImportFullyQualifiedNamesRectorTest, but it passed... :/ I'll try to debug it and provide you more information ASAP.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions