Home Documentation Download Pricing Buy Now

Formatted PHP attributes leads to invalid PHP on next export

0 votes

We are using Prettier (with the PHP plugin) in our project, and after changing Doctrine data format from annotations to attributes in Skipper, we ran into issues. The first export from Skipper goes fine, then Prettier formats those attributes a little differently than Skipper did. They are still valid PHP after prettier formatting, but then when exporting from Skipper again, the result is a syntax error (Prettier's output of course depends on settings, but mostly I think the issue is with changing them from one single line to multiple lines, or the trailing comma).

Here's an example:

After first export from Skipper:

#[ORM\Entity(repositoryClass: "Our\AppBundle\Entity\Repository\DataRepository")]
#[ORM\Table(name: "data", options: ["collate"=>"utf8_swedish_ci"])]
class Data
{
  #[ORM\Id]
  #[ORM\ManyToOne(targetEntity: \Our\AppBundle\Entity\Document::class)]
  #[ORM\JoinColumn(name: "document", referencedColumnName: "id", nullable: false)]
  private $Document;
  // ...

After Prettier formatting:

#[
  ORM\Entity(
    repositoryClass: 'Our\AppBundle\Entity\Repository\DataRepository',
  ),
]
#[ORM\Table(name: 'data', options: ['collate' => 'utf8_swedish_ci'])]
class Data
{
  #[ORM\Id]
  #[
    ORM\ManyToOne(
      targetEntity: \Our\AppBundle\Entity\Document::class,
    ),
  ]
  #[
    ORM\JoinColumn(
      name: 'document',
      referencedColumnName: 'id',
      nullable: false,
    ),
  ]
  private $Document;
  // ...

Then exporting from Skipper again (without any schema changes):

#[, ORM\Entity(repositoryClass: "Our\AppBundle\Entity\Repository\DataRepository")]
#[ORM\Table(name: "data", options: ["collate"=>"utf8_swedish_ci"])]
class Data
{
  #[]
  #[, ORM\Id]
  #[ORM\ManyToOne(targetEntity: \Our\AppBundle\Entity\Document::class), ORM\JoinColumn(name: "document", referencedColumnName: "id", nullable: false)]
  private $Document;
  // ...

And that PHP file is invalid and causes syntax error when trying to run the app. Of course Skipper doesn't need to know how to output similar formatting as Prettier, but the expected result would be that when nothing has been changed, then Skipper export doesn't modify the files. And when something has been changed, it can output same way that it originally did, and any formatting on that can be done after the export.

Skipper version is the latest (3.5.0.1878)

asked 1 day ago in Bug report by cvuorinen (340 points)
edited 1 day ago by cvuorinen

thank you for the report. Can you please send my skipper project + before/after php file where we can simulate this issue? Please send it to [email protected]

Thank you

Please log in or register to answer this question.

...