Larastan Query Builder instance understanding orWhere preceeding Query Scope

Viewed 530

I'm using Larastan to eliminate some of the static analysis errors I have going on in my codebase. I have several errors involving the the Eloquent Higher Order Messaging Proxy known as orWhere.

I'm using this method as show below.

ModelA::query()->scopeOne()->orWhere->scopeTwo()->get();

After looking through the Larastan repository I stumbled upon this issue that was brought up to fix this issue and the pull request which was merged.

Issue

Pull Request

I currently have dev-master version of Larastan and have checked to make sure the Builder class as the property-read of orWhere inside of it which it does.

When I run the phpstan on my file that contains the orWhere higher order message proxy it gives me the following error.

23     Call to an undefined method Illuminate\Database\Eloquent\Builder<App\Models\ModelA>::scope2().  

ModelA

<?php

namespace App\Models;

use App\Builders\ModelQueryBuilder;

class ModelA extends ParentModel 
{
    /**
     * Create a new Eloquent query builder for the model.
     *
     * @param  \Illuminate\Database\Query\Builder  $query
     * @return \App\Builders\ModelAQueryBuilder<\App\Models\ModelA>
     */
    public function newEloquentBuilder($query)
    {
        return new ModelABuilder($query);
    }
}
<?php

namespace App\Builders;

/**
 * @template TModelClass of \App\Models\ModelA
 * @extends ParentMemberQueryBuilder<TModelClass>
 */
class ModelAQueryBuilder extends ParentMemberQueryBuilder
{
    /**
     * @return \App\Builders\ModelAQueryBuilder
     */
    public function scopeOne()
    {
        return $this->whateverConstraints();
    }
}
<?php

namespace App\Builders;

/**
 * @template TModelClass of \App\Models\ParentMember
 * @extends GrandparentQueryBuilder<TModelClass>
 */
class ParentMemberQueryBuilder extends GrandparentMemberQueryBuilder
{
}
<?php

namespace App\Builders;

use Illuminate\Database\Eloquent\Builder;

/**
 * @template TModelClass of \App\Models\GrandParent
 * @extends Builder<TModelClass>
 */
class GrandparentMemberQueryBuilder extends Builder
{
    /**
     * @return \App\Builders\GrandparentQueryBuilder
     */
    public function scopeTwo()
    {
        return $this->whereConstraints();
    }
}

0 Answers
Related