Skip to content

Commit

Permalink
Merge pull request #11 from stefanak-michal/method_return_null
Browse files Browse the repository at this point in the history
added support for method to return null
  • Loading branch information
stefanak-michal authored Aug 4, 2021
2 parents 09570d3 + 40675b6 commit 9639d3d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

PHP API library following Deepr specification.

![](https://img.shields.io/badge/phpunit-passed-success) ![](https://img.shields.io/badge/coverage-96%25-green) ![](https://img.shields.io/github/stars/stefanak-michal/deepr-php) ![](https://img.shields.io/packagist/dt/stefanak-michal/deepr-php) ![](https://img.shields.io/github/v/release/stefanak-michal/deepr-php) ![](https://img.shields.io/github/commits-since/stefanak-michal/deepr-php/latest)
![](https://img.shields.io/badge/phpunit-passed-success) ![](https://img.shields.io/badge/coverage-97%25-green) ![](https://img.shields.io/github/stars/stefanak-michal/deepr-php) ![](https://img.shields.io/packagist/dt/stefanak-michal/deepr-php) ![](https://img.shields.io/github/v/release/stefanak-michal/deepr-php) ![](https://img.shields.io/github/commits-since/stefanak-michal/deepr-php/latest)

## Usage

Expand Down
28 changes: 16 additions & 12 deletions src/Deepr.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,21 +254,25 @@ private function recursion(IComponent &$root, string $action, array $values)

if (method_exists($root, $key)) {
$data = $root->{$key}(...$v['()']);
if ($root === $data) {
$root = new Collection();

if (is_null($data)) {
$this->recursion($root, $key, $v);
$collection = new Collection();
$collection->add($root, $k);
$root = $collection;
return;
}
if ($data instanceof Collection && count($data->getChildren())) {
foreach ($data->getChildren() as $child) {

if ($root === $data)
$root = new Collection();
if ($data instanceof Collection) {
foreach ($data->getChildren() as $child)
$this->recursion($child, '', $v);
}
} else {
$this->recursion($data, $key, $v);
}
$root->add($data, $k);
} elseif ($root instanceof Collection && count($root->getChildren()) && method_exists($root->getChildren()[0], $key)) {
foreach ($root->getChildren() as $child) {
$this->recursion($child, $k, $v);
}
if ($data instanceof IComponent)
$root->add($data, $k);
else
throw new Exception('Method has to return instance of IComponent or null', self::ERROR_STRUCTURE);
} elseif (strpos($k, '?') === false) {
throw new Exception('Missing method ' . $key, self::ERROR_MISSING);
}
Expand Down
4 changes: 1 addition & 3 deletions tests/classes/Movie.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,9 @@ public function getActors(): IComponent
* RPC method to get movie by title. Use it with source values call.
* {"<=": {"_type": "Movie"}, "byTitle": {"()": ["The Matrix"]}}
* @param string $title
* @return Movie
* @see \Deepr\tests\classes\Movie
*/
public function byTitle(string $title): Movie
public function byTitle(string $title)
{
$row = Database::getMovieByTitle($title);
if (!empty($row)) {
Expand All @@ -70,7 +69,6 @@ public function byTitle(string $title): Movie
$this->released = $row['released'];
$this->tagline = $row['tagline'];
}
return $this;
}

}

0 comments on commit 9639d3d

Please sign in to comment.