Search code examples
doctrinecommand-line-interfacemany-to-onesymfony4

Symfony 4 and Doctrine - Why is Doctirne generating multiple declarations of an `$__EXTRA_LINE` variable?


I'm generating a ManyToOne association on entities that already exist using the Doctrine CLI.

The generated code is dropping in multiple declarations of a variable $__EXTRA_LINE which is not even being called from the class with $this->.

This is obviously causing an error when calling php bin/console make:migration or running the script due to multiple declarations, and also errors due to undefined variables in the functions (not using $this-> on in the function body).

Generated code is as follows:

private $__EXTRA__LINE; // 1
/**
* @return Collection|JobInvoice[]
*/
public function getJobInvoices(): Collection
{
    return $this->job_invoices;
}
private $__EXTRA__LINE; // 2
public function addJobInvoice(JobInvoice $jobInvoice): self
{
    if (!$this->job_invoices->contains($jobInvoice)) {
        $this->job_invoices[] = $jobInvoice;
        $jobInvoice->setInvoice($this);
    }
    $__EXTRA__LINE; // no '$this->'
    return $this;
}
private $__EXTRA__LINE; // 3
public function removeJobInvoice(JobInvoice $jobInvoice): self
{
    if ($this->job_invoices->contains($jobInvoice)) {
        $this->job_invoices->removeElement($jobInvoice);

        // set the owning side to null (unless already changed)
        if ($jobInvoice->getInvoice() === $this) {
         $jobInvoice->setInvoice(null);
        }
    }
    $__EXTRA__LINE; // no '$this->'
    return $this;
}

What could be cause this error or is not an error and is it happening for a reason that is important for this ManyToOne to work?


Solution

  • I found the vendor folder in the project:

        // this fake property is a placeholder for a linebreak
        $newCode = str_replace('    private $__EXTRA__LINE;', '', $newCode);
    
        /vendor/symfony/maker-bundle/src/Util/ClassSourceManipulator.php line 611
    

    maybe it helps you