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

[property-info] Detect invalid tags and throw error accordingly #36850

Closed
wants to merge 4 commits into from
Closed

[property-info] Detect invalid tags and throw error accordingly #36850

wants to merge 4 commits into from

Conversation

drupol
Copy link
Contributor

@drupol drupol commented May 18, 2020

Q A
Branch? 3.4
Bug fix? yes
New feature? no
Deprecations? no
Tickets Fix #36049 and api-platform/core#3565
License MIT

I'm doing this as a work in progress.

This PR:

  • Update composer.json and support phpdocumentor/reflection-docblock version ^3, ^4 and ^5.
  • Add a new test to check if an invalid tag returns the proper exception
  • Tests are passing when building with lowest deps (I don't know how to deal with that yet)
  • Tests are passing using highest deps

Questions:

  1. How to deal with the test when the InvalidTag class is not available ?
  2. Throwing an exception might be a BC break
  3. If instead of throwing an InvalidArgumentException, we ignore it, then the following tests are failing:
1) Symfony\Component\PropertyInfo\Tests\Extractor\PhpDocExtractorTest::testExtract with data set #27 ('emptyVar', null, null, null)

Error: Call to undefined method phpDocumentor\Reflection\DocBlock\Tags\InvalidTag::getType()

/home/devlin/dev/git/symfony/src/Symfony/Component/PropertyInfo/Extractor/PhpDocExtractor.php:151
/home/devlin/dev/git/symfony/src/Symfony/Component/PropertyInfo/Tests/Extractor/PhpDocExtractorTest.php:40

@drupol
Copy link
Contributor Author

drupol commented May 18, 2020

@nicolas-grekas Hi! Should I rebase this for branch 4.4 ?

@nicolas-grekas
Copy link
Member

nicolas-grekas commented May 18, 2020

Should I rebase this for branch 4.4 ?

this looks like a bug fix to me, so yes please. Check 3.4 before, in case it makes sense on 3.4.

@drupol drupol changed the base branch from master to 3.4 May 18, 2020 10:43
@nicolas-grekas nicolas-grekas modified the milestones: 4.4, 3.4 May 18, 2020
composer.json Outdated
@@ -100,7 +100,7 @@
"egulias/email-validator": "~1.2,>=1.2.8|~2.0",
"symfony/phpunit-bridge": "^3.4.31|^4.3.4|~5.0",
"symfony/security-acl": "~2.8|~3.0",
"phpdocumentor/reflection-docblock": "^3.0|^4.0"
"phpdocumentor/reflection-docblock": "^3.0||^4.0||^5.0"
Copy link
Member

Choose a reason for hiding this comment

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

please use a single | for consistency

@nicolas-grekas
Copy link
Member

Tests are passing using highest deps

not the case anymore, failures are on all jobs :)

@@ -83,6 +83,10 @@ public function getShortDescription($class, $property, array $context = [])
}

foreach ($docBlock->getTagsByName('var') as $var) {
if (is_a($var, 'phpDocumentor\Reflection\DocBlock\Tags\InvalidTag')) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if (is_a($var, 'phpDocumentor\Reflection\DocBlock\Tags\InvalidTag')) {
if (is_a($var, InvalidTag::class)) {

(add the appropriate use too)

Copy link
Contributor

Choose a reason for hiding this comment

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

The InvalidTag is introduced in v5 of phpdocumentor/reflection-docblock. A use statement would be a BC break with v3 and v4 since those are autoloaded?

Copy link
Member

Choose a reason for hiding this comment

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

no. Use statements don't imply that a class exist. And ::class does not either (it is not an actual constant access on the class, but a compile-time thing)

Copy link
Contributor

Choose a reason for hiding this comment

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

Ha I did't know that.

@@ -137,6 +141,10 @@ public function getTypes($class, $property, array $context = [])
$types = [];
/** @var DocBlock\Tags\Var_|DocBlock\Tags\Return_|DocBlock\Tags\Param $tag */
foreach ($docBlock->getTagsByName($tag) as $tag) {
if (is_a($tag, 'phpDocumentor\Reflection\DocBlock\Tags\InvalidTag')) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if (is_a($tag, 'phpDocumentor\Reflection\DocBlock\Tags\InvalidTag')) {
if (is_a($tag, InvalidTag::class)) {

@@ -137,6 +141,10 @@ public function getTypes($class, $property, array $context = [])
$types = [];
/** @var DocBlock\Tags\Var_|DocBlock\Tags\Return_|DocBlock\Tags\Param $tag */
foreach ($docBlock->getTagsByName($tag) as $tag) {
if (is_a($tag, 'phpDocumentor\Reflection\DocBlock\Tags\InvalidTag')) {
return null;
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we throw here too?

Copy link
Contributor

Choose a reason for hiding this comment

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

Throwing here would break applications with invalid docblocks.

@nicolas-grekas
Copy link
Member

Closing in favor of #36975, thanks @drupol

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.

[PropertyInfo] Not compatible with phpDocumentor v5
7 participants