Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Zimmermann committed May 2, 2020
1 parent aa43701 commit 7864d26
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions src/Type/ObjectStoreObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
namespace Phore\ObjectStore\Type;


use Exception;
use Phore\Core\Exception\NotFoundException;
use Phore\ObjectStore\Driver\ObjectStoreDriver;

use Psr\Http\Message\StreamInterface;

/**
Expand Down Expand Up @@ -66,6 +66,7 @@ public function exists(): bool

/**
* @return string
* @throws NotFoundException
*/
public function get(): string
{
Expand All @@ -74,6 +75,7 @@ public function get(): string

/**
* @return StreamInterface
* @throws NotFoundException
*/
public function getStream(): StreamInterface
{
Expand All @@ -82,25 +84,29 @@ public function getStream(): StreamInterface

/**
* @return array
* @throws NotFoundException
*/
public function getJson(): array
{
$data = $this->get();
$ret = json_decode($data, true);
if ($ret === null)
if ($ret === null) {
throw new \InvalidArgumentException("Cannot json-decode data from object '$this->objectId'");
}
return $ret;
}

/**
* @return array
* @throws NotFoundException
*/
public function getYaml(): array
{
$data = $this->get();
$ret = yaml_parse($data);
if ($ret === false)
if ($ret === false) {
throw new \InvalidArgumentException("Cannot yaml_parse data from object '$this->objectId'");
}
return $ret;
}

Expand Down Expand Up @@ -139,15 +145,17 @@ public function putStream($resource): self
* @param null $key
* @param null $default
* @return array|null
* @throws \Exception
* @throws Exception
*/
public function getMeta($key = null, $default = null)
public function getMeta($key = null, $default = null): ?array
{
if (!$this->metaData)
if (!$this->metaData) {
$this->metaData = $this->driver->getMeta($this->objectId);
}
$data = $this->metaData;
if ($key !== null)
if ($key !== null) {
return phore_pluck($key, $data, $default);
}
return $data;
}

Expand Down Expand Up @@ -187,7 +195,7 @@ public function rename(string $newObjectName): ObjectStoreObject
/**
* @throws NotFoundException
*/
public function remove()
public function remove(): void
{
$this->driver->remove($this->objectId);
}
Expand All @@ -200,7 +208,7 @@ public function remove()
*
* @param string $data
*/
public function append(string $data)
public function append(string $data): void
{
$this->driver->append($this->objectId, $data);
}
Expand Down

0 comments on commit 7864d26

Please sign in to comment.