-
Notifications
You must be signed in to change notification settings - Fork 132
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
Fix issues found by static analysis #394
Conversation
@@ -26,7 +26,7 @@ public function __construct(BetterReflectionFunction $betterReflectionFunction) | |||
*/ | |||
public static function export($name, $return = null) | |||
{ | |||
BetterReflectionFunction::export(...\func_get_args()); | |||
return BetterReflectionFunction::export(...\func_get_args()); |
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.
WOW that's bad O_O
@@ -180,7 +180,7 @@ public function hasProperty($name) | |||
/** | |||
* {@inheritDoc} | |||
*/ | |||
public function getProperty($name) | |||
public function getProperty($name) : ?ReflectionProperty |
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.
AFAIK, all adapters didn't really have return types. Wondering if we should change 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.
I can put it in the docblock?
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.
PHP allows it...
@@ -121,6 +121,10 @@ private function compileConstFetch(Node\Expr\ConstFetch $constNode) | |||
*/ | |||
private function compileClassConstFetch(Node\Expr\ClassConstFetch $node, CompilerContext $context) | |||
{ | |||
if ($node->class instanceof Node\Expr || $node->name instanceof Node\Expr\Error) { |
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 would require also a test to reach this code location. This may as well be an assumption that is hard to code within the types we have available.
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.
$node->class
cannot ever be a Node\Expr
here, but Node\Expr\ClassConstFetch::$class
can be. I suppose the error node may be possible, if you allow errors in PhpParser
.
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'll change to a @var
docblock
@@ -62,15 +62,15 @@ protected function __construct() | |||
{ | |||
} | |||
|
|||
public static function export() : void | |||
public static function export() |
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 indeed supposed to be void
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 method inherits from a method that has a non-void
return type
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 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 the parent were user-defined, a void
return type would be a fatal error: https://3v4l.org/BXtvR
@@ -34,7 +34,7 @@ | |||
public const CLOSURE_NAME = '{closure}'; | |||
|
|||
/** | |||
* @var NamespaceNode | |||
* @var ?NamespaceNode |
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.
NamespaceNode|null
@@ -510,7 +510,7 @@ public function setBodyFromClosure(Closure $newBody) : void | |||
*/ | |||
public function setBodyFromString(string $newBody) : void | |||
{ | |||
$this->node->stmts = $this->loadStaticParser()->parse('<?php ' . $newBody); | |||
$this->node->stmts = $this->loadStaticParser()->parse('<?php ' . $newBody) ?: []; |
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.
Hmm... the parser should never yield non-arrays...
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.
In theory it can yield null
just based on the return type.
@@ -184,6 +184,14 @@ private function parseDefaultValueNode() : void | |||
$defaultValueNode = $this->node->default; | |||
|
|||
if ($defaultValueNode instanceof Node\Expr\ClassConstFetch) { | |||
if ($defaultValueNode->class instanceof Node\Expr) { |
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.
Same scenario as above - this would require a test case
@@ -67,7 +67,7 @@ private function __construct() | |||
{ | |||
} | |||
|
|||
public static function export() : void | |||
public static function export() |
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 indeed void
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 method inherits from a method that has a non-void
return type
@@ -21,7 +21,7 @@ class ReflectionType | |||
]; | |||
|
|||
/** | |||
* @var $type | |||
* @var string |
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.
👍
@@ -87,7 +87,7 @@ public function __construct( | |||
$this->astConversionStrategy = $astConversionStrategy; | |||
} | |||
|
|||
public function enterNode(Node $node) : void |
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.
These should be kept
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 method inherits from a method that has a non-void
return type
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 added an @inheritDoc
annotation 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.
Btw this issue is documented here: phpstan/phpstan#729 (comment)
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, ok - makes sense to drop these at least for now 👍
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.
Will revert this change though, per #394 (comment)
@@ -25,7 +25,7 @@ class FileIteratorSourceLocator implements SourceLocator | |||
private $aggregateSourceLocator; | |||
|
|||
/** | |||
* @var \Iterator|\SplFileInfo[] | |||
* @var \Iterator<\SplFileInfo> |
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.
@muglug Is there an editor that can understand this? I don't think that eg. PHPStorm supports this syntax.
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 don't think so? But it's a logical syntax for an iterator
that only contains SplFileInfo
.
The union type that works in PHPStorm - \Iterator|\SplFileInfo[]
- is illogical, since it implies the property can accept arrays.
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 agree it's logical but this syntax is not supported in editors and other tools (eg. PHPCS).
https://github.com/phpDocumentor/fig-standards/tree/master/proposed is still only a draft.
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.
Yup, and until people stop using broken docblocks in their code, there'll be less momentum to fix it.
I have a @psalm-var
annotation for non-phpdoc-compatible types, I could add it there 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.
Yeah, until this can be fixed "properly", at least we have editor support with the \SplFileInfo[]
hint, which is preferable to not figuring out types IMO :/
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.
Syntax change indeed to be reverted here.
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.
Yup will do
25556f7
to
9996b89
Compare
627b41c
to
497395e
Compare
@@ -27,7 +27,7 @@ public function __construct(BetterReflectionFunction $betterReflectionFunction) | |||
*/ | |||
public static function export($name, $return = null) | |||
{ | |||
BetterReflectionFunction::export(...func_get_args()); | |||
return BetterReflectionFunction::export(...func_get_args()); |
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.
Hmm, I know there's been a couple of comments on these, but ::export
methods really do return nothing:
There's certainly a discrepancy here (phpdocs vs reality), so which do we pick? What the docs/types say, or how it actually behaves? So far we've been obeying the real-world behaviour (which I'd favour, but is of course incompatible with static analysis...)
/cc @Ocramius
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.
Reality would be better overall.
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'm confused. It can return e.g. https://3v4l.org/oolCP
@@ -350,7 +350,6 @@ function (ReflectionMethod $method) use ($filter) { | |||
*/ | |||
public function getImmediateMethods(?int $filter = null) : array | |||
{ | |||
/** @var \ReflectionMethod[] $methods */ |
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.
why removing this?
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.
Because it can be inferred easily
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_map()
's documented return value is array
- unless we have generics, this isn't inferred by tooling that doesn't assume implementation details of array_map
, so the change should be reverted.
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.
Hmm, errata - it can be inferred, it's just that most tooling won't do recursive inferring of types, so this can't really be removed unless the ecosystem evolves
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 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'll revert this
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.
Oh this was also inaccurate, which is why I made the change in the first place (it shouldn't have the leading slash)
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 like the pic :D
I know the tool you built is doing it, but the majority still needs to catch up ;-)
@@ -515,6 +518,7 @@ public function setBodyFromClosure(Closure $newBody) : void | |||
*/ | |||
public function setBodyFromString(string $newBody) : void | |||
{ | |||
/** @var Node[] $this->node->stmts */ |
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 haven't checked, but does PhpStorm (or other IDEs) actually support this syntax? o_O also, can this not be inferred anyway? And finally, why are we documenting the type when it's not actually used anywhere later?
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.
No, this syntax is not supported
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'll remove
also, can this not be inferred anyway
The method can return null here
* @param Class_|Interface_|Trait_ $classNode | ||
*/ | ||
private function addClassModifiers(Declaration $classNode, CoreReflectionClass $classReflection) : void | ||
private function addClassModifiers(Class_ $classNode, CoreReflectionClass $classReflection) : void |
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.
Is ClassLike
not more appropriate here? As this would no longer accept Interface_
or Trait_
I think, which I believe should be accepted so we can make them abstract
(unless I'm mistaken)
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/Interfaces can't be abstract
though? Or final
?
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.
No fix needed
@@ -64,11 +64,20 @@ public function __invoke(CoreReflectionClass $classReflection) : string | |||
{ | |||
$classNode = $this->createClass($classReflection); | |||
|
|||
$this->addClassModifiers($classNode, $classReflection); | |||
if ($classNode instanceof Class_) { | |||
$this->addClassModifiers($classNode, $classReflection); |
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.
Interface_
and Trait_
should be passed here too
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.
How can we have abstract/final interfaces or traits?
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.
No fix needed
@@ -25,7 +25,7 @@ class FileIteratorSourceLocator implements SourceLocator | |||
private $aggregateSourceLocator; | |||
|
|||
/** | |||
* @var \Iterator|\SplFileInfo[] | |||
* @var \Iterator<\SplFileInfo> |
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, until this can be fixed "properly", at least we have editor support with the \SplFileInfo[]
hint, which is preferable to not figuring out types IMO :/
@@ -87,7 +87,7 @@ public function __construct( | |||
$this->astConversionStrategy = $astConversionStrategy; | |||
} | |||
|
|||
public function enterNode(Node $node) : void |
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, ok - makes sense to drop these at least for now 👍
@@ -27,7 +27,7 @@ public function __construct(BetterReflectionFunction $betterReflectionFunction) | |||
*/ | |||
public static function export($name, $return = null) | |||
{ | |||
BetterReflectionFunction::export(...func_get_args()); | |||
return BetterReflectionFunction::export(...func_get_args()); |
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.
Reality would be better overall.
@@ -34,7 +34,7 @@ public function __construct(BetterReflectionMethod $betterReflectionMethod) | |||
*/ | |||
public static function export($class, $name, $return = null) | |||
{ | |||
BetterReflectionMethod::export(...func_get_args()); | |||
return BetterReflectionMethod::export(...func_get_args()); |
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.
Same here: to be reverted
@@ -313,7 +313,7 @@ public function isDestructor() | |||
public function getClosure($object = null) | |||
{ | |||
try { | |||
$this->betterReflectionMethod->getClosure($object); | |||
return $this->betterReflectionMethod->getClosure($object); |
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.
Looks like we never tested this - that's needed here
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, this needs a test addition too
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.
Test added in 74ba592
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!
@@ -175,7 +175,9 @@ public function hasProperty($name) | |||
} | |||
|
|||
/** | |||
* {@inheritDoc} | |||
* @param string $name |
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.
We shouldn't change the parent API in the Adapter
ns
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.
See #389
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.
same as discussion in https://github.com/Roave/BetterReflection/pull/394/files#r164996850
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.
Handled in #391
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.
Reverted
@@ -184,7 +184,9 @@ public function hasProperty($name) | |||
} | |||
|
|||
/** | |||
* {@inheritDoc} | |||
* @param string $name |
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.
We shouldn't change the documented API in the Adapter
ns
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 already have, though - documented here
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, but that bug is being fixed. This needs revert or we can wait for the other patch to go in before reverting
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.
Reverted
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function enterNode(Node $node) |
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.
: void
is to be kept - would highlight changes in the parent API.
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function enterNode(Node $node) |
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.
: void
is to be kept - would highlight changes in the parent API.
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function leaveNode(Node $node) |
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.
: void
is to be kept - would highlight changes in the parent API.
@@ -25,7 +25,7 @@ class FileIteratorSourceLocator implements SourceLocator | |||
private $aggregateSourceLocator; | |||
|
|||
/** | |||
* @var \Iterator|\SplFileInfo[] | |||
* @var \Iterator<\SplFileInfo> |
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.
Syntax change indeed to be reverted here.
@@ -35,17 +35,28 @@ public function __invoke(?Namespace_ $namespace) : Context | |||
private function aliasesToFullyQualifiedNames(Namespace_ $namespace) : array | |||
{ | |||
// flatten(flatten(map(stuff))) | |||
return array_merge([], ...array_merge([], ...array_map(function ($use) : array { | |||
/** @var $use Use_|GroupUse */ | |||
return array_merge( |
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 don't understand what was changed here, since the alignment was changed. The operation was simply turning array[][]
into array
, but I don't see the diff nodes affected here.
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.
Changing /** @var $use Use_|GroupUse */
to /** @param Use_|GroupUse $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.
Seems related to https://github.com/Roave/BetterReflection/pull/394/files#r164988430 - type is being inferred over implementation of array_map()
. LGTM.
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.
Not totally related. Psalm has a MissingDocblockType
that triggers for @var $var Type
annotations. When I had a look at this, it made sense to not only fix the order but change it to a @param
.
Psalm doesn't project types into closures, so it's not able to infer this, but it does check the boundaries – e.g. it sees the error in
class A {}
class B {}
$as = [new A(), new B()];
$classes = array_map(
function(B $a) : string {
return "hello";
},
$as
);
(I don't have link generation set up, but you can always paste into getpsalm.org to verify)
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.
👍
@Ocramius w/r/t Currently PHPStan doesn’t check return type equality or covariance of docblock return types, allowing you to do whatever you want. I could add a workaround that allows Once PHPStan starts using BetterReflection I imagine these issues will pop up there, too. |
@muglug |
3fb0330
to
3d7a27a
Compare
I've removed the unnecessary |
@@ -184,7 +184,9 @@ public function hasProperty($name) | |||
} | |||
|
|||
/** | |||
* {@inheritDoc} | |||
* @param string $name |
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, but that bug is being fixed. This needs revert or we can wait for the other patch to go in before reverting
@@ -175,7 +175,9 @@ public function hasProperty($name) | |||
} | |||
|
|||
/** | |||
* {@inheritDoc} | |||
* @param string $name |
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.
same as discussion in https://github.com/Roave/BetterReflection/pull/394/files#r164996850
@@ -350,7 +350,6 @@ function (ReflectionMethod $method) use ($filter) { | |||
*/ | |||
public function getImmediateMethods(?int $filter = null) : array | |||
{ | |||
/** @var \ReflectionMethod[] $methods */ |
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_map()
's documented return value is array
- unless we have generics, this isn't inferred by tooling that doesn't assume implementation details of array_map
, so the change should be reverted.
@@ -35,17 +35,28 @@ public function __invoke(?Namespace_ $namespace) : Context | |||
private function aliasesToFullyQualifiedNames(Namespace_ $namespace) : array | |||
{ | |||
// flatten(flatten(map(stuff))) | |||
return array_merge([], ...array_merge([], ...array_map(function ($use) : array { | |||
/** @var $use Use_|GroupUse */ | |||
return array_merge( |
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.
Seems related to https://github.com/Roave/BetterReflection/pull/394/files#r164988430 - type is being inferred over implementation of array_map()
. LGTM.
@@ -313,7 +313,7 @@ public function isDestructor() | |||
public function getClosure($object = null) | |||
{ | |||
try { | |||
$this->betterReflectionMethod->getClosure($object); | |||
return $this->betterReflectionMethod->getClosure($object); |
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, this needs a test addition too
@@ -130,6 +130,7 @@ private function compileConstFetch(Node\Expr\ConstFetch $constNode) | |||
*/ | |||
private function compileClassConstFetch(Node\Expr\ClassConstFetch $node, CompilerContext $context) | |||
{ | |||
/** @var Node\Name $node->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.
This syntax is not really compatible with most tooling out there - what should we do about it?
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 it breaks anything I'm happy to remove it, or replace with an assert
.
My hope is that the PSR-5 PHPDoc proposal is approved, and the people who make similar tools add support for this. It's a common-sense 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.
This is also that could be fixed with a Psalm config, as it relates to behaviour of PhpParser that will never occur given how it's used in BetterReflection. vimeo/psalm#482 would fix that internally.
Anyway, using an assert
also fixes a PHPStan error at the same location so maybe that's the way to go here.
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.
Let's keep them for now 👍
@@ -148,6 +149,7 @@ private function compileClassConstFetch(Node\Expr\ClassConstFetch $node, Compile | |||
$classInfo = $context->getReflector()->reflect($className); | |||
} | |||
|
|||
/** @var string $node->name */ |
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.
Same question about compatibility: what to do here?
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.
Let's keep this for now
@@ -67,7 +69,7 @@ public function methodExpectationProvider() : array | |||
['isUserDefined', null, true, []], | |||
['getClosureThis', NotImplemented::class, null, []], | |||
['getClosureScopeClass', NotImplemented::class, null, []], | |||
['getDocComment', null, '', []], | |||
['getDocComment', null, 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.
Nice catch here 👍
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.
LGTM 👍
Let's 🚢 this :)
Thanks @muglug for keeping up with our extremely lengthy and annoying review process ^_^
@Ocramius totally worth it for the improvements it forced me to make to Psalm. Thanks for taking your time with it! |
This attempts to adhere, as much as possible, to the base
Reflection*
signatures. In the case of #389, I made the current different return type explicit so that changing will be a clear breaking change.According to the docs, static
::export
methods can return a value, so I allowed that even if your model does not. You may want to add an explicitreturn null
.Roave\BetterReflection\Reflection\Adapter\ReflectionMethod::getClosure
wasn't returning aClosure
, now it should.