diff --git a/src/Config.php b/src/Config.php index 402b6e4..d2a0f00 100644 --- a/src/Config.php +++ b/src/Config.php @@ -30,13 +30,6 @@ class Config implements Countable, Iterator, ArrayAccess */ protected $allowModifications; - /** - * Number of elements in configuration data. - * - * @var int - */ - protected $count; - /** * Data within the configuration. * @@ -71,8 +64,6 @@ public function __construct(array $array, $allowModifications = false) } else { $this->data[$key] = $value; } - - $this->count++; } } @@ -126,8 +117,6 @@ public function __set($name, $value) } else { $this->data[$name] = $value; } - - $this->count++; } else { throw new Exception\RuntimeException('Config is read only'); } @@ -200,7 +189,6 @@ public function __unset($name) throw new Exception\InvalidArgumentException('Config is read only'); } elseif (isset($this->data[$name])) { unset($this->data[$name]); - $this->count--; $this->skipNextIteration = true; } } @@ -213,7 +201,7 @@ public function __unset($name) */ public function count() { - return $this->count; + return count($this->data); } /** @@ -360,8 +348,6 @@ public function merge(Config $merge) } else { $this->data[$key] = $value; } - - $this->count++; } } diff --git a/test/ConfigTest.php b/test/ConfigTest.php index bcf2764..9554636 100644 --- a/test/ConfigTest.php +++ b/test/ConfigTest.php @@ -184,6 +184,17 @@ public function testCountAfterMerge() $this->assertEquals(count($data->toArray()), $data->count()); } + public function testCountWithDoubleKeys() + { + $config = new Config(array(), true); + + $config->foo = 1; + $config->foo = 2; + $this->assertSame(2, $config->foo); + $this->assertCount(1, $config->toArray()); + $this->assertCount(1, $config); + } + public function testIterator() { // top level