phpstan / phpstan-nette

Nette Framework class reflection extension for PHPStan & framework-specific rules
MIT License
100 stars 35 forks source link

PHPStan: Call to an undefined method Slince\Shopify\Client::methodName() #130

Closed FilipCZ closed 1 year ago

FilipCZ commented 1 year ago

Hello, in several classes as part of the project, after testing (PHPStan level 2), I'm encountering errors of the type Slince\Shopify\Client::methodName(). Could you please advise me on how to resolve these issues? Thank you.

<?php

namespace App\Providers\Shopify;

use Slince\Shopify\Exception\ClientException;

class BlogProvider extends ShopifyProvider
{
    public function __construct(...)
    {
        ...
        parent::__construct();
    }

    /**
     * @param int $id
     * @return array
     */
    public function push(int $id): array
    {
        try {
            // getArticleManager() declared in Client.php (https://github.com/slince/shopify-api-php/blob/3.x/src/Client.php)
        $this->getClient($id)->getArticleManager()->update(); // PHPStan throws error here: Call to an undefined method Slince\Shopify\Client::getArticleManager().
            return ['result' => true];

        } catch (ClientException $exception) {
            ...
        }
    }
}

?>
<?php

namespace App\Providers\Shopify;

...
use Slince\Shopify\Client;
use Slince\Shopify\PublicAppCredential;

class ShopifyProvider
{

    public function __construct(...)
    {
        ...
    }

    /**
     * @param int $clientId
     * @return \Slince\Shopify\Client
     */
    public function getClient(int $clientId): Client {
        ...

        return new Client($baseUrl, $credential, [
            'meta_cache_dir' => __DIR__,
            'api_version' => '2023-04',
        ]);
    }
}

?>
ondrejmirtes commented 1 year ago

This isn't valid PHPDoc syntax: https://phpstan.org/r/81c961dd-e518-4131-8159-092af5d04e65

You need the () at the end: https://phpstan.org/r/37ed5bcf-4a98-45da-b83b-574bca67acea

So the solution is: send a PR to https://github.com/slince/shopify-api-php and fix their PHPDocs

Alternatively you can fix wrong PHPDocs with stub files: https://phpstan.org/user-guide/stub-files

github-actions[bot] commented 1 year ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.