1 | <?php |
||
17 | class ElasticsearchModel extends Model |
||
18 | { |
||
19 | use Elasticsearchable, Paginationable, Relationshipable; |
||
20 | |||
21 | /** |
||
22 | * @var ElasticsearchDAL |
||
23 | */ |
||
24 | public $_dal; |
||
25 | |||
26 | public function __construct(array $attributes = []) |
||
27 | { |
||
28 | $this->validateModelEndpoint(); |
||
29 | |||
30 | parent::__construct($attributes); |
||
31 | } |
||
32 | |||
33 | public function injectDependencies() |
||
34 | { |
||
35 | // @TODO: move logger to DAL |
||
36 | $this->injectDataAccessLayer(new ElasticsearchDAL($this, app(Client::class))); |
||
37 | // $this->injectLogger(app(Log::class)); |
||
1 ignored issue
–
show
|
|||
38 | } |
||
39 | |||
40 | public static function findWithParentId($id, $parent, array $columns = ['*']) |
||
41 | { |
||
42 | /** @var static $model */ |
||
43 | $model = parent::find($id, $columns, ['parent' => $parent]); |
||
44 | |||
45 | if ($model) { |
||
46 | $model->setParentId($parent); |
||
47 | } |
||
48 | |||
49 | return $model; |
||
50 | } |
||
51 | |||
52 | /** |
||
53 | * Execute the query and get the result. |
||
54 | * |
||
55 | * @param QueryBuilder|array $query |
||
56 | * @return ElasticsearchCollection|static[] |
||
57 | */ |
||
58 | public static function search($query = []) |
||
59 | { |
||
60 | if ($query instanceof QueryBuilder) { |
||
61 | $query = $query->build(); |
||
62 | } |
||
63 | $model = static::createInstance(); |
||
64 | return $model->_dal->search($query); |
||
65 | } |
||
66 | |||
67 | /** |
||
68 | * Execute the query and get the first result. |
||
69 | * |
||
70 | * @param QueryBuilder|array $query |
||
71 | * @return static |
||
72 | */ |
||
73 | public static function first($query = []) |
||
74 | { |
||
75 | if ($query instanceof QueryBuilder) { |
||
76 | $query = $query->build(); |
||
77 | } |
||
78 | $query['from'] = 0; |
||
79 | $query['size'] = 1; |
||
80 | return static::search($query)->first(); |
||
81 | } |
||
82 | |||
83 | /** |
||
84 | * Execute the query and get the first result or throw an exception. |
||
85 | * |
||
86 | * @param QueryBuilder|array $query |
||
87 | * @throws ModelNotFoundException |
||
88 | * @return static |
||
89 | */ |
||
90 | public static function firstOrFail($query = []) |
||
91 | { |
||
92 | $model = static::first($query); |
||
93 | if (is_null($model)) { |
||
94 | throw new ModelNotFoundException(get_called_class()); |
||
95 | } |
||
96 | return $model; |
||
97 | } |
||
98 | |||
99 | /** |
||
100 | * Apply the callback to the documents of the given query. |
||
101 | * |
||
102 | * @param QueryBuilder|array $query |
||
103 | * @param callable $callback |
||
104 | * @param int $limit |
||
105 | * @return int hits.total |
||
106 | */ |
||
107 | public static function map($query = [], callable $callback, $limit = -1) |
||
136 | |||
137 | /** |
||
138 | * Execute the query and get all items. |
||
139 | * |
||
140 | * @param QueryBuilder|array $query |
||
141 | * @return Collection |
||
142 | */ |
||
143 | public static function all($query = []) |
||
154 | |||
155 | protected function belongsTo($class) |
||
156 | { |
||
157 | return new BelongsToRelationship($this, $class); |
||
158 | } |
||
159 | |||
160 | protected function hasMany($class) |
||
161 | { |
||
164 | } |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.