Skip to content

Commit d34c4e9

Browse files
committed
Properties: Don't mutate properties when setting them
1 parent f6c97d8 commit d34c4e9

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/Properties.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,24 @@
1111
trait Properties
1212
{
1313
/** @var array */
14-
protected $properties = [];
14+
private $properties = [];
1515

1616
/** @var array */
17-
protected $mutatedProperties = [];
17+
private $mutatedProperties = [];
1818

1919
/** @var bool Whether accessors and mutators are enabled */
2020
protected $accessorsAndMutatorsEnabled = false;
2121

22+
/**
23+
* Get whether this class has any properties
24+
*
25+
* @return bool
26+
*/
27+
public function hasProperties()
28+
{
29+
return ! empty($this->properties);
30+
}
31+
2232
/**
2333
* Get whether a property with the given key exists
2434
*
@@ -97,10 +107,6 @@ protected function setProperty($key, $value)
97107
{
98108
$this->properties[$key] = $value;
99109

100-
if ($this->accessorsAndMutatorsEnabled) {
101-
$this->mutateProperty($key);
102-
}
103-
104110
return $this;
105111
}
106112

@@ -119,7 +125,7 @@ protected function mutateProperty($key)
119125
$value = array_key_exists($key, $this->properties)
120126
? $this->properties[$key]
121127
: null;
122-
$this->mutatedProperties[$key] = $value; // Prevents repeated checks
128+
$this->mutatedProperties[$key] = true; // Prevents repeated checks
123129

124130
$mutator = Str::camel('mutate_' . $key) . 'Property';
125131
if (method_exists($this, $mutator)) {

0 commit comments

Comments
 (0)