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

PhpDocExtractor::getTypes() throws fatal error when type omitted #25947

Closed
wants to merge 2 commits into from

Conversation

userdude
Copy link

Q A
Branch? 3.2
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets
License MIT
Doc PR

When omitting a type in a DocBlock Tag, it will throw a fatal error due to the type being null with a call to $tag->getType().

@magnusnordlander
Copy link
Contributor

I've worked with @userdude on this issue, so I won't change the status, but I too have experienced this bug and I can attest that this solution fixes it.

@derrabus
Copy link
Member

This fix needs to go into the 3.3 branch. 3.2 is EOL.

@nicolas-grekas nicolas-grekas added this to the 3.3 milestone Jan 29, 2018
@@ -128,7 +128,9 @@ public function getTypes($class, $property, array $context = array())
$types = array();
/** @var DocBlock\Tags\Var_|DocBlock\Tags\Return_|DocBlock\Tags\Param $tag */
foreach ($docBlock->getTagsByName($tag) as $tag) {
$types = array_merge($types, $this->phpDocTypeHelper->getTypes($tag->getType()));
if ($tag && null !== $tag->getType()) {
$types = array_merge($types, $this->phpDocTypeHelper->getTypes($tag->getType()));
Copy link
Contributor

Choose a reason for hiding this comment

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

The bug doest not exists in 2.7 ?

Copy link
Author

@userdude userdude Jan 29, 2018

Choose a reason for hiding this comment

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

It looks like PhpDocExtractor was added in 2.8, and at that time it handled nulls (albeit differently).

f1eb185#diff-72b9199530f645acef692f3d77d4de4dR84

Copy link
Member

Choose a reason for hiding this comment

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

It may be a good idea to send an extra PR that adds this test case to the 2.8 branch to prevent regressions there.

@xabbuh xabbuh modified the milestones: 3.3, 3.4 Jan 29, 2018
@xabbuh
Copy link
Member

xabbuh commented Jan 29, 2018

moving to the 3.4 milestone as the last bugfix release for 3.3 was published today

@stof stof changed the base branch from 3.2 to 3.4 January 29, 2018 16:28
@stof stof changed the base branch from 3.4 to 3.2 January 29, 2018 16:28
@userdude userdude changed the base branch from 3.2 to 3.4 February 2, 2018 15:36
@userdude
Copy link
Author

userdude commented Feb 2, 2018

Rebased to 3.4, will try to add the 2.8 regression test as a separate PR but will be next week.

class OmittedParamTagTypeDocBlock
{
/**
* @param $omittedTagType
Copy link
Member

Choose a reason for hiding this comment

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

please remove this docblock, it's not needed

Copy link
Contributor

Choose a reason for hiding this comment

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

It's very much needed; it's the entire point of the test. Currently the PhpDocExtractor throws a fatal error when getting the type from a PHPDoc tag like this one.

Copy link
Contributor

Choose a reason for hiding this comment

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

I believe a comment explaining the point would be valuable here, to prevent somebody "fixing" it later :)

@fabpot
Copy link
Member

fabpot commented Feb 7, 2018

Thank you @userdude.

fabpot added a commit that referenced this pull request Feb 7, 2018
…mitted (Jared Farrish)

This PR was squashed before being merged into the 3.4 branch (closes #25947).

Discussion
----------

PhpDocExtractor::getTypes() throws fatal error when type omitted

| Q             | A
| ------------- | ---
| Branch?       | 3.2
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT
| Doc PR        |

When omitting a type in a `DocBlock` `Tag`, it will throw a fatal error due to the type being null with a call to `$tag->getType()`.

Commits
-------

54253ec PhpDocExtractor::getTypes() throws fatal error when type omitted
@fabpot fabpot closed this Feb 7, 2018
This was referenced Mar 1, 2018
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.

None yet