Skip to content
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

@note annotation causes error from Doctrine #40

Open
jtheuerkauf opened this issue Feb 6, 2024 · 3 comments
Open

@note annotation causes error from Doctrine #40

jtheuerkauf opened this issue Feb 6, 2024 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@jtheuerkauf
Copy link

Among the changes in this commit are some annotations in the PhpDoc comments. The @note annotation is throwing errors during configure:

With:

/**
 * Create many entities with persisting them to the database.
 *
 * @param bool|null $cleanHeap Clean the heap after creating entities.
 *
 * @note To change the default value use {@see static::$cleanHeap} property.
 */

produces:

[Spiral\Attributes\Exception\SemanticAttributeException]
[Semantical Error] The annotation "@note" in method Spiral\DatabaseSeeder\Factory\AbstractFactory::create() was never imported. Did you maybe forget to add a "use" statement for this annotation?
in vendor/spiral/attributes/src/Internal/DoctrineAnnotationReader.php:87

Previous: [Doctrine\Common\Annotations\AnnotationException]
[Semantical Error] The annotation "@note" in method Spiral\DatabaseSeeder\Factory\AbstractFactory::create() was never imported. Did you maybe forget to add a "use" statement for this annotation?
in vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationException.php:36

Removing @note:

/**
 * Create many entities with persisting them to the database.
 *
 * @param bool|null $cleanHeap Clean the heap after creating entities.
 *
 * To change the default value use {@see static::$cleanHeap} property.
 */

stops the error from occurring.


i presume the same will be true of the createOne() method.

i'm happy to submit a change for these, if someone wants to offer an alternate annotation, or make the call to just remove @note from the remark...

Suggestions?

@jtheuerkauf
Copy link
Author

(FWIW, my opinion is remove the annotation and combine the description with the method description:

/**
 * Create many entities with persisting them to the database.
 * To change the default value use {@see static::$cleanHeap} property.
 *
 * @param bool|null $cleanHeap Clean the heap after creating entities.
 */

It's not a valid annotation anyway, as far as i can tell.

jtheuerkauf added a commit to jtheuerkauf/spiral-database-seeder that referenced this issue Feb 6, 2024
@butschster
Copy link
Member

Exceptions stemming from Doctrine annotations are a common issue. The optimal solution involves configuring Doctrine to ignore specific annotations.

This can be achieved with the following line of code:

\Doctrine\Common\Annotations\AnnotationReader::addGlobalIgnoredName('note');

This code snippet should be inserted into a bootloader to guarantee its execution at an early stage in the application's lifecycle. Ensure that this bootloader is positioned at the beginning of the system's bootloader section for optimal effectiveness.

@butschster butschster self-assigned this Feb 6, 2024
@butschster butschster added the bug Something isn't working label Feb 6, 2024
@jtheuerkauf
Copy link
Author

jtheuerkauf commented Feb 6, 2024

Good to know, thanks for that!

Obviously, comments shouldn't have to be scrutinized for functional impact, but here we are.

It seems to me that if the code involved (AbstractFactory) must be parsed by Doctrine, then complying with supported PHPDoc syntax/tags is preferable to adding the functional overhead of a workaround.

(Especially in this case where there seems to be no functional/documentation advantage to an invalid @note tag)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Todo
Development

No branches or pull requests

2 participants