Skip to content
This repository was archived by the owner on Nov 4, 2021. It is now read-only.

Commit e7068dd

Browse files
authored
Merge pull request #201 from lucasmichot/feature/do-not-use-array-helpers
Do not use array helpers
2 parents 096fa57 + ee58ce7 commit e7068dd

File tree

5 files changed

+19
-12
lines changed

5 files changed

+19
-12
lines changed

src/Builders/FilterBuilder.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace ScoutElastic\Builders;
44

55
use Laravel\Scout\Builder;
6+
use Illuminate\Support\Arr;
67
use Illuminate\Database\Eloquent\Model;
78

89
class FilterBuilder extends Builder
@@ -515,7 +516,7 @@ public function select($fields)
515516
{
516517
$this->select = array_merge(
517518
$this->select,
518-
array_wrap($fields)
519+
Arr::wrap($fields)
519520
);
520521

521522
return $this;
@@ -540,7 +541,7 @@ public function withTrashed()
540541
{
541542
$this->wheres['must'] = collect($this->wheres['must'])
542543
->filter(function ($item) {
543-
return array_get($item, 'term.__soft_deleted') !== 0;
544+
return Arr::get($item, 'term.__soft_deleted') !== 0;
544545
})
545546
->values()
546547
->all();

src/ElasticEngine.php

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

55
use stdClass;
66
use Laravel\Scout\Builder;
7+
use Illuminate\Support\Arr;
78
use Laravel\Scout\Engines\Engine;
89
use ScoutElastic\Payloads\TypePayload;
910
use Illuminate\Database\Eloquent\Model;
@@ -296,7 +297,7 @@ public function map(Builder $builder, $results, $model)
296297

297298
$primaryKey = $model->getKeyName();
298299

299-
$columns = array_get($results, '_payload.body._source');
300+
$columns = Arr::get($results, '_payload.body._source');
300301

301302
if (is_null($columns)) {
302303
$columns = ['*'];

src/Payloads/RawPayload.php

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

33
namespace ScoutElastic\Payloads;
44

5+
use Illuminate\Support\Arr;
6+
57
class RawPayload
68
{
79
/**
@@ -21,7 +23,7 @@ class RawPayload
2123
public function set($key, $value)
2224
{
2325
if (! is_null($key)) {
24-
array_set($this->payload, $key, $value);
26+
Arr::set($this->payload, $key, $value);
2527
}
2628

2729
return $this;
@@ -67,7 +69,7 @@ public function setIfNotNull($key, $value)
6769
*/
6870
public function has($key)
6971
{
70-
return array_has($this->payload, $key);
72+
return Arr::has($this->payload, $key);
7173
}
7274

7375
/**
@@ -80,15 +82,15 @@ public function has($key)
8082
public function add($key, $value)
8183
{
8284
if (! is_null($key)) {
83-
$currentValue = array_get($this->payload, $key, []);
85+
$currentValue = Arr::get($this->payload, $key, []);
8486

8587
if (! is_array($currentValue)) {
86-
$currentValue = array_wrap($currentValue);
88+
$currentValue = Arr::wrap($currentValue);
8789
}
8890

8991
$currentValue[] = $value;
9092

91-
array_set($this->payload, $key, $currentValue);
93+
Arr::set($this->payload, $key, $currentValue);
9294
}
9395

9496
return $this;
@@ -119,6 +121,6 @@ public function addIfNotEmpty($key, $value)
119121
*/
120122
public function get($key = null, $default = null)
121123
{
122-
return array_get($this->payload, $key, $default);
124+
return Arr::get($this->payload, $key, $default);
123125
}
124126
}

src/Searchable.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace ScoutElastic;
44

55
use Exception;
6+
use Illuminate\Support\Arr;
67
use ScoutElastic\Builders\FilterBuilder;
78
use ScoutElastic\Builders\SearchBuilder;
89
use Laravel\Scout\Searchable as ScoutSearchable;
@@ -73,7 +74,7 @@ public function getMapping()
7374
$mapping = $this->mapping ?? [];
7475

7576
if ($this::usesSoftDelete() && config('scout.soft_delete', false)) {
76-
array_set($mapping, 'properties.__soft_deleted', ['type' => 'integer']);
77+
Arr::set($mapping, 'properties.__soft_deleted', ['type' => 'integer']);
7778
}
7879

7980
return $mapping;

tests/Config.php

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

33
namespace ScoutElastic\Tests;
44

5+
use Illuminate\Support\Arr;
6+
57
class Config
68
{
79
/**
@@ -15,7 +17,7 @@ class Config
1517
*/
1618
public static function set($key, $value)
1719
{
18-
array_set(static::$values, $key, $value);
20+
Arr::set(static::$values, $key, $value);
1921
}
2022

2123
/**
@@ -25,7 +27,7 @@ public static function set($key, $value)
2527
*/
2628
public static function get($key = null, $default = null)
2729
{
28-
return array_get(static::$values, $key, $default);
30+
return Arr::get(static::$values, $key, $default);
2931
}
3032

3133
/**

0 commit comments

Comments
 (0)