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

Loosen storage contracts #10

Merged
merged 4 commits into from
Oct 21, 2019
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: 8 additions & 0 deletions src/HydratableInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Contracts;

interface HydratableInterface extends \JsonSerializable
{
public static function hydrate(string $json, $instance = null);
}
4 changes: 3 additions & 1 deletion src/Mock/IdGenerator/Sequential.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace Contracts\Mock\IdGenerator;

class Sequential implements \Contracts\IdGeneratorInterface
use Contracts\IdGeneratorInterface;

class Sequential implements IdGeneratorInterface
{
private $id = 0;
public function generate()
Expand Down
2 changes: 1 addition & 1 deletion src/Mock/Storage/JsonObjectMemory.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function retrieveAll(): array
return $results;
}

public function store(string $data, string $id = null): string
public function store($data, string $id = null): string
{
$this->validate($data);
return parent::store($data, $id);
Expand Down
7 changes: 4 additions & 3 deletions src/Mock/Storage/Memory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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.");
Expand Down
7 changes: 2 additions & 5 deletions src/RetrieverInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
4 changes: 2 additions & 2 deletions src/StorerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}
2 changes: 0 additions & 2 deletions test/Mock/IdGenerator/SequentialTest.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<?php


namespace ContractsTest\Mock\IdGenerator;


use Contracts\Mock\IdGenerator\Sequential;
use PHPUnit\Framework\TestCase;

Expand Down