diff --git a/src/HydratableInterface.php b/src/HydratableInterface.php new file mode 100644 index 0000000..30b8f45 --- /dev/null +++ b/src/HydratableInterface.php @@ -0,0 +1,8 @@ +validate($data); return parent::store($data, $id); diff --git a/src/Mock/Storage/Memory.php b/src/Mock/Storage/Memory.php index 17e7b33..15b2ebd 100644 --- a/src/Mock/Storage/Memory.php +++ b/src/Mock/Storage/Memory.php @@ -2,15 +2,16 @@ namespace Contracts\Mock\Storage; +use Contracts\RetrieverInterface; use Contracts\StorerInterface; use Contracts\BulkRetrieverInterface; -class Memory implements StorerInterface, BulkRetrieverInterface +class Memory implements RetrieverInterface, StorerInterface, BulkRetrieverInterface { protected $storage = []; - public function retrieve(string $id): ?string + public function retrieve(string $id) { if (isset($this->storage[$id])) { return $this->storage[$id]; @@ -23,7 +24,7 @@ public function retrieveAll(): array return $this->storage; } - public function store(string $data, string $id = null): string + public function store($data, string $id = null): string { if (!isset($id)) { throw new \Exception("An id is required to store the data."); diff --git a/src/RetrieverInterface.php b/src/RetrieverInterface.php index e00bf5b..27e9d86 100644 --- a/src/RetrieverInterface.php +++ b/src/RetrieverInterface.php @@ -10,11 +10,8 @@ interface RetrieverInterface * @param string $id * The identifier for the data. * - * @return string + * @return string | HydratableInterface * The data or null if no data could be retrieved. - * - * @throws \Exception - * No data matched the identifier. */ - public function retrieve(string $id): ?string; + public function retrieve(string $id); } diff --git a/src/StorerInterface.php b/src/StorerInterface.php index 4cb8e11..b8e8eb5 100644 --- a/src/StorerInterface.php +++ b/src/StorerInterface.php @@ -7,7 +7,7 @@ interface StorerInterface /** * Store. * - * @param string $data + * @param string|HydratableInterface $data * The data to be stored. * @param string $id * The identifier for the data. If the act of storing generates the @@ -19,5 +19,5 @@ interface StorerInterface * @throws \Exception * Issues storing the data. */ - public function store(string $data, string $id = null): string; + public function store($data, string $id = null): string; } diff --git a/test/Mock/IdGenerator/SequentialTest.php b/test/Mock/IdGenerator/SequentialTest.php index 3c75bfc..f1e743c 100644 --- a/test/Mock/IdGenerator/SequentialTest.php +++ b/test/Mock/IdGenerator/SequentialTest.php @@ -1,9 +1,7 @@