Skip to content

Commit b6661a9

Browse files
authored
Replace legacy array helper functions with Arr class methods (#659)
1 parent 8af1704 commit b6661a9

File tree

21 files changed

+79
-58
lines changed

21 files changed

+79
-58
lines changed

src/Database/Attach/File.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Storage;
77
use Response;
88
use File as FileHelper;
9+
use Illuminate\Support\Arr;
910
use October\Rain\Database\Model;
1011
use October\Rain\Resize\Resizer;
1112
use Symfony\Component\HttpFoundation\File\UploadedFile;
@@ -327,7 +328,7 @@ public function output($disposition = 'inline', $returnResponse = true)
327328
*/
328329
public function outputThumb($width, $height, $options = [], $returnResponse = true)
329330
{
330-
$disposition = array_get($options, 'disposition', 'inline');
331+
$disposition = Arr::get($options, 'disposition', 'inline');
331332
$options = $this->getDefaultThumbOptions($options);
332333

333334
// Generate thumb if not existing already

src/Database/Models/DeferredBinding.php

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

33
use Event;
44
use Carbon\Carbon;
5+
use Illuminate\Support\Arr;
56
use October\Rain\Database\Model;
67
use Throwable;
78

@@ -209,12 +210,12 @@ protected function deleteSlaveRecord()
209210
}
210211

211212
$options = $masterObject->getRelationDefinition($this->master_field);
212-
if (!array_get($options, 'delete', false)) {
213+
if (!Arr::get($options, 'delete', false)) {
213214
return;
214215
}
215216

216217
// Only delete it if the relationship is null
217-
$foreignKey = array_get($options, 'key', $masterObject->getForeignKey());
218+
$foreignKey = Arr::get($options, 'key', $masterObject->getForeignKey());
218219
if ($foreignKey && !$relatedObj->$foreignKey) {
219220
$relatedObj->delete();
220221
}

src/Database/Relations/AttachOneOrMany.php

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

33
use Illuminate\Database\Eloquent\Model;
44
use Illuminate\Database\Eloquent\Builder;
5+
use Illuminate\Support\Arr;
56
use October\Rain\Database\Attach\File as FileModel;
67
use Symfony\Component\HttpFoundation\File\UploadedFile;
78

@@ -368,7 +369,7 @@ public function remove(Model $model, $sessionKey = null)
368369

369370
$options = $this->parent->getRelationDefinition($this->relationName);
370371

371-
if (array_get($options, 'delete', false)) {
372+
if (Arr::get($options, 'delete', false)) {
372373
$model->delete();
373374
}
374375
else {
@@ -477,7 +478,7 @@ protected function ensureRelationIsEmpty()
477478
{
478479
$options = $this->parent->getRelationDefinition($this->relationName);
479480

480-
if (array_get($options, 'delete', false)) {
481+
if (Arr::get($options, 'delete', false)) {
481482
$this->delete();
482483
}
483484
else {

src/Database/Relations/DefinedConstraints.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php namespace October\Rain\Database\Relations;
22

33
use Illuminate\Database\Eloquent\Relations\BelongsToMany as BelongsToManyBase;
4+
use Illuminate\Support\Arr;
45

56
/**
67
* DefinedConstraints handles the constraints and filters defined by a relation
@@ -33,28 +34,28 @@ public function addDefinedConstraintsToRelation($relation, ?array $args = null)
3334
}
3435

3536
// Default models (belongsTo, hasOne, hasOneThrough, morphOne)
36-
if ($defaultData = array_get($args, 'default')) {
37+
if ($defaultData = Arr::get($args, 'default')) {
3738
$relation->withDefault($defaultData);
3839
}
3940

4041
// Pivot data (belongsToMany, morphToMany, morphByMany)
41-
if ($pivotData = array_get($args, 'pivot')) {
42+
if ($pivotData = Arr::get($args, 'pivot')) {
4243
$relation->withPivot($pivotData);
4344
}
4445

4546
// Pivot incrementing key (belongsToMany, morphToMany, morphByMany)
46-
if ($pivotKey = array_get($args, 'pivotKey')) {
47+
if ($pivotKey = Arr::get($args, 'pivotKey')) {
4748
$relation->withPivot($pivotKey);
4849
}
4950

5051
// Pivot timestamps (belongsToMany, morphToMany, morphByMany)
51-
if (array_get($args, 'timestamps')) {
52+
if (Arr::get($args, 'timestamps')) {
5253
$relation->withTimestamps();
5354
}
5455

5556
// Count "helper" relation
5657
// @deprecated use Laravel withCount() method instead
57-
if (array_get($args, 'count')) {
58+
if (Arr::get($args, 'count')) {
5859
if ($relation instanceof BelongsToManyBase) {
5960
$relation->countMode = true;
6061
$keyName = $relation->getQualifiedForeignPivotKeyName();
@@ -79,14 +80,14 @@ public function addDefinedConstraintsToQuery($query, ?array $args = null)
7980
}
8081

8182
// Conditions
82-
if ($conditions = array_get($args, 'conditions')) {
83+
if ($conditions = Arr::get($args, 'conditions')) {
8384
$query->whereRaw($conditions);
8485
}
8586

8687
// Sort order
8788
// @deprecated count is deprecated
88-
$hasCountArg = array_get($args, 'count') !== null;
89-
if (($orderBy = array_get($args, 'order')) && !$hasCountArg) {
89+
$hasCountArg = Arr::get($args, 'count') !== null;
90+
if (($orderBy = Arr::get($args, 'order')) && !$hasCountArg) {
9091
if (!is_array($orderBy)) {
9192
$orderBy = [$orderBy];
9293
}
@@ -105,7 +106,7 @@ public function addDefinedConstraintsToQuery($query, ?array $args = null)
105106
}
106107

107108
// Scope
108-
if ($scope = array_get($args, 'scope')) {
109+
if ($scope = Arr::get($args, 'scope')) {
109110
if (is_string($scope)) {
110111
$query->$scope($this->parent);
111112
}

src/Database/Relations/HasOneOrMany.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php namespace October\Rain\Database\Relations;
22

33
use Illuminate\Database\Eloquent\Model;
4+
use Illuminate\Support\Arr;
45

56
/**
67
* HasOneOrMany
@@ -253,7 +254,7 @@ public function remove(Model $model, $sessionKey = null)
253254
$options = $this->parent->getRelationDefinition($this->relationName);
254255

255256
// Delete or orphan the model
256-
if (array_get($options, 'delete', false)) {
257+
if (Arr::get($options, 'delete', false)) {
257258
$model->delete();
258259
}
259260
else {
@@ -304,7 +305,7 @@ protected function ensureRelationIsEmpty()
304305
{
305306
$options = $this->parent->getRelationDefinition($this->relationName);
306307

307-
if (array_get($options, 'delete', false)) {
308+
if (Arr::get($options, 'delete', false)) {
308309
$this->delete();
309310
}
310311
else {

src/Database/Relations/MorphOneOrMany.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php namespace October\Rain\Database\Relations;
22

33
use Illuminate\Database\Eloquent\Model;
4+
use Illuminate\Support\Arr;
45

56
/**
67
* MorphOneOrMany
@@ -244,7 +245,7 @@ public function remove(Model $model, $sessionKey = null)
244245
$options = $this->parent->getRelationDefinition($this->relationName);
245246

246247
// Delete or orphan the model
247-
if (array_get($options, 'delete', false)) {
248+
if (Arr::get($options, 'delete', false)) {
248249
$model->delete();
249250
}
250251
else {
@@ -298,7 +299,7 @@ protected function ensureRelationIsEmpty()
298299
{
299300
$options = $this->parent->getRelationDefinition($this->relationName);
300301

301-
if (array_get($options, 'delete', false)) {
302+
if (Arr::get($options, 'delete', false)) {
302303
$this->delete();
303304
}
304305
else {

src/Database/Traits/Encryptable.php

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

33
use Crypt;
44
use Exception;
5+
use Illuminate\Support\Arr;
56

67
/**
78
* Encryptable database trait
@@ -49,8 +50,8 @@ public function initializeEncryptable()
4950
$this->bindEvent('model.beforeGetAttribute', function ($key) {
5051
if (
5152
in_array($key, $this->getEncryptableAttributes()) &&
52-
array_get($this->attributes, $key) !== null &&
53-
array_get($this->attributes, $key) !== ''
53+
Arr::get($this->attributes, $key) !== null &&
54+
Arr::get($this->attributes, $key) !== ''
5455
) {
5556
return $this->getEncryptableValue($key);
5657
}

src/Database/Traits/Multisite.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php namespace October\Rain\Database\Traits;
22

3+
use Illuminate\Support\Arr;
34
use Site;
45
use October\Rain\Database\Scopes\MultisiteScope;
56
use Exception;
@@ -331,7 +332,7 @@ public function getMultisiteConfig($key, $default = null)
331332
return $default;
332333
}
333334

334-
return array_get($this->propagatableSync, $key, $default);
335+
return Arr::get($this->propagatableSync, $key, $default);
335336
}
336337

337338
/**

src/Database/Traits/Revisionable.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
use Exception;
55
use DateTime;
66
use Illuminate\Database\Eloquent\Model as EloquentModel;
7+
use Illuminate\Support\Arr;
78

89
/**
910
* Revisionable trait tracks changes to specific attributes
@@ -79,7 +80,7 @@ public function revisionableAfterUpdate()
7980

8081
$toSave[] = [
8182
'field' => $attribute,
82-
'old_value' => array_get($this->original, $attribute),
83+
'old_value' => Arr::get($this->original, $attribute),
8384
'new_value' => $value,
8485
'revisionable_type' => $relationObject->getMorphClass(),
8586
'revisionable_id' => $this->getKey(),

src/Database/Traits/SimpleTree.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php namespace October\Rain\Database\Traits;
22

3+
use Illuminate\Support\Arr;
34
use October\Rain\Database\Collection;
45
use October\Rain\Database\TreeCollection;
56
use Exception;
@@ -228,7 +229,7 @@ public function scopeListsNested($query, $column, $key = null, $indent = '&nbsp;
228229
}
229230

230231
// Add the children
231-
$childItems = array_get($map, $item->{$idName}, []);
232+
$childItems = Arr::get($map, $item->{$idName}, []);
232233
if (count($childItems) > 0) {
233234
$result = $result + $buildCollection($childItems, $map, $depth + 1);
234235
}

0 commit comments

Comments
 (0)