-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Debug] Detect internal and deprecated methods #23816
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
rebase unlocked - the same should also apply to internal methods, isn't it? |
Yes, I'm on it. |
rebased Edit: known issue, when you extend a method of an inherited trait, the deprecation will show the name of the class using the trait instead of the name of the trait itself. I didn't find a workaround but I think it's still better than no warning at all. |
6ba9fd2
to
0891882
Compare
fabbot failure is a false-positive. Travis and appveyor failures are unrelated. |
* | ||
* @return string[] | ||
*/ | ||
private function getOwnInterfaces($class) |
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.
$ownInterfaces = class_implements($class, false);
if ($parent = get_parent_class($class)) {
foreach (class_implements($parent, false) as $interface) {
unset($ownInterfaces[$interface]);
}
}
foreach ($ownInterfaces as $interface) {
foreach (class_implements($interface) as $interface) {
unset($ownInterfaces[$interface]);
}
}
return $ownInterfaces;
if (!isset($parentInterfaces[$interface])) { | ||
@trigger_error(sprintf('The "%s" %s "%s" that is deprecated %s', $name, $refl->isInterface() ? 'interface extends' : 'class implements', $interface, self::$deprecated[$interface]), E_USER_DEPRECATED); | ||
// Detect method annotations | ||
$doc = $method->getDocComment(); |
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.
could be merged with next line
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.
done
@@ -361,4 +364,30 @@ public function loadClass($class) | |||
return true; | |||
} | |||
} | |||
|
|||
/** | |||
* `class_implements` includes interfaces from the parents so we have to |
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.
I think you can configure your IDE to auto-break lines at 120, not 80 :)
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.
Done :)
} | ||
} | ||
|
||
$traits = class_uses($name, false); |
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.
$traits = array($parent) + class_uses($name, false);
Then below foreach ($interfaces + $traits
to remove the array_merge() (directly $traits
after, maybe renamed btw)
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.
array($parent) + $interfaces;
could cause conflicts so I did $parentAndTraits = ($parent ? array($parent => $parent) : array()) + class_uses($name, false);
instead.
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.
with minor comments
Thank you @GuilhemN. |
This PR was squashed before being merged into the 3.4 branch (closes #23816). Discussion ---------- [Debug] Detect internal and deprecated methods | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | no | New feature? | yes <!-- don't forget updating src/**/CHANGELOG.md files --> | BC breaks? | no | Deprecations? | no <!-- don't forget updating UPGRADE-*.md files --> | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | I just realized we do not detect `@deprecated` methods like we do for `@final` methods, so here's a fix. I reorganized the file to avoid code duplication... so the diff is kind of impressive but the behavior is the same. Commits ------- 16eeabf [Debug] Detect internal and deprecated methods
…(GuilhemN) This PR was merged into the 3.4 branch. Discussion ---------- [Debug] Correctly detect methods not from the same vendor | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no <!-- don't forget updating src/**/CHANGELOG.md files --> | BC breaks? | no | Deprecations? | no <!-- don't forget updating UPGRADE-*.md files --> | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | I just realized there were two issues in #23816: * when a class extended another class from the same vendor itself extending a class from another vendor containing deprecated methods, the deprecation wasn't triggered in case the first class extended a deprecated method from the last class because the parent from the same vendor was used for "the same vendor check". * As stated in #23816 (comment), ReflectionMethod::$class doesn't contain the right value when using a trait so if you extended a trait containing methods from another vendor you would have always get deprecations. I fixed this by comparing the method file to the filename of the class using the trait. @nicolas-grekas are you aware of any issue of `ReflectionMethod::getFilename()`? Commits ------- 08d352a [Debug] Correctly detect methods not from the same vendor
…vendor (GuilhemN) This PR was merged into the 3.4 branch. Discussion ---------- [Debug] Correctly detect methods not from the same vendor | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no <!-- don't forget updating src/**/CHANGELOG.md files --> | BC breaks? | no | Deprecations? | no <!-- don't forget updating UPGRADE-*.md files --> | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | I just realized there were two issues in symfony#23816: * when a class extended another class from the same vendor itself extending a class from another vendor containing deprecated methods, the deprecation wasn't triggered in case the first class extended a deprecated method from the last class because the parent from the same vendor was used for "the same vendor check". * As stated in symfony#23816 (comment), ReflectionMethod::$class doesn't contain the right value when using a trait so if you extended a trait containing methods from another vendor you would have always get deprecations. I fixed this by comparing the method file to the filename of the class using the trait. @nicolas-grekas are you aware of any issue of `ReflectionMethod::getFilename()`? Commits ------- 08d352a [Debug] Correctly detect methods not from the same vendor
…vendor (GuilhemN) This PR was merged into the 3.4 branch. Discussion ---------- [Debug] Correctly detect methods not from the same vendor | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no <!-- don't forget updating src/**/CHANGELOG.md files --> | BC breaks? | no | Deprecations? | no <!-- don't forget updating UPGRADE-*.md files --> | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | I just realized there were two issues in symfony#23816: * when a class extended another class from the same vendor itself extending a class from another vendor containing deprecated methods, the deprecation wasn't triggered in case the first class extended a deprecated method from the last class because the parent from the same vendor was used for "the same vendor check". * As stated in symfony#23816 (comment), ReflectionMethod::$class doesn't contain the right value when using a trait so if you extended a trait containing methods from another vendor you would have always get deprecations. I fixed this by comparing the method file to the filename of the class using the trait. @nicolas-grekas are you aware of any issue of `ReflectionMethod::getFilename()`? Commits ------- 08d352a [Debug] Correctly detect methods not from the same vendor
…vendor (GuilhemN) This PR was merged into the 3.4 branch. Discussion ---------- [Debug] Correctly detect methods not from the same vendor | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no <!-- don't forget updating src/**/CHANGELOG.md files --> | BC breaks? | no | Deprecations? | no <!-- don't forget updating UPGRADE-*.md files --> | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | I just realized there were two issues in symfony#23816: * when a class extended another class from the same vendor itself extending a class from another vendor containing deprecated methods, the deprecation wasn't triggered in case the first class extended a deprecated method from the last class because the parent from the same vendor was used for "the same vendor check". * As stated in symfony#23816 (comment), ReflectionMethod::$class doesn't contain the right value when using a trait so if you extended a trait containing methods from another vendor you would have always get deprecations. I fixed this by comparing the method file to the filename of the class using the trait. @nicolas-grekas are you aware of any issue of `ReflectionMethod::getFilename()`? Commits ------- 08d352a [Debug] Correctly detect methods not from the same vendor
…vendor (GuilhemN) This PR was merged into the 3.4 branch. Discussion ---------- [Debug] Correctly detect methods not from the same vendor | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no <!-- don't forget updating src/**/CHANGELOG.md files --> | BC breaks? | no | Deprecations? | no <!-- don't forget updating UPGRADE-*.md files --> | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | I just realized there were two issues in symfony#23816: * when a class extended another class from the same vendor itself extending a class from another vendor containing deprecated methods, the deprecation wasn't triggered in case the first class extended a deprecated method from the last class because the parent from the same vendor was used for "the same vendor check". * As stated in symfony#23816 (comment), ReflectionMethod::$class doesn't contain the right value when using a trait so if you extended a trait containing methods from another vendor you would have always get deprecations. I fixed this by comparing the method file to the filename of the class using the trait. @nicolas-grekas are you aware of any issue of `ReflectionMethod::getFilename()`? Commits ------- 08d352a [Debug] Correctly detect methods not from the same vendor
…vendor (GuilhemN) This PR was merged into the 3.4 branch. Discussion ---------- [Debug] Correctly detect methods not from the same vendor | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no <!-- don't forget updating src/**/CHANGELOG.md files --> | BC breaks? | no | Deprecations? | no <!-- don't forget updating UPGRADE-*.md files --> | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | I just realized there were two issues in symfony#23816: * when a class extended another class from the same vendor itself extending a class from another vendor containing deprecated methods, the deprecation wasn't triggered in case the first class extended a deprecated method from the last class because the parent from the same vendor was used for "the same vendor check". * As stated in symfony#23816 (comment), ReflectionMethod::$class doesn't contain the right value when using a trait so if you extended a trait containing methods from another vendor you would have always get deprecations. I fixed this by comparing the method file to the filename of the class using the trait. @nicolas-grekas are you aware of any issue of `ReflectionMethod::getFilename()`? Commits ------- 08d352a [Debug] Correctly detect methods not from the same vendor
This PR was merged into the 3.4 branch. Discussion ---------- [Debug] fix test assertion | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | Fixes tests for #23816 after the changes made in #24149. Commits ------- 75a26bb [Debug] fix test assertion
This cause issue when you still need to extend the old method to keep support for older versions (look at the way bundles were able to support both Symfony 2.7 and 2.8 to configure options in form types, by implementing both the old |
I just realized we do not detect
@deprecated
methods like we do for@final
methods, so here's a fix.I reorganized the file to avoid code duplication... so the diff is kind of impressive but the behavior is the same.