Skip to content

Commit c9fdad9

Browse files
authored
Merge pull request #294 from RonasIT/293-delete-deprecated
[293]: delete deprecated SearchTrait methods, update visibility
2 parents c2fc7e8 + 978aaec commit c9fdad9

3 files changed

Lines changed: 26 additions & 49 deletions

File tree

src/Traits/EntityControlTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function force($value = true): self
4848
return $this;
4949
}
5050

51-
public function setModel($modelClass): self
51+
protected function setModel($modelClass): self
5252
{
5353
$this->model = new $modelClass();
5454

src/Traits/SearchTrait.php

Lines changed: 5 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ protected function setAdditionalReservedFilters(...$filterNames)
4040
array_push($this->reservedFilters, ...$filterNames);
4141
}
4242

43-
public function paginate(): LengthAwarePaginator
43+
protected function paginate(): LengthAwarePaginator
4444
{
4545
$defaultPerPage = config('defaults.items_per_page');
4646
$perPage = Arr::get($this->filter, 'per_page', $defaultPerPage);
@@ -138,10 +138,10 @@ public function searchQuery(array $filter = []): self
138138
$this->filterLess($field, true, $fieldName);
139139
} elseif (Str::endsWith($fieldName, '_from')) {
140140
$field = Str::replace('_from', '', $fieldName);
141-
$this->filterFrom($field, false, $fieldName);
141+
$this->filterGreater($field, false, $fieldName);
142142
} elseif (Str::endsWith($fieldName, '_to')) {
143143
$field = Str::replace('_to', '', $fieldName);
144-
$this->filterTo($field, false, $fieldName);
144+
$this->filterLess($field, false, $fieldName);
145145
} elseif (Str::endsWith($fieldName, '_in_list')) {
146146
$field = Str::replace('_in_list', '', $fieldName);
147147
$this->filterByList($field, $fieldName);
@@ -169,7 +169,7 @@ public function getSearchResults(): LengthAwarePaginator
169169
return $this->wrapPaginatedData($data);
170170
}
171171

172-
public function wrapPaginatedData(Collection $data): LengthAwarePaginator
172+
protected function wrapPaginatedData(Collection $data): LengthAwarePaginator
173173
{
174174
$total = $data->count();
175175

@@ -183,7 +183,7 @@ public function wrapPaginatedData(Collection $data): LengthAwarePaginator
183183
return $this->getModifiedPaginator($paginator);
184184
}
185185

186-
public function getModifiedPaginator(LengthAwarePaginator $paginator): LengthAwarePaginator
186+
protected function getModifiedPaginator(LengthAwarePaginator $paginator): LengthAwarePaginator
187187
{
188188
$collection = $paginator->getCollection();
189189

@@ -215,30 +215,6 @@ protected function getDesc(bool $isDesc): string
215215
return ($isDesc) ? 'DESC' : 'ASC';
216216
}
217217

218-
/** @deprecated use filterGreater instead */
219-
public function filterMoreThan(string $field, $value): self
220-
{
221-
return $this->filterValue($field, '>', $value);
222-
}
223-
224-
/** @deprecated use filterLess instead */
225-
public function filterLessThan(string $field, $value): self
226-
{
227-
return $this->filterValue($field, '<', $value);
228-
}
229-
230-
/** @deprecated use filterGreater instead */
231-
public function filterMoreOrEqualThan(string $field, $value): self
232-
{
233-
return $this->filterValue($field, '>=', $value);
234-
}
235-
236-
/** @deprecated use filterLess instead */
237-
public function filterLessOrEqualThan(string $field, $value): self
238-
{
239-
return $this->filterValue($field, '<=', $value);
240-
}
241-
242218
public function filterValue(string $field, string $sign, $value): self
243219
{
244220
if (!empty($value)) {
@@ -290,12 +266,6 @@ protected function getQuerySearchCallback(string $field, string $mask): Closure
290266
};
291267
}
292268

293-
/** @deprecated use filterGreater instead */
294-
public function filterFrom(string $field, bool $isStrict = true, ?string $filterName = null): self
295-
{
296-
return $this->filterGreater($field, $isStrict, $filterName);
297-
}
298-
299269
public function filterGreater(string $field, bool $isStrict = true, ?string $filterName = null): self
300270
{
301271
$filterName = empty($filterName) ? 'from' : $filterName;
@@ -308,12 +278,6 @@ public function filterGreater(string $field, bool $isStrict = true, ?string $fil
308278
return $this;
309279
}
310280

311-
/** @deprecated use filterLess instead */
312-
public function filterTo(string $field, bool $isStrict = true, ?string $filterName = null): self
313-
{
314-
return $this->filterLess($field, $isStrict, $filterName);
315-
}
316-
317281
public function filterLess(string $field, bool $isStrict = true, ?string $filterName = null): self
318282
{
319283
$filterName = (empty($filterName)) ? 'to' : $filterName;

tests/SearchTraitTest.php

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -274,24 +274,37 @@ public function testSearchQueryWithListFilters()
274274
->getSearchResults();
275275
}
276276

277-
public function testSearchQueryWithFiltersFunctions()
277+
public function testSearchQueryWithChainedFilters()
278278
{
279279
$this->shouldSettablePropertiesBeResetProperty->setValue($this->testRepositoryClass, false);
280280

281281
$this->mockGetSearchResultWithFilters(self::$selectResult);
282282

283+
$this->callEncapsulatedMethod(
284+
$this->testRepositoryClass,
285+
'setAdditionalReservedFilters',
286+
'date_greater',
287+
'date_less',
288+
'updated_at_greater',
289+
'updated_at_less',
290+
);
291+
283292
$this->testRepositoryClass
284293
->searchQuery([
285294
'user_id_in_list' => [1, 2],
286295
'user_id_not_in_list' => [3, 4],
287296
'name' => 'text_name',
297+
'date_greater' => Carbon::now(),
298+
'date_less' => Carbon::now(),
299+
'updated_at_greater' => Carbon::now(),
300+
'updated_at_less' => Carbon::now(),
288301
])
289-
->filterMoreOrEqualThan('date', Carbon::now())
290-
->filterLessOrEqualThan('date', Carbon::now())
291-
->filterMoreOrEqualThan('created_at', Carbon::now())
292-
->filterLessOrEqualThan('created_at', Carbon::now())
293-
->filterMoreThan('updated_at', Carbon::now())
294-
->filterLessThan('updated_at', Carbon::now())
302+
->filterGreater('date', false, 'date_greater')
303+
->filterLess('date', false, 'date_less')
304+
->filterValue('created_at', '>=', Carbon::now())
305+
->filterValue('created_at', '<=', Carbon::now())
306+
->filterGreater('updated_at', true, 'updated_at_greater')
307+
->filterLess('updated_at', true, 'updated_at_less')
295308
->getSearchResults();
296309
}
297310
}

0 commit comments

Comments
 (0)