1 | <?php |
||
12 | class ModelSearchAspect extends SearchAspect |
||
13 | { |
||
14 | /** @var \Illuminate\Database\Eloquent\Model */ |
||
15 | protected $model; |
||
16 | |||
17 | /** @var array */ |
||
18 | protected $attributes = []; |
||
19 | |||
20 | public static function forModel(string $model, ...$attributes): self |
||
21 | { |
||
22 | return new self($model, $attributes); |
||
23 | } |
||
24 | |||
25 | /** |
||
26 | * @param string $model |
||
27 | * @param array|\Closure $attributes |
||
28 | * |
||
29 | * @throws \Spatie\Searchable\Exceptions\InvalidSearchableModel |
||
30 | */ |
||
31 | public function __construct(string $model, $attributes = []) |
||
32 | { |
||
33 | if (! is_subclass_of($model, Model::class)) { |
||
34 | throw InvalidSearchableModel::notAModel($model); |
||
35 | } |
||
36 | |||
37 | if (! is_subclass_of($model, Searchable::class)) { |
||
38 | throw InvalidSearchableModel::modelDoesNotImplementSearchable($model); |
||
39 | } |
||
40 | |||
41 | $this->model = $model; |
||
|
|||
42 | |||
43 | if (is_array($attributes)) { |
||
44 | $this->attributes = SearchableAttribute::createMany($attributes); |
||
45 | |||
46 | return; |
||
47 | } |
||
48 | |||
49 | if (is_string($attributes)) { |
||
50 | $this->attributes = SearchableAttribute::create($attributes); |
||
51 | |||
52 | return; |
||
53 | } |
||
54 | |||
55 | if (is_callable($attributes)) { |
||
56 | $callable = $attributes; |
||
57 | |||
58 | $callable($this); |
||
59 | |||
60 | return; |
||
61 | } |
||
62 | } |
||
63 | |||
64 | public function addSearchableAttribute(string $attribute, bool $partial = true): self |
||
65 | { |
||
66 | $this->attributes[] = SearchableAttribute::create($attribute, $partial); |
||
67 | |||
68 | return $this; |
||
69 | } |
||
70 | |||
71 | public function addExactSearchableAttribute(string $attribute): self |
||
72 | { |
||
73 | $this->attributes[] = SearchableAttribute::createExact($attribute); |
||
74 | |||
75 | return $this; |
||
76 | } |
||
77 | |||
78 | public function getType(): string |
||
88 | |||
89 | public function getResults(string $term, User $user = null): Collection |
||
101 | |||
102 | protected function addSearchConditions(Builder $query, string $term) |
||
103 | { |
||
104 | $attributes = $this->attributes; |
||
105 | $searchTerms = explode(' ', $term); |
||
120 | } |
||
121 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..