Skip to content

Doctrine annotations analysis #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Zarganwar opened this issue Jun 22, 2017 · 5 comments
Closed

Doctrine annotations analysis #6

Zarganwar opened this issue Jun 22, 2017 · 5 comments

Comments

@Zarganwar
Copy link

Is it possible to check Doctrine Annotations or exists some extension for it?

@stesie
Copy link
Contributor

stesie commented Aug 13, 2017

What kinds of checks are you thinking of? Yet I'm not aware of another doctrine extension to PHPStan other than this one.

Me and my team actually came up with two ideas: keep @var in sync with the doctrine mapping annotations as well as ensure @JoinColumn annotation explicitly states nullable (as we stumbled over it defaulting to true multiple times). Yet both are less a topic of static code analysis, but more of sniffing for code smells.

Shameless plug: our coding standard for phpcs, which plays nicely with PHPStan (as it happily picks up the @var annotations)

@soullivaneuh
Copy link

Some samples:

/**
 * @var \DateTime
 *
 * @ORM\Column(type="date", nullable=true)
 */
private $lastInvoiceDate;

Here, it should be @var \DateTime|null because the column is nullable.

/**
 * @var Product
 *
 * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Product")
 * @ORM\JoinColumn(referencedColumnName="id")
 */
private $product;

Here too, because JoinColumn are nullable by default.

@Majkl578
Copy link
Contributor

I briefly discussed this with @ondrejmirtes and I think this should be split into two parts:

  1. generic doctrine annotations support - declaration, attributes, their attributes, project-agnostic with no explicit understanding of their purpose;
  2. annotations integration for specific project (ORM, ODM, Symfony Validator, JMS) that would understand their context and usage.

I may try to come up with something in this regard, but I'm not sure if it's not wise to wait for Annotations 2.0 which will come with better parser and PP language definition.

@ondrejmirtes
Copy link
Member

Following in #31.

@github-actions
Copy link

github-actions bot commented May 2, 2021

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 2, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants