-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Let the DocBlock::ofMethod handle an ~optional~ className #3885
Let the DocBlock::ofMethod handle an ~optional~ className #3885
Conversation
Codecov Report
@@ Coverage Diff @@
## master #3885 +/- ##
=========================================
Coverage 83.66% 83.66%
Complexity 3853 3853
=========================================
Files 151 151
Lines 10195 10195
=========================================
Hits 8530 8530
Misses 1665 1665
Continue to review full report at Codecov.
|
@Ocramius Can you have a look at this, please? I cannot really put a finger on it, but at first glance this seems more like a workaround than a solution. |
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.
Fix seems correct to me, @sebastianbergmann: we are now recording docblocks by hierarchy level in a class hierarchy.
The only problem I see with the patch is that it introduces a change in the test suite, rather than an addition, and that makes it hard to validate it. I suggest reverting test changes, and adding targeted tests instead.
{ | ||
public static function asArrayProvider() | ||
public function asArrayProvider() |
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.
Would suggest not changing these as part of thr patch: write independent/new fixtures instead. Changing this means changing tests that might be affected by the bug and/or fix.
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 renamed them and wrote similar tests. I hope it is clear, would be happy to hear how it could be done better
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'd generally suggest reverting the old asset changes: they do prevent regressions (like the one that you are fixing - and BTW thanks very much for your efforts!)
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've now kept the old test, but named it testWithVariousIterableStaticDataProviders
instead of testWithVariousIterableDataProviders
, and then also made tests for when this provider is non-static, of the parent, called from the parent, etc.
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.
Thanks!
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
abstract class AbstractVariousIterableDataProviderTest |
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.
What is being tested with this added fixture? I suggest adding a test for what this is checking.
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.
Solved
src/Util/Annotation/DocBlock.php
Outdated
@@ -111,7 +114,7 @@ public static function ofMethod(\ReflectionMethod $method): self | |||
$method->getEndLine(), | |||
$method->getFileName(), | |||
$method->getName(), | |||
$method->getDeclaringClass()->getName() | |||
$className ?? $method->getDeclaringClass()->getName() |
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.
If fetching the specific class is the use-case, then I suggest making the new argument mandatory, and naming $className
so that it reflects the fact that this is a specific class in the hierarchy.
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.
Absolutely, it's not optional.
@@ -62,7 +62,7 @@ public function forClassName(string $class): DocBlock | |||
|
|||
/** | |||
* @throws Exception | |||
* @psalm-param class-string $className |
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.
Ow, not sure how this made it through 😱
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.
What's with this psalm-param? I do not really understand it, I copied it to more locations, seemed logical to me
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.
This is a restriction on the string
type, stating that the string must be a class name. The @psalm-param
is an annotation we have to use here, in lack of better type support in phpdocumentor/phpstorm/etc.
All good BTW 👍
@@ -80,6 +80,6 @@ public function forMethod(string $class, string $method): DocBlock | |||
); | |||
} | |||
|
|||
return $this->methodDocBlocks[$class][$method] = DocBlock::ofMethod($reflection); | |||
return $this->methodDocBlocks[$class][$method] = DocBlock::ofMethod($reflection, $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.
$class
should probably be named $classInHierarchy
or such
src/Util/Annotation/DocBlock.php
Outdated
/** | ||
* @psalm-param class-string $className | ||
*/ | ||
public static function ofMethod(\ReflectionMethod $method, string $className = null): self |
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.
Now there are two ways to create DocBlock object
DocBlock::ofClass(
new \ReflectionClass($class)
);
DocBlock::ofMethod(
new \ReflectionMethod($class, $method)
);
Unfortunately, you can not obtain class namespace from method reflection object, only class that declares method.
Maybe it's better to describe only one method to create a DocBlock object e.g.
public static function fromReflection(\ReflectionClass $class, \ReflectionMethod $method = null): self
or make a public constructor
public function __construct(\ReflectionClass $class, \ReflectionMethod $method = null)
@Ocramius what do you think about that?
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.
What about separate named ctors (as separate static methods)?
Also, please keep the ctor private: that's what gave us this flexibility in first place 👍
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.
There is a difference between docblocks of classes and those of methods right? I think the current structure makes that quite clear?
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.
Yeah, all good with that
Currently having problems with the following:
So I made this
Now php-Cs-fixer wants it to look like
but then psalm does not recognize the psalm-annotation. What should I do? |
If suppressing won't work, then I suggest updating the baseline file. See If all is good, we should see that one error added to the file, and if lucky even some error removals in the diff 👍 |
Hurray! |
Cherry-picked into |
Did you cherry-pick the whole pull-request or only the first commit? I did make quite some adjustments, thanks to ocramius' feedback, that should certainly be included as well Edit: Ah, of course you did, I'm sorry for the bump |
Fixes issue #3879