Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API Restore nullable params #76

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/Collections/DeltaConfigCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand All @@ -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);
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/Collections/MemoryConfigCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/Collections/MutableConfigCollectionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
14 changes: 7 additions & 7 deletions tests/Collections/DeltaConfigCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -144,16 +144,16 @@ public function testRemove()
$this->assertFalse($collection->isDeltaReset('Second')); // Only partial reset so false
$this->assertEquals(
[
'string' => ['bobnew'],
'string' => 'bobnew',
'bool' => false,
],
$collection->get('Second')
);
$this->assertEquals(
[
[
'type' => 'merge',
'config' => ['string' => ['bobnew']],
'type' => 'set',
'config' => ['string' => 'bobnew'],
],
[
'type' => DeltaConfigCollection::REMOVE,
Expand All @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion tests/Collections/MemoryConfigCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));

Expand Down