Skip to content

Commit

Permalink
Merge pull request #19 from alwaysblank/12-allow-removing-data
Browse files Browse the repository at this point in the history
  • Loading branch information
alwaysblank authored Oct 28, 2022
2 parents e71624f + 3346d6e commit 877692c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/Brief.php
Original file line number Diff line number Diff line change
Expand Up @@ -903,4 +903,23 @@ protected function resolveInternalKey($key) {

return null;
}

/**
* Remove data from the Brief.
*
* This will resolve aliases and delete the data they point to,
* but *not* the aliases themselves.
*
* @param $key
*
* @return void
*/
public function delete($key) {
$internalKey = $this->resolveInternalKey($key);
if ($internalKey === null) {
// Doesn't exist, so nothing to do.
return;
}
unset($this->store[$internalKey]);
}
}
12 changes: 12 additions & 0 deletions tests/BriefTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,18 @@ public function testCanUserCustomEmptyFunction(): void
], ['isEmpty' => $test]);
$this->assertFalse($Brieful->isEmpty());
}

public function testCanDeleteDataFromBrief(): void {
$Brief = Brief::make(['key' => 'value']);
$this->assertEquals('value', $Brief->key);
$Brief->delete('key');
$this->assertNull($Brief->value);
$NumericBrief = Brief::make(['value', 'not-value']);
$this->assertEquals('value', $NumericBrief->_0);
$NumericBrief->delete(0);
$this->assertNull($NumericBrief->_0);

}
}

/**
Expand Down

0 comments on commit 877692c

Please sign in to comment.