Skip to content

BUGFIX: Fix getTagValues with comments on same line as an annotation#2615

Open
albe wants to merge 9 commits into
neos:8.2from
sorenmalling:bugfix/tag-values-issue
Open

BUGFIX: Fix getTagValues with comments on same line as an annotation#2615
albe wants to merge 9 commits into
neos:8.2from
sorenmalling:bugfix/tag-values-issue

Conversation

@albe

@albe albe commented Nov 1, 2021

Copy link
Copy Markdown
Contributor

Related to #2612

@albe

albe commented Nov 9, 2021

Copy link
Copy Markdown
Contributor Author

TODO: Add test cases from #2612 (comment) and make tests pass

@albe albe self-assigned this Nov 9, 2021
Comment thread Neos.Flow/Tests/Unit/Reflection/Fixture/ClassWithAnnotatedMethod.php Outdated
Comment thread Neos.Flow/Tests/Unit/Reflection/MethodReflectionTest.php Outdated
Comment thread Neos.Flow/Tests/Unit/Reflection/MethodReflectionTest.php Outdated
@albe

albe commented Nov 20, 2021

Copy link
Copy Markdown
Contributor Author

@sorenmalling I somehow can't commit the suggestions in the comments above - can you do this? Otherwise I'll redo those changes in my local branch

Co-authored-by: Alexander Berl <a.berl@outlook.com>
@sorenmalling

Copy link
Copy Markdown
Contributor

@sorenmalling I somehow can't commit the suggestions in the comments above - can you do this? Otherwise I'll redo those changes in my local branch

Done, and tests are running

Comment thread Neos.Flow/Tests/Unit/Reflection/MethodReflectionTest.php Outdated
sorenmalling and others added 3 commits November 23, 2021 11:58
Co-authored-by: Alexander Berl <a.berl@outlook.com>
BUGFIX: Parse tags and annotations correctly for reflection
{
$tagAndValue = [];
if (preg_match('/@[A-Za-z0-9\\\\]+\\\\([A-Za-z0-9]+)(?:\\((.*)\\))?$/', $line, $tagAndValue) === 0) {
if (preg_match('/(@[A-Za-z0-9\\\\]+\\\\[A-Za-z0-9]+)(?:(?:\\(|\s)([^\)]*))?/', $line, $tagAndValue) === 0) {

@albe albe Nov 24, 2021

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.

This regex captures the test cases in the discussion above, but will blow up if there's a round bracket in the annotation args or comment.

So we should add test cases for at least:

@something("foo()") => ['something' => 'foo()']

@something do not call foo() ever, it's bad => ['something' => 'do not call foo() ever, it\'s bad']

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.

Phew… those seem far-fetched. Then again, could happen, of course.

Comment thread Neos.Flow/Tests/Unit/Reflection/MethodReflectionTest.php Outdated
Co-authored-by: Alexander Berl <a.berl@outlook.com>
Comment thread Neos.Flow/Tests/Unit/Reflection/Fixture/ClassWithAnnotatedMethod.php Outdated
…od.php

Co-authored-by: Alexander Berl <a.berl@outlook.com>
@kdambekalns kdambekalns changed the title TASK: Add test for comments on same line as an annotation TASK: Fix getTagValues with comments on same line as an annotation Dec 22, 2021
@kdambekalns
kdambekalns changed the base branch from master to 7.2 December 22, 2021 07:46
@kdambekalns
kdambekalns changed the base branch from 7.2 to master December 22, 2021 07:46
@kdambekalns

Copy link
Copy Markdown
Member

I think this should go into 7.2 as a BUGFIX, no?

@kdambekalns kdambekalns changed the title TASK: Fix getTagValues with comments on same line as an annotation BUGFIX: Fix getTagValues with comments on same line as an annotation Dec 22, 2021
@mhsdesign

Copy link
Copy Markdown
Member

Ha funny thing. This topic still exists and @kitsunet and me lately had fun with #3520

Id say our tag parsing is a hopeless situation and we should deprecate tags. Doctrines annotation parser and php attributes are way more stable. So we should instead deprecate tags and go though the codebase and allow everywhere also fully namespaced annotations/attributes.

We could also do it one fix at a time and eventually finish as well ^^ See #3559

CC @sorenmalling

@kitsunet

Copy link
Copy Markdown
Member

Yeah I think so too. I added another one to the list :D

#3561

And we should probably deprecate tags for 9.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The result of MethodRefelection::getTagValues() changed from Neos 7.1 to Neos 7.2

5 participants