Larastan: [0.5.7] Class XXXXX was not found while trying to analyse it

Created on 6 May 2020  路  2Comments  路  Source: nunomaduro/larastan

  • Larastan Version: 0.5.7
  • --level used: 7

Description

Unexpected error message when running phpstan:

"Class replica was not found while trying to analyse it - autoloading is probably not configured properly."

Here "replica" is a param, not a class, so I have no idea where this is coming from but thought I should raise it.

Laravel code where the issue was found

Snippets of relevant code:

From Controller:

        $lends = auth()->user()->lendsNotDeletedFromReplica();

From User:

    /**
     * All non-deleted lends from the replica connection
     *
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function lendsNotDeletedFromReplica(): HasMany
    {
        return $this->hasManyFromConnection('replica', LendingRequest::class)
            ->where('status', '!=', 'deleted');
    }

User inherits from Model:

    /**
     * Allows use of different DB connections for relationships
     *
     * @param  string  $connection
     * @param  string  $related
     * @param  string  $foreignKey
     * @param  string  $localKey
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function hasManyFromConnection(
        string $connection,
        string $related,
        string $foreignKey = null,
        string $localKey = null
    ): HasMany {
        $foreignKey = $foreignKey ?: $this->getForeignKey();
        $instance = new $related;
        $instance->setConnection($connection);
        $localKey = $localKey ?: $this->getKeyName();
        return new HasMany($instance->newQuery(), $this, $instance->getTable().'.'.$foreignKey, $localKey);
    }

bug

Most helpful comment

All 2 comments

Tested and this has resolved the issue.

Was this page helpful?
0 / 5 - 0 ratings