Skip to content

Conversation

@shalomabitan
Copy link
Contributor

Using the package with phpstan I was getting an error when attempting to run this code

   public static function refreshIndex(): void
   {
       /** @var static $instance */
       $instance = new static();
       $index = $instance->getIndex();

       try {
           $client = $instance->getConnection()->getClient();
           $client?->indices()?->refresh(['index' => $index]);
       } catch (Throwable $th) {
           logger()->error('Failed to refresh index', ['index' => $index, 'error' => $th->getMessage()]);
       }
   } 

The error phpstan was throwing was

 ------ ----------------------------------------------------------------------------------------------
  Line   app/Traits/Models/OnElasticsearchConnection.php (in context of class App\Models\Search\Lead)
 ------ ----------------------------------------------------------------------------------------------
  29     Cannot call method getClient() on string.
 ------ ----------------------------------------------------------------------------------------------

After digging it was found that the docblock in the src/Eloquent/Docs/ModelDocs.php is incorrectly claiming a string will be returned and not the correct return type of use PDPhilip\Elasticsearch\Connection;

…g that it expects a string when it really returns a Connection
@pdphilip
Copy link
Owner

pdphilip commented Mar 3, 2025

Thanks @shalomabitan, we're in the process of rebuilding the package for v5 but will review this for v4 anyway when we get there.

@pdphilip pdphilip merged commit aff2dae into pdphilip:main Mar 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants