Skip to content

Commit d888386

Browse files
authored
Merge pull request #23 from Icinga/do-not-mutate-property-when-setting-it
Properties: Don't mutate properties when setting them
2 parents 517ce57 + d34c4e9 commit d888386

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
*
@@ -95,10 +105,6 @@ protected function setProperty($key, $value)
95105
{
96106
$this->properties[$key] = $value;
97107

98-
if ($this->accessorsAndMutatorsEnabled) {
99-
$this->mutateProperty($key);
100-
}
101-
102108
return $this;
103109
}
104110

@@ -117,7 +123,7 @@ protected function mutateProperty($key)
117123
$value = array_key_exists($key, $this->properties)
118124
? $this->properties[$key]
119125
: null;
120-
$this->mutatedProperties[$key] = $value; // Prevents repeated checks
126+
$this->mutatedProperties[$key] = true; // Prevents repeated checks
121127

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

0 commit comments

Comments
 (0)