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

Return static instance on abstract class setters #200

Merged
merged 1 commit into from
Jun 17, 2024

Conversation

veewee
Copy link
Contributor

@veewee veewee commented Jun 17, 2024

Q A
Documentation no
Bugfix no/yes
BC Break no
New Feature no
RFC no
QA no

Description

This PR improves static analysis when using the setters that are located in the abstract generators:
Instead of returning with type Abstract* on setters, the static instance will be returned.
This makes static analyzers understand a fluent approach better.

For example:

(new MethodGenerator('getX'))
    ->setStatic(true)
    // > This would previously result in the static analyzer to believe the type is `AbstractMemberGenerator`
    ->setBody('return '.$code)
    ->setReturnType(ClassMapCollection::class)

Resulting in issues like:

>   54     Parameter #1 $method of method
         Laminas\Code\Generator\ClassGenerator::addMethodFromGenerator()
         expects Laminas\Code\Generator\MethodGenerator,
         Laminas\Code\Generator\AbstractMemberGenerator given.

@Ocramius Ocramius self-assigned this Jun 17, 2024
@Ocramius Ocramius added this to the 4.14.0 milestone Jun 17, 2024
Copy link
Member

@Ocramius Ocramius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @veewee

@Ocramius Ocramius merged commit 562e02b into laminas:4.14.x Jun 17, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants