Skip to content

Builder callback type #420

@WimWidgets

Description

@WimWidgets
  • Scout Version: 8.3.1
  • Laravel Version: 7.28.3
  • PHP Version: 7.4.9

Description:

The $callback property of the Laravel\Scout\Builder is defined as a string.

    /**
     * Optional callback before search execution.
     *
     * @var string
     */
    public $callback;

In the constructor the $callback parameter is defined as either a closure or null, although the docblock does not reflect the possible null value.

    /**
     * Create a new search builder instance.
     *
     * @param  \Illuminate\Database\Eloquent\Model  $model
     * @param  string  $query
     * @param  \Closure  $callback <--- this should say \Closure|null
     * @param  bool  $softDelete
     * @return void
     */
    public function __construct($model, $query, $callback = null, $softDelete = false)
    {
        $this->model = $model;
        $this->query = $query;
        $this->callback = $callback; // <--- a property of type string is set with a closure

        if ($softDelete) {
            $this->wheres['__soft_deleted'] = 0;
        }
    }

Proposal:

Change the type hint for the $callback property to be @var \Closure|null, just like the $queryCallback property. And also update the constructor docblock to match the parameter value.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions