-
Notifications
You must be signed in to change notification settings - Fork 121
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
Release 5.4.0 does not add our phpstan tags #365
Comments
I'm sorry I don't get your question. Can you explain what you are trying to do? |
For years, up to v5.3.0 we were adding What should I do to start resolving this? |
I do not know how to start debugging. |
This library doesn't support the @phpstan- tags. They are handled as generic tags. I don't know how your code works nor I have the time to dive into a project consuming this library. Right now I do not have a clue what the impact of our changes are on your code without debugging it. Which is the same thing you are doing? |
We are adding a node visitor to nikic/php-parser and when there is a need we add tags to an existing AST. We are adding/creating tags, not parsing them. |
Only thing that could happen is that you have a newer version of php parser. Nothing has been changed on this side regarding tag creation as far as I know. |
The referenced issue is closed, I do not see a need to research this more. If you need any assistance feel free to reopen this issue or create a new one |
@jaapio The referenced issue wasn't closed because the issue reported here has already been resolved. Meanwhile, I was able to find that tag descriptions change significantly when updating from v5.3.0 to v5.4.0, resulting in code that relies on the description to fail. Here's an example
Description of
Description of
|
The problem arises from "empty" lines. require_once 'vendor/autoload.php';
use phpDocumentor\Reflection\DocBlockFactory;
use phpDocumentor\Reflection\DocBlock\Serializer;
$docComment = '/**
* Example.
*
* @param array $single Single line description.
* @param array $multi1 Description with two lines.
* line 2/2
* @param array $multi2 Description with three lines.
* line 2/3
* line 3/3
* @param array $multi3 Description with curly braces and three lines {
* line 2/3
* line 3/3
* }
* @param array $empty1 Description with curly braces and empty line {
*
* below empty line
* }
* @param array $empty2 Description with empty
*
* below empty line
*/';
$factory = DocBlockFactory::createInstance();
$docblock = $factory->create($docComment);
$paramTags = $docblock->getTagsByName('param');
$serializer = new Serializer(0, '',true, null, null, PHP_EOL);
echo $serializer->getDocComment($docblock); now gives
while it was
in v5.3.0. |
I'm investigating this, it will take some time as it is a limitation of the phpstan parser. It stops when descriptions span over multiple lines but also when it detects and @ |
Thank you! |
The phpstan parser is not consuming the full description when parsing docblocks with a more complex description. For them it's mostlikely not an issue as phpstan doesn't use the descriptions. But it will also parse the descriptions into unexpected tags. This could be an advantage but is not according to the phpdoc spec. Our own tokenizer is already tokenizing the docblocks into the correct parts. So all we needed to do is assume all remaining tokens in the phpstan ast belong to the description. From there our own code is able to handle this as before in v5.3. fixes #365
The phpstan parser is not consuming the full description when parsing docblocks with a more complex description. For them it's mostlikely not an issue as phpstan doesn't use the descriptions. But it will also parse the descriptions into unexpected tags. This could be an advantage but is not according to the phpdoc spec. Our own tokenizer is already tokenizing the docblocks into the correct parts. So all we needed to do is assume all remaining tokens in the phpstan ast belong to the description. From there our own code is able to handle this as before in v5.3. fixes #365
I took your first example to reproduce the issue and added it to our test suite. It would be nice if you are able to check the new version before I create a new tag. Thanks for your bug report this will help a lot of people! |
You're welcome. Here it is php-stubs/wordpress-stubs#174 |
Thank you for the rapid solution once we came up with a reproducible example! For php-stubs/wordpress-stubs, we still see some differences compared to v5.3.0, though they are now far fewer in number. I'll try to pinpoint those, but I can only do so tomorrow. |
Ok, I managed to do it now. The remaining differences are due to variations in the handling of spaces/indentation. We rely on the doc comment to adhere to the WordPress coding standards, specifically looking for indentation that consists of 4 spaces or a multiple thereof. In v5.4.0, the indentation is no longer part of the sequence of multiples of 4. Therefor our visitor no longer recognizes the Original ( /**
* Registers the script module if no script module with that script module
* identifier has already been registered.
*
* @since 6.5.0
*
* @param string $id The identifier of the script module. Should be unique. It will be used in the
* final import map.
* @param string $src Optional. Full URL of the script module, or path of the script module relative
* to the WordPress root directory. If it is provided and the script module has
* not been registered yet, it will be registered.
* @param array $deps {
* Optional. List of dependencies.
*
* @type string|array ...$0 {
* An array of script module identifiers of the dependencies of this script
* module. The dependencies can be strings or arrays. If they are arrays,
* they need an `id` key with the script module identifier, and can contain
* an `import` key with either `static` or `dynamic`. By default,
* dependencies that don't contain an `import` key are considered static.
*
* @type string $id The script module identifier.
* @type string $import Optional. Import type. May be either `static` or
* `dynamic`. Defaults to `static`.
* }
* }
* @param string|false|null $version Optional. String specifying the script module version number. Defaults to false.
* It is added to the URL as a query string for cache busting purposes. If $version
* is set to false, the version number is the currently installed WordPress version.
* If $version is set to null, no version is added.
*/ v5.3.0 [2]=>
object(phpDocumentor\Reflection\DocBlock\Tags\Param)#28 (6) {
["variableName":"phpDocumentor\Reflection\DocBlock\Tags\Param":private]=>
string(4) "deps"
["isVariadic":"phpDocumentor\Reflection\DocBlock\Tags\Param":private]=>
bool(false)
["isReference":"phpDocumentor\Reflection\DocBlock\Tags\Param":private]=>
bool(false)
["type":protected]=>
object(phpDocumentor\Reflection\Types\Array_)#29 (3) {
["valueType":protected]=>
object(phpDocumentor\Reflection\Types\Mixed_)#30 (0) {
}
["keyType":protected]=>
NULL
["defaultKeyType":protected]=>
object(phpDocumentor\Reflection\Types\Compound)#31 (2) {
["types":"phpDocumentor\Reflection\Types\AggregatedType":private]=>
array(2) {
[0]=>
object(phpDocumentor\Reflection\Types\String_)#32 (0) {
}
[1]=>
object(phpDocumentor\Reflection\Types\Integer)#33 (0) {
}
}
["token":"phpDocumentor\Reflection\Types\AggregatedType":private]=>
string(1) "|"
}
}
["name":protected]=>
string(5) "param"
["description":protected]=>
object(phpDocumentor\Reflection\DocBlock\Description)#27 (2) {
["bodyTemplate":"phpDocumentor\Reflection\DocBlock\Description":private]=>
string(668) "{
Optional. List of dependencies.
@type string|array ...$0 {
An array of script module identifiers of the dependencies of this script
module. The dependencies can be strings or arrays. If they are arrays,
they need an `id` key with the script module identifier, and can contain
an `import` key with either `static` or `dynamic`. By default,
dependencies that don't contain an `import` key are considered static.
@type string $id The script module identifier.
@type string $import Optional. Import type. May be either `static` or
`dynamic`. Defaults to `static`.
}
}"
["tags":"phpDocumentor\Reflection\DocBlock\Description":private]=>
array(0) {
}
}
} v5.4.0 [2]=>
object(phpDocumentor\Reflection\DocBlock\Tags\Param)#42 (6) {
["variableName":"phpDocumentor\Reflection\DocBlock\Tags\Param":private]=>
string(4) "deps"
["isVariadic":"phpDocumentor\Reflection\DocBlock\Tags\Param":private]=>
bool(false)
["isReference":"phpDocumentor\Reflection\DocBlock\Tags\Param":private]=>
bool(false)
["type":protected]=>
object(phpDocumentor\Reflection\Types\Array_)#43 (3) {
["valueType":protected]=>
object(phpDocumentor\Reflection\Types\Mixed_)#44 (0) {
}
["keyType":protected]=>
NULL
["defaultKeyType":protected]=>
object(phpDocumentor\Reflection\Types\Compound)#45 (2) {
["types":"phpDocumentor\Reflection\Types\AggregatedType":private]=>
array(2) {
[0]=>
object(phpDocumentor\Reflection\Types\String_)#46 (0) {
}
[1]=>
object(phpDocumentor\Reflection\Types\Integer)#47 (0) {
}
}
["token":"phpDocumentor\Reflection\Types\AggregatedType":private]=>
string(1) "|"
}
}
["name":protected]=>
string(5) "param"
["description":protected]=>
object(phpDocumentor\Reflection\DocBlock\Description)#48 (2) {
["bodyTemplate":"phpDocumentor\Reflection\DocBlock\Description":private]=>
string(1049) "{
Optional. List of dependencies.
@type string|array ...$0 {
An array of script module identifiers of the dependencies of this script
module. The dependencies can be strings or arrays. If they are arrays,
they need an `id` key with the script module identifier, and can contain
an `import` key with either `static` or `dynamic`. By default,
dependencies that don't contain an `import` key are considered static.
@type string $id The script module identifier.
@type string $import Optional. Import type. May be either `static` or
`dynamic`. Defaults to `static`.
}
}"
["tags":"phpDocumentor\Reflection\DocBlock\Description":private]=>
array(0) {
}
}
} |
It seems that the new parser is automatically trimming the white space from the description. But as does this only for the first lines the white space trimming of our description factory doesn't work anymore. So my initial fix isn't complete. I'm still searching for a good solution. |
I pushed a very ugly hack to see if this solves the issues you are facing in a separate branch. It would be very nice to get some feedback on that to see if it completely solves your issues before I dive into the phpstan code to see what is wrong and how to solve this. |
Unfortunately, things have worsened again. One cause seems to be that the hack adds unexpected new lines.
becomes
|
Ok, but do you see your tags again? I assume that the extra white lines are not breaking the visitor. |
@IanDelMar I did try another deep dive into this issue and found a better solution. Which makes the second test pass. |
Sorry, I have been quite busy.
That's exactly what's happening. The tags are disappearing again. While this could probably be fixed in our visitor, it is still a breaking change for our case. I'll have a look at #370 on the weekend. |
Great! will merge and tag a new version |
We are adding phpstan tags to WordPress core stubs.
https://github.com/php-stubs/wordpress-stubs/blob/master/visitor.php
After upgrading to v5.4.0 we don't see our tags.
How to proceed?
The text was updated successfully, but these errors were encountered: