Skip to content
This repository was archived by the owner on Sep 28, 2022. It is now read-only.

Commit c5b1966

Browse files
committed
Merge pull request #1 from larapack/analysis-z3w7o1
Applied fixes from StyleCI
2 parents 807991d + a6909d3 commit c5b1966

File tree

1 file changed

+36
-33
lines changed

1 file changed

+36
-33
lines changed

src/Larapack/AttributePurging/Purgeable.php

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,94 +2,96 @@
22

33
namespace Larapack\AttributePurging;
44

5-
use Exception;
6-
75
trait Purgeable
86
{
97
/**
108
* @var array List of attribute names which should not be saved to the database.
11-
*
9+
*
1210
* protected $purge = [];
1311
*/
14-
12+
1513
/**
1614
* @var array List of original attribute values before they were purged.
1715
*/
1816
protected $originalPurgeableValues = [];
19-
17+
2018
/**
2119
* Boot the purgeable trait for a model.
20+
*
2221
* @return void
2322
*/
2423
public static function bootPurgeable()
2524
{
2625
/*
2726
* Remove any purge attributes from the data set
2827
*/
29-
static::creating(function($model){
28+
static::creating(function ($model) {
3029
$model->purgeAttributes();
3130
});
32-
33-
static::updating(function($model){
31+
32+
static::updating(function ($model) {
3433
$model->purgeAttributes();
3534
});
36-
37-
static::created(function($model){
35+
36+
static::created(function ($model) {
3837
$model->restorePurgedValues();
3938
});
40-
41-
static::updated(function($model){
39+
40+
static::updated(function ($model) {
4241
$model->restorePurgedValues();
4342
});
4443
}
45-
44+
4645
/**
4746
* Removes purged attributes from the dataset, used before saving.
47+
*
4848
* @param $attributes mixed Attribute(s) to purge, if unspecified, $purgable property is used
49+
*
4950
* @return array Current attribute set
5051
*/
5152
public function purgeAttributes($attributesToPurge = null)
5253
{
53-
if ($attributesToPurge !== null)
54+
if ($attributesToPurge !== null) {
5455
$purgeable = is_array($attributesToPurge) ? $attributesToPurge : [$attributesToPurge];
55-
else
56+
} else {
5657
$purgeable = $this->getPurgeableAttributes();
57-
58+
}
59+
5860
$attributes = $this->getAttributes();
59-
61+
6062
$cleanAttributes = array_diff_key($attributes, array_flip($purgeable));
61-
63+
6264
$originalAttributes = array_diff_key($attributes, $cleanAttributes);
63-
64-
if (is_array($this->originalPurgeableValues))
65+
66+
if (is_array($this->originalPurgeableValues)) {
6567
$this->originalPurgeableValues = array_merge($this->originalPurgeableValues, $originalAttributes);
66-
else
68+
} else {
6769
$this->originalPurgeableValues = $originalAttributes;
68-
70+
}
71+
6972
return $this->attributes = $cleanAttributes;
7073
}
71-
74+
7275
/**
7376
* Returns a collection of fields that will be hashed.
7477
*/
7578
public function getPurgeableAttributes()
7679
{
77-
if (property_exists(get_called_class(), 'purge'))
78-
{
79-
return $this->purge;
80-
}
81-
82-
return [];
83-
}
84-
80+
if (property_exists(get_called_class(), 'purge')) {
81+
return $this->purge;
82+
}
83+
84+
return [];
85+
}
86+
8587
/**
8688
* Returns the original values of any purged attributes.
8789
*/
8890
public function getOriginalPurgeValues()
8991
{
9092
return $this->originalPurgeableValues;
9193
}
92-
94+
9395
/**
9496
* Returns the original values of any purged attributes.
9597
*/
@@ -99,13 +101,14 @@ public function getOriginalPurgeValue($attribute)
99101
? $this->originalPurgeableValues[$attribute]
100102
: null;
101103
}
102-
104+
103105
/**
104106
* Restores the original values of any purged attributes.
105107
*/
106108
public function restorePurgedValues()
107109
{
108110
$this->attributes = array_merge($this->getAttributes(), $this->originalPurgeableValues);
111+
109112
return $this;
110113
}
111114
}

0 commit comments

Comments
 (0)