diff --git a/src/Properties.php b/src/Properties.php index ac4d539..1381b26 100644 --- a/src/Properties.php +++ b/src/Properties.php @@ -2,7 +2,6 @@ namespace ipl\Stdlib; -use Closure; use OutOfBoundsException; /** @@ -13,12 +12,6 @@ trait Properties /** @var array */ private $properties = []; - /** @var array */ - private $mutatedProperties = []; - - /** @var bool Whether accessors and mutators are enabled */ - protected $accessorsAndMutatorsEnabled = false; - /** * Get whether this class has any properties * @@ -38,17 +31,7 @@ public function hasProperties() */ public function hasProperty($key) { - if (array_key_exists($key, $this->properties)) { - return true; - } elseif ($this->accessorsAndMutatorsEnabled) { - $mutator = 'mutate' . Str::camel($key) . 'Property'; - - if (method_exists($this, $mutator)) { - return true; - } - } - - return false; + return array_key_exists($key, $this->properties); } /** @@ -78,14 +61,6 @@ public function setProperties(array $properties) */ protected function getProperty($key) { - if (isset($this->properties[$key]) && $this->properties[$key] instanceof Closure) { - $this->setProperty($key, $this->properties[$key]($this)); - } - - if ($this->accessorsAndMutatorsEnabled) { - $this->mutateProperty($key); - } - if (array_key_exists($key, $this->properties)) { return $this->properties[$key]; } @@ -108,29 +83,6 @@ protected function setProperty($key, $value) return $this; } - /** - * Try to mutate the given key - * - * @param string $key - * @todo Support for generators, if needed - */ - protected function mutateProperty($key) - { - if (array_key_exists($key, $this->mutatedProperties)) { - return; - } - - $value = array_key_exists($key, $this->properties) - ? $this->properties[$key] - : null; - $this->mutatedProperties[$key] = true; // Prevents repeated checks - - $mutator = Str::camel('mutate_' . $key) . 'Property'; - if (method_exists($this, $mutator)) { - $this->properties[$key] = $this->$mutator($value); - } - } - /** * Check whether an offset exists * @@ -140,10 +92,6 @@ protected function mutateProperty($key) */ public function offsetExists($offset): bool { - if ($this->accessorsAndMutatorsEnabled) { - $this->mutateProperty($offset); - } - return isset($this->properties[$offset]); } @@ -179,7 +127,6 @@ public function offsetSet($offset, $value): void public function offsetUnset($offset): void { unset($this->properties[$offset]); - unset($this->mutatedProperties[$offset]); } /** diff --git a/tests/PropertiesTest.php b/tests/PropertiesTest.php index 73b0d04..4c044cf 100644 --- a/tests/PropertiesTest.php +++ b/tests/PropertiesTest.php @@ -96,21 +96,6 @@ public function testUnsetForPropertyAccess() $subject->foo; } - public function testGetMutatorGetsCalled() - { - $subject = new TestClassUsingThePropertiesTrait(); - - $this->assertSame('foobar', $subject->foobar); - } - - public function testSetMutatorGetsCalled() - { - $subject = new TestClassUsingThePropertiesTrait(); - $subject->special = 'foobar'; - - $this->assertSame('FOOBAR', $subject->special); - } - public function testGetPropertiesReturnsEmptyArrayIfUnset() { $this->markTestSkipped('Properties::getProperties() not yet implemented'); diff --git a/tests/TestClassUsingThePropertiesTrait.php b/tests/TestClassUsingThePropertiesTrait.php index 4b4236e..7d5a41e 100644 --- a/tests/TestClassUsingThePropertiesTrait.php +++ b/tests/TestClassUsingThePropertiesTrait.php @@ -7,19 +7,4 @@ class TestClassUsingThePropertiesTrait implements \ArrayAccess { use Properties; - - public function __construct() - { - $this->accessorsAndMutatorsEnabled = true; - } - - public function mutateFoobarProperty() - { - return 'foobar'; - } - - public function mutateSpecialProperty($value) - { - return strtoupper($value); - } }