-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Debug] Detect virtual methods using @method #28902
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
Conversation
No, the idea of |
And only interface-level annotations should be considered IMO. Class-level |
I've updated the regex for See https://regex101.com/r/Jw5R11/1 i think this is sufficient to move forward. |
continue; | ||
} | ||
|
||
if (false !== \strpos($doc, $annotation) && preg_match_all('#\n \* @'.$annotation.'(?:( .+?)\.?)(?=\r?\n \*(?: @|/$|\r?\n))#s', $doc, $notice)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should look for @method
here, not for method
@@ -223,7 +224,19 @@ public function checkAnnotations(\ReflectionClass $refl, $class) | |||
|
|||
// Detect annotations on the class | |||
if (false !== $doc = $refl->getDocComment()) { | |||
foreach (array('final', 'deprecated', 'internal') as $annotation) { | |||
foreach (array('final', 'deprecated', 'internal', 'method') as $annotation) { | |||
if ('method' === $annotation) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as the implementation for @method
is entirely different, I would not put it in the foreach (array('final', 'deprecated', 'internal') as $annotation) {
. Put a separate block of code before or after the loop with the different handling.
This is fun :) I think i got to the tricky part, so last commit needs review :) deprecations so far:
|
The issue is with |
abstract classes should be excluded from this check, as it is fine for them to provide incomplete implementations of an interface (a child class extending them would complain about the missing method). |
I think it works correct now 🎉 |
@@ -249,6 +267,9 @@ public function checkAnnotations(\ReflectionClass $refl, $class) | |||
if (!isset(self::$checkedClasses[$use])) { | |||
$this->checkClass($use); | |||
} | |||
if ($refl->isAbstract() && isset(self::$method[$use])) { | |||
self::$method[$refl->name][] = $use; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so self::$method
stores @methods
per interface, or interfaces per abstract, and is resolved below as such. This way we preserve the original interface name. At least that's how i intended it :)
@@ -249,6 +267,9 @@ public function checkAnnotations(\ReflectionClass $refl, $class) | |||
if (!isset(self::$checkedClasses[$use])) { | |||
$this->checkClass($use); | |||
} | |||
if ($refl->isAbstract() && isset(self::$method[$use])) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
operands should be swapped for performance
https://github.com/nrk/predis/blob/v1.1/src/ClientInterface.php#L27 makes test fail, something wrong with description parsing but more important, it made me discover we should skip the deprecration if edit: ready! |
From phpDocumentor/phpDocumentor#1855 i discovered we might be able to support Do we want to include it in this PR? Support it even? |
Turns out it's supported as of phpdoc3 (https://github.com/phpDocumentor/phpDocumentor2/blob/v3.0.0-alpha1/docs/references/phpdoc/tags/method.rst) I haven tested phpstorm yet, but if it works we might want to have a future proof implementation. IF virtual statics are worth it :) |
It's a few keystrokes away, isn't it? Let's do it :) |
https://regex101.com/r/XLHqy5/3/ i made this :D |
This PR was squashed before being merged into the 4.1 branch (closes #28915). Discussion ---------- [Config] Fix @method annotation | Q | A | ------------- | --- | Branch? | 4.1 | Bug fix? | yes | New feature? | no | BC breaks? | no <!-- see https://symfony.com/bc --> | Deprecations? | no | Tests pass? | yes <!-- please add some, will be required by reviewers --> | Fixed tickets | #... <!-- #-prefixed issue number(s), if any --> | License | MIT | Doc PR | symfony/symfony-docs#... <!-- required for new features --> ``` @method [[static] return type] [name]([[type] [parameter]<, ...>]) [<description>] ``` I dont think this was intended to be the method description, which will be taken into account after #28902 Let me know if there's a better description, other then `Gets the child node definitions` :) Commits ------- 0d7a961 [Config] Fix @method annotation
This PR was squashed before being merged into the 4.2-dev branch (closes #28916). Discussion ---------- [Form] Fix @method annotation | Q | A | ------------- | --- | Branch? | master | Bug fix? | yes | New feature? | no | BC breaks? | no <!-- see https://symfony.com/bc --> | Deprecations? | no | Tests pass? | yes <!-- please add some, will be required by reviewers --> | Fixed tickets | #... <!-- #-prefixed issue number(s), if any --> | License | MIT | Doc PR | symfony/symfony-docs#... <!-- required for new features --> Same as #28915 for 4.2 (these are the only occurrences for interfaces) Actually provides a use case for symfony/symfony#28902 (comment) 🎉 Commits ------- 13f0db718e [Form] Fix @method annotation
This PR was squashed before being merged into the 4.2-dev branch (closes #28916). Discussion ---------- [Form] Fix @method annotation | Q | A | ------------- | --- | Branch? | master | Bug fix? | yes | New feature? | no | BC breaks? | no <!-- see https://symfony.com/bc --> | Deprecations? | no | Tests pass? | yes <!-- please add some, will be required by reviewers --> | Fixed tickets | #... <!-- #-prefixed issue number(s), if any --> | License | MIT | Doc PR | symfony/symfony-docs#... <!-- required for new features --> Same as #28915 for 4.2 (these are the only occurrences for interfaces) Actually provides a use case for #28902 (comment) 🎉 Commits ------- 13f0db7 [Form] Fix @method annotation
This PR was squashed before being merged into the 4.1 branch (closes symfony#28915). Discussion ---------- [Config] Fix @method annotation | Q | A | ------------- | --- | Branch? | 4.1 | Bug fix? | yes | New feature? | no | BC breaks? | no <!-- see https://symfony.com/bc --> | Deprecations? | no | Tests pass? | yes <!-- please add some, will be required by reviewers --> | Fixed tickets | #... <!-- #-prefixed issue number(s), if any --> | License | MIT | Doc PR | symfony/symfony-docs#... <!-- required for new features --> ``` @method [[static] return type] [name]([[type] [parameter]<, ...>]) [<description>] ``` I dont think this was intended to be the method description, which will be taken into account after symfony#28902 Let me know if there's a better description, other then `Gets the child node definitions` :) Commits ------- 0d7a961 [Config] Fix @method annotation
Ready :) Status: needs review |
Thank you @ro0NL. |
This PR was squashed before being merged into the 4.3-dev branch (closes #28902). Discussion ---------- [Debug] Detect virtual methods using @method | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no <!-- see https://symfony.com/bc --> | Deprecations? | no | Tests pass? | yes <!-- please add some, will be required by reviewers --> | Fixed tickets | #28897 (comment) | License | MIT | Doc PR | symfony/symfony-docs#10504 My first Debug PR, so im still on it. But early feedback welcome. In #28901 we'll introduce a new virtual interface method using `@method` annotation. IIUC the idea is to trigger whenever such a method is overridden. Commits ------- 38877c3 [Debug] Detect virtual methods using @method
My first Debug PR, so im still on it. But early feedback welcome.
In #28901 we'll introduce a new virtual interface method using
@method
annotation. IIUC the idea is to trigger whenever such a method is overridden.