pact-foundation / pact-php

PHP version of Pact. Enables consumer driven contract testing, providing a mock service and DSL for the consumer project, and interaction playback and verification for the service provider project
Apache License 2.0
273 stars 92 forks source link

fix: Fix 'call to unknown method' warning in ide #517

Closed tienvx closed 8 months ago

tienvx commented 8 months ago
interface UrlInterface
{
    public function setUrl(UriInterface $url): self;

    public function setToken(?string $token): self;

    public function setUsername(string $username): self;

    public function setPassword(string $password): self;
}

interface BrokerInterface extends UrlInterface
{
    // ...
}

        $broker = (new Broker())
            ->setUrl($url)
            ->setToken($token)
            ->setUsername($username)
            ->setPassword($password)
            ->setEnablePending($enablePending) // ide warning here
            ->setIncludeWipPactSince($wipPactSince)
            ->setProviderTags($providerTags)
            ->setProviderBranch($providerBranch)
            ->setConsumerVersionSelectors($consumerVersionSelectors)
            ->setConsumerVersionTags($consumerVersionTags);
Lewiscowles1986 commented 8 months ago

The issue with this is that it's not static. Is this IDE specific, and if so, would some IDE-specific annotation or work-around not work better for this?

In this case, self seems like the right type, but thinking very hard, perhaps static means something else as a return type. Late-static bound perhaps?

tienvx commented 8 months ago

Is this IDE specific

Yes

In this case, self seems like the right type, but thinking very hard, perhaps static means something else as a return type. Late-static bound perhaps?

I simply use this feature from PHP 8.0 https://php.watch/versions/8.0/static-return-type

would some IDE-specific annotation or work-around not work better for this?

According to the link above, I think @return static also can do it.

Lewiscowles1986 commented 8 months ago

returning UrlInterface will also work without static for this. Approved, but this really is not what the linked article describes at all.

tienvx commented 8 months ago

returning UrlInterface will also work without static for this.

I replaced self by UrlInterface and it doesn't work.

Any way, I will close this PR for now and focus on writing more tests which is more important.