From c0cd27a330a52e222c4b41da6348dd0a0ac3cd4b Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Thu, 8 Dec 2022 11:08:31 +1300 Subject: [PATCH] API Restore nullable params --- src/Collections/DeltaConfigCollection.php | 8 ++++---- src/Collections/MemoryConfigCollection.php | 4 ++-- .../MutableConfigCollectionInterface.php | 4 ++-- tests/Collections/DeltaConfigCollectionTest.php | 14 +++++++------- tests/Collections/MemoryConfigCollectionTest.php | 2 +- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/Collections/DeltaConfigCollection.php b/src/Collections/DeltaConfigCollection.php index 41d4ac5..57f1a53 100644 --- a/src/Collections/DeltaConfigCollection.php +++ b/src/Collections/DeltaConfigCollection.php @@ -145,9 +145,9 @@ public function isDeltaReset($class = null) ); } - public function unserialize($serialized) + public function __unserialize(array $data): void { - parent::__unserialize($serialized); + parent::__unserialize($data); $this->postInit(); } @@ -166,7 +166,7 @@ protected function postInit() $this->getDeltaMiddleware()->setCollection($this); } - public function set(string $class, string|null $name, mixed $data, array $metadata = []): static + public function set(string $class, ?string $name, mixed $data, array $metadata = []): static { // Check config to merge $this->clearDeltas($class, $name); @@ -184,7 +184,7 @@ public function set(string $class, string|null $name, mixed $data, array $metada return $this; } - public function remove(string $class, string|null $name): static + public function remove(string $class, ?string $name = null): static { // Check config to merge $this->clearDeltas($class, $name); diff --git a/src/Collections/MemoryConfigCollection.php b/src/Collections/MemoryConfigCollection.php index 762f603..5963a5c 100644 --- a/src/Collections/MemoryConfigCollection.php +++ b/src/Collections/MemoryConfigCollection.php @@ -75,7 +75,7 @@ public function transform($transformers) return $this; } - public function set(string $class, string|null $name, mixed $data, array $metadata = []): static + public function set(string $class, ?string $name, mixed $data, array $metadata = []): static { $this->saveMetadata($class, $metadata); @@ -172,7 +172,7 @@ public function exists($class, $name = null, $excludeMiddleware = 0) return true; } - public function remove(string $class, string|null $name): static + public function remove(string $class, ?string $name = null): static { $classKey = strtolower($class ?? ''); if ($name) { diff --git a/src/Collections/MutableConfigCollectionInterface.php b/src/Collections/MutableConfigCollectionInterface.php index 58a5654..0131e18 100644 --- a/src/Collections/MutableConfigCollectionInterface.php +++ b/src/Collections/MutableConfigCollectionInterface.php @@ -8,7 +8,7 @@ interface MutableConfigCollectionInterface extends ConfigCollectionInterface * Sets config for a given field. * Set name to null to set the config for the entire class. */ - public function set(string $class, string $name, mixed $value, array $metadata = []): static; + public function set(string $class, ?string $name, mixed $value, array $metadata = []): static; /** * Merge a config for a class, or a field on that class @@ -18,7 +18,7 @@ public function merge(string $class, string $name, array $value): static; /** * Remove config for a given class, or field on that class */ - public function remove(string $class, string $name): static; + public function remove(string $class, ?string $name = null): static; /** * Delete all entries diff --git a/tests/Collections/DeltaConfigCollectionTest.php b/tests/Collections/DeltaConfigCollectionTest.php index 360e9f7..bb6a96c 100644 --- a/tests/Collections/DeltaConfigCollectionTest.php +++ b/tests/Collections/DeltaConfigCollectionTest.php @@ -122,9 +122,9 @@ public function testMerge() public function testRemove() { $collection = $this->scaffoldCollection(); - $collection->merge('First', 'key', ['value']); - $collection->remove('First', null); - $collection->merge('Second', 'string', ['bobnew']); + $collection->set('First', 'key', 'value'); + $collection->remove('First'); + $collection->set('Second', 'string', 'bobnew'); $collection->merge('Second', 'array', ['four' => 4]); $collection->remove('Second', 'array'); @@ -144,7 +144,7 @@ public function testRemove() $this->assertFalse($collection->isDeltaReset('Second')); // Only partial reset so false $this->assertEquals( [ - 'string' => ['bobnew'], + 'string' => 'bobnew', 'bool' => false, ], $collection->get('Second') @@ -152,8 +152,8 @@ public function testRemove() $this->assertEquals( [ [ - 'type' => 'merge', - 'config' => ['string' => ['bobnew']], + 'type' => 'set', + 'config' => ['string' => 'bobnew'], ], [ 'type' => DeltaConfigCollection::REMOVE, @@ -167,7 +167,7 @@ public function testRemove() public function testClear() { $collection = $this->scaffoldCollection(); - $collection->merge('First', 'key', ['value']); + $collection->set('First', 'key', 'value'); $collection->remove('First', 'string'); $collection->removeAll(); diff --git a/tests/Collections/MemoryConfigCollectionTest.php b/tests/Collections/MemoryConfigCollectionTest.php index c9c60c4..adc8667 100644 --- a/tests/Collections/MemoryConfigCollectionTest.php +++ b/tests/Collections/MemoryConfigCollectionTest.php @@ -17,7 +17,7 @@ public function testGetSetAndDelete() $collection->set('test2', null, 'value'); $this->assertTrue($collection->exists('test2')); - $collection->remove('test', null); + $collection->remove('test'); $this->assertFalse($collection->exists('test')); $this->assertEquals([], $collection->get('test'));