Skip to content

Update AnnotationReader's metadata parser to use list of known ignored annotation #235

Merged
lcobucci merged 1 commit intodoctrine:masterfrom
sanmai:patch-1
Jan 28, 2019
Merged

Update AnnotationReader's metadata parser to use list of known ignored annotation #235
lcobucci merged 1 commit intodoctrine:masterfrom
sanmai:patch-1

Conversation

@sanmai
Copy link
Copy Markdown
Contributor

@sanmai sanmai commented Jan 23, 2019

A parser used to collect parsing metadata basically ignores a known list of globally ignored annotation names, goes through loops checking annotations that do not need any checking. Let's fix that by communicating the list during initialization.

E.g. these checks should not be evaluated for known ignored annotations:

} elseif ( ! isset($this->ignoredAnnotationNames[$name])
&& isset($this->imports['__NAMESPACE__'])
&& $this->classExists($this->imports['__NAMESPACE__'] . '\\' . $name)
) {
$name = $this->imports['__NAMESPACE__'].'\\'.$name;
$found = true;
} elseif (! isset($this->ignoredAnnotationNames[$name]) && $this->classExists($name)) {
$found = true;
}

Please let me know if this change needs a test. One way to test is to rig an additional autoloader that would fail on attempt to load a class named as one of the commonly-ignored annotations like @see.

Copy link
Copy Markdown
Member

@Ocramius Ocramius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requires test case additions, backing the OP claims.

Also needed:

  • reword issue title to match changes
  • reword commit message to contain detailed reasoning of changes

@sanmai
Copy link
Copy Markdown
Contributor Author

sanmai commented Jan 23, 2019

No problem, I'll add a test later. Meanwhile I'm open to suggestions about exact wording.

@sanmai sanmai changed the title Update AnnotationReader Update AnnotationReader's metadata parser to use list of known ignored annotation Jan 23, 2019
@sanmai
Copy link
Copy Markdown
Contributor Author

sanmai commented Jan 23, 2019

@Ocramius please see if it is better now.

Comment thread tests/Doctrine/Tests/Annotations/AbstractReaderTest.php
sanmai added a commit to sanmai/annotations that referenced this pull request Jan 23, 2019
Ocramius
Ocramius previously approved these changes Jan 23, 2019
Copy link
Copy Markdown
Member

@Ocramius Ocramius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good. @doctrine/doctrinecore can you please also check?

@Ocramius Ocramius removed the BC-Break label Jan 23, 2019
@Ocramius Ocramius added this to the 1.7.0 milestone Jan 23, 2019
alcaeus
alcaeus previously approved these changes Jan 23, 2019
Copy link
Copy Markdown
Member

@alcaeus alcaeus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch. Thanks @sanmai!

stof
stof previously approved these changes Jan 23, 2019
SenseException
SenseException previously approved these changes Jan 23, 2019
Copy link
Copy Markdown
Member

@lcobucci lcobucci left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some teeny tiny things (quite small to be honest). Nice catch indeed 👍

self::assertEmpty($reader->getPropertyAnnotations($class->getProperty('foo')));
}

public function testGloballyIgnoredAnnotationNotIgnored()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

: void missing

Copy link
Copy Markdown
Contributor Author

@sanmai sanmai Jan 24, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how's that going in line with all other code in this file. Isn't it better to put these things aside? Like there's #177 which is supposed to do exactly what you're asking, but all over all code.

Copy link
Copy Markdown
Member

@lcobucci lcobucci Jan 24, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sanmai I understand your frustration here, these are cosmetic things and don't have much impact on the behaviour of the code. However we have an agreement among maintainers to try as much as possible to make sure our CS is applied everywhere, even when the project isn't following it properly (that's why we have automated incremental checks on ORM and DBAL, for example).

We haven't had the chance of applying the incremental checks here and modifying the entire code base is a bit too much (as explained in #177), hence my comments.

I'm sorry for the confusion and will completely understand if you decide to not apply the suggestions in the comments, I'm just trying to ensure that we (Doctrine team) follow our agreements. A maintainer is able to edit your commit on your fork (if you hadn't changed the option while creating the PR).

I hope you'll understand the motivation and I thank you for your contribution.

Copy link
Copy Markdown
Contributor Author

@sanmai sanmai Jan 25, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, that's just me that spend a good amount of time to make sure that my code looks just like every other code, but if there's a consensus to write newer code in a more appropriate style, I'm good with that too. I'd change on my part but I'd like if these new guidelines would be somewhere, at least. Then anyone else wouldn't need to spend the time so useless as I did. Otherwise put, this discussion shouldn't have happen in the first place. Are we on the same page with this?

Also, all other folks now would need to review the thing again. Bummer.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lcobucci anything else?

Copy link
Copy Markdown
Member

@greg0ire greg0ire Jan 28, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd change on my part but I'd like if these new guidelines would be somewhere, at least.

I believe that one is documented here: https://www.doctrine-project.org/projects/doctrine-coding-standard/en/latest/reference/index.html#project-level-ruleset ("Always add native types where possible")

Copy link
Copy Markdown
Contributor Author

@sanmai sanmai Jan 28, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, that's not exactly obvious, what do you think? How am I supposed to find it?..

A link to these guidelines from the README.md, or even from CONTRIBUTING.md, would be best. Nevertheless, I will know better now, thanks.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you're right! I might make PRs to change that if you do not beat me to it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread tests/Doctrine/Tests/Annotations/AbstractReaderTest.php Outdated
@sanmai sanmai dismissed stale reviews from SenseException, stof, alcaeus, and Ocramius via 3eed959 January 25, 2019 03:42
Comment thread tests/Doctrine/Tests/Annotations/AbstractReaderTest.php Outdated
greg0ire
greg0ire previously approved these changes Jan 28, 2019
…d annotation

A parser used to collect parsing metadata basically ignores a known list of globally ignored annotation names, goes through loops checking annotations that do not need any checking. Let's fix that by communicating the list during initialization.
@lcobucci lcobucci self-assigned this Jan 28, 2019
@lcobucci lcobucci merged commit 21e7da9 into doctrine:master Jan 28, 2019
@lcobucci
Copy link
Copy Markdown
Member

@sanmai @Ocramius @Majkl578 @greg0ire I've found an interesting thing while backporting this to 1.7: the test passes even if $this->preParser->setIgnoredAnnotationNames(self::$globalIgnoredNames); isn't called 👍

Also interesting to mention it fails for SimpleAnnotationReaderTest, because it wrongly parses a lowercase annotation (@version).

Shall we mark it as an fix to v2.0 only?

@sanmai sanmai deleted the patch-1 branch January 29, 2019 03:26
sanmai added a commit to sanmai/annotations that referenced this pull request Jan 29, 2019
@sanmai
Copy link
Copy Markdown
Contributor Author

sanmai commented Jan 29, 2019

Actually I had this issue on a released version. Let me check what it was...

@sanmai
Copy link
Copy Markdown
Contributor Author

sanmai commented Jan 30, 2019

@lcobucci I got this fix backported to 1.6, see #240

@alcaeus alcaeus modified the milestones: v1.7.0, v1.8.0 Sep 17, 2019
alcaeus pushed a commit to alcaeus/annotations that referenced this pull request May 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants