laravel-ide-helper icon indicating copy to clipboard operation
laravel-ide-helper copied to clipboard

Macro return type

Open Stevemoretz opened this issue 2 years ago • 2 comments

It would be nice to have the return type for a macro, currently it gives no return type in PhpDocs.

Stevemoretz avatar Jan 27 '22 21:01 Stevemoretz

Any solution for this?

AidasK avatar Apr 19 '22 08:04 AidasK

seems not working yet, but it could with typesystem:

Builder::macro(/**
         * @template T
         * @param string $column
         * @param string $operator
         * @param $value
         * @return T
         */ 'whereOrNull', function (string $column, string $operator, mixed $value): Builder|\Illuminate\Contracts\Database\Query\Builder {
            /** @var Builder $builder */
            $builder = $this;

            return $builder->where(fn (Builder $builder) => $builder->where($column, $operator, $value)->orWhereNull($column));
        });
        Builder::macro('whereNot', function (string $column, $value) {
            /** @var Builder $builder */
            $builder = $this;
            if (null === $value) {
                return $builder->whereNotNull($column);
            }

            return $builder->where($column, '!=', $value);
        });

joelharkes avatar Jan 25 '23 14:01 joelharkes