diff --git a/README.md b/README.md index 0fdd77f..d009172 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/Deepr.php b/src/Deepr.php index 938556b..b735356 100644 --- a/src/Deepr.php +++ b/src/Deepr.php @@ -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); } diff --git a/tests/classes/Movie.php b/tests/classes/Movie.php index 31405b6..bd6aa2c 100644 --- a/tests/classes/Movie.php +++ b/tests/classes/Movie.php @@ -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)) { @@ -70,7 +69,6 @@ public function byTitle(string $title): Movie $this->released = $row['released']; $this->tagline = $row['tagline']; } - return $this; } }