Skip to content

Commit 62ff023

Browse files
committed
Replaced deprecated helpers with corresponding Str:: and Arr:: functions
1 parent 51e9434 commit 62ff023

File tree

5 files changed

+15
-10
lines changed

5 files changed

+15
-10
lines changed

src/Filters/FiltersExact.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ protected function withRelationConstraint(Builder $query, $value, string $proper
4545
[$relation, $property] = collect(explode('.', $property))
4646
->pipe(function (Collection $parts) {
4747
return [
48-
$parts->except(count($parts) - 1)->map('camel_case')->implode('.'),
48+
$parts->except(count($parts) - 1)->map([Str::class, 'camel'])->implode('.'),
4949
$parts->last(),
5050
];
5151
});

src/Filters/FiltersScope.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@
22

33
namespace Spatie\QueryBuilder\Filters;
44

5+
use Illuminate\Support\Arr;
6+
use Illuminate\Support\Str;
57
use Illuminate\Database\Eloquent\Builder;
68

79
class FiltersScope implements Filter
810
{
911
public function __invoke(Builder $query, $values, string $property) : Builder
1012
{
11-
$scope = camel_case($property);
12-
$values = array_wrap($values);
13+
$scope = Str::camel($property);
14+
$values = Arr::wrap($values);
1315

1416
return $query->$scope(...$values);
1517
}

src/QueryBuilder.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Spatie\QueryBuilder;
44

5+
use Illuminate\Support\Str;
56
use Illuminate\Http\Request;
67
use Illuminate\Support\Collection;
78
use Illuminate\Database\Eloquent\Builder;
@@ -86,7 +87,7 @@ public function allowedFields($fields): self
8687

8788
$this->allowedFields = collect($fields)
8889
->map(function (string $fieldName) {
89-
if (! str_contains($fieldName, '.')) {
90+
if (! Str::contains($fieldName, '.')) {
9091
$modelTableName = $this->getModel()->getTable();
9192

9293
return "{$modelTableName}.{$fieldName}";
@@ -360,14 +361,14 @@ protected function addAppendsToResults(Collection $results)
360361
protected function addIncludesToQuery(Collection $includes)
361362
{
362363
$includes
363-
->map('camel_case')
364+
->map([Str::class, 'camel'])
364365
->map(function (string $include) {
365366
return collect(explode('.', $include));
366367
})
367368
->flatMap(function (Collection $relatedTables) {
368369
return $relatedTables
369370
->mapWithKeys(function ($table, $key) use ($relatedTables) {
370-
$fields = $this->getFieldsForIncludedTable(snake_case($table));
371+
$fields = $this->getFieldsForIncludedTable(Str::snake($table));
371372

372373
$fullRelationName = $relatedTables->slice(0, $key + 1)->implode('.');
373374

@@ -402,9 +403,9 @@ protected function guardAgainstUnknownFields()
402403
{
403404
$fields = $this->request->fields()
404405
->map(function ($fields, $model) {
405-
$tableName = snake_case(preg_replace('/-/', '_', $model));
406+
$tableName = Str::snake(preg_replace('/-/', '_', $model));
406407

407-
$fields = array_map('snake_case', $fields);
408+
$fields = array_map([Str::class, 'snake'], $fields);
408409

409410
return $this->prependFieldsWithTableName($fields, $tableName);
410411
})

src/QueryBuilderServiceProvider.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Spatie\QueryBuilder;
44

5+
use Illuminate\Support\Str;
56
use Illuminate\Http\Request;
67
use Illuminate\Support\Collection;
78
use Illuminate\Support\ServiceProvider;
@@ -66,7 +67,7 @@ public function boot()
6667
return collect($value)->map($this->bindTo($this))->all();
6768
}
6869

69-
if (str_contains($value, ',')) {
70+
if (Str::contains($value, ',')) {
7071
return explode(',', $value);
7172
}
7273

tests/RelationFilterTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Spatie\QueryBuilder\Tests;
44

5+
use Illuminate\Support\Str;
56
use Illuminate\Http\Request;
67
use Spatie\QueryBuilder\Filter;
78
use Spatie\QueryBuilder\QueryBuilder;
@@ -128,7 +129,7 @@ public function it_can_filter_and_reject_results_by_exact_property()
128129
/** @test */
129130
public function given_the_models_table_name_it_does_filter_by_property_rather_than_relation()
130131
{
131-
TestModel::create(['name' => $name = str_random()]);
132+
TestModel::create(['name' => $name = Str::random()]);
132133

133134
$result = $this
134135
->createQueryFromFilterRequest(['test_models.name' => $name])

0 commit comments

Comments
 (0)