Skip to content
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

Psalm is unaware of a handful of methods on the various core reflection classes #7810

Closed
ollieread opened this issue Mar 23, 2022 · 5 comments · Fixed by #8592
Closed

Psalm is unaware of a handful of methods on the various core reflection classes #7810

ollieread opened this issue Mar 23, 2022 · 5 comments · Fixed by #8592
Labels
bug easy problems Issues that can be fixed without background knowledge of Psalm good first issue Help wanted internal stubs/callmap

Comments

@ollieread
Copy link

I've only created examples for the ones that I encountered, but if my understanding is correct, and stubs/Reflection.phpstub is how Psalm understands reflection classes, there is a lot missing.

ReflectionProperty::hasDefaultValue() https://psalm.dev/r/7de1ce446b
ReflectionProperty::isPromoted() https://psalm.dev/r/0b4cc46fd2
ReflectionParameter::isPromoted() https://psalm.dev/r/62322a32a6

If my assumption/understanding is correct, I'm more than happy to create a PR that updates all of the Reflection stubs to accurately match what is available.

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/7de1ce446b
<?php

class PropertyWrapper {
    private ReflectionProperty $reflection;
    
    public function __construct(ReflectionProperty $reflection)
    {
        $this->reflection = $reflection;
    }
    
    public function hasDefault(): bool
    {
        return $this->reflection->hasDefaultValue();
    }
}
Psalm output (using commit a9f4148):

INFO: MixedReturnStatement - 13:16 - Could not infer a return type

INFO: MixedInferredReturnType - 11:35 - Could not verify return type 'bool' for PropertyWrapper::hasDefault
https://psalm.dev/r/0b4cc46fd2
<?php

class PropertyWrapper {
    private ReflectionProperty $reflection;
    
    public function __construct(ReflectionProperty $reflection)
    {
        $this->reflection = $reflection;
    }
    
    public function isPromoted(): bool
    {
        return $this->reflection->isPromoted();
    }
}
Psalm output (using commit a9f4148):

INFO: MixedReturnStatement - 13:16 - Could not infer a return type

INFO: MixedInferredReturnType - 11:35 - Could not verify return type 'bool' for PropertyWrapper::isPromoted
https://psalm.dev/r/62322a32a6
<?php

class PropertyWrapper {
    private ReflectionParameter $reflection;
    
    public function __construct(ReflectionParameter $reflection)
    {
        $this->reflection = $reflection;
    }
    
    public function isPromoted(): bool
    {
        return $this->reflection->isPromoted();
    }
}
Psalm output (using commit a9f4148):

INFO: MixedReturnStatement - 13:16 - Could not infer a return type

INFO: MixedInferredReturnType - 11:35 - Could not verify return type 'bool' for PropertyWrapper::isPromoted

@ollieread
Copy link
Author

ollieread commented Mar 23, 2022

It is also unaware of Attribute::$flags https://psalm.dev/r/8f628693b7, which I believe is controlled by stubs/Php80.phpstub

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/8f628693b7
<?php

class AttributeWrapper {
    private Attribute $attribute;
    
    public function __construct(Attribute $attribute)
    {
        $this->attribute = $attribute;
    }
    
    public function getFlags(): int
    {
        return $this->attribute->flags;
    }
    
    public function isRepeatable(): bool
    {
        return (bool)($this->getFlags() & Attribute::IS_REPEATABLE);
    }
}
Psalm output (using commit a9f4148):

INFO: MixedReturnStatement - 13:16 - Could not infer a return type

INFO: MixedInferredReturnType - 11:33 - Could not verify return type 'int' for AttributeWrapper::getFlags

@AndrolGenhald AndrolGenhald added bug easy problems Issues that can be fixed without background knowledge of Psalm internal stubs/callmap good first issue labels Mar 23, 2022
@AndrolGenhald
Copy link
Collaborator

AndrolGenhald commented Mar 23, 2022

I'm more than happy to create a PR

Go for it! Just be sure to use the correct Phpxx.phpstub for things that don't exist in all PHP versions.

@ollieread
Copy link
Author

I'm more than happy to create a PR

Go for it! Just be sure to use the correct Phpxx.phpstub for things that don't exist in all PHP versions.

Sorry, this got buried under mountain if other things. If this still hasn't been fixed I will take a look and create a PR for the reflection stubs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug easy problems Issues that can be fixed without background knowledge of Psalm good first issue Help wanted internal stubs/callmap
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants