Skip to content

Commit

Permalink
Merge pull request #19 from swisnl/fix-code-smell
Browse files Browse the repository at this point in the history
Fix code smell/style
  • Loading branch information
JaZo authored Jun 1, 2018
2 parents 2a9ed58 + f81018d commit e97f858
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 19 deletions.
10 changes: 5 additions & 5 deletions src/ItemHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
class ItemHydrator
{
/**
* @var \Swis\JsonApi\Client\TypeMapper
* @var \Swis\JsonApi\Client\Interfaces\TypeMapperInterface
*/
private $typeMapper;
protected $typeMapper;

/**
* @param \Swis\JsonApi\Client\Interfaces\TypeMapperInterface $typeMapper
Expand Down Expand Up @@ -44,9 +44,9 @@ public function hydrate(ItemInterface $item, array $attributes): ItemInterface

/**
* @param \Swis\JsonApi\Client\Interfaces\ItemInterface $item
* @param array|null $attributes
* @param array $attributes
*/
protected function fill(ItemInterface $item, array $attributes = null)
protected function fill(ItemInterface $item, array $attributes)
{
$item->fill(array_diff_key($attributes, array_combine($item->getAvailableRelations(), $item->getAvailableRelations())));
}
Expand All @@ -59,7 +59,7 @@ protected function fill(ItemInterface $item, array $attributes = null)
*
* @throws \Exception
*/
protected function fillRelations(ItemInterface $item, array $attributes = null)
protected function fillRelations(ItemInterface $item, array $attributes)
{
// Fill Relations
foreach ($item->getAvailableRelations() as $availableRelation) {
Expand Down
23 changes: 11 additions & 12 deletions src/JsonApi/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ public function deserialize(string $json): DocumentInterface
*/
private function getJsonApiDocument(string $json): Art4JsonApiDocumentInterface
{
/** @var \Art4\JsonApiClient\DocumentInterface $jsonApiDocument */
$jsonApiDocument = $this->manager->parse($json);

if (!$jsonApiDocument instanceof Art4JsonApiDocumentInterface) {
Expand All @@ -109,20 +108,20 @@ protected function buildDataDocument(Art4JsonApiDocumentInterface $jsonApiDocume
$allHydratedItems = new Collection();
$allJsonApiItems = new Collection();

if ($data instanceof ResourceCollectionInterface) {
$collection = $this->hydrator->hydrateCollection($jsonApiDocument->get('data'));
$allHydratedItems = $allHydratedItems->concat($collection);
$allJsonApiItems = $allJsonApiItems->concat($jsonApiDocument->get('data')->asArray());

$document = new CollectionDocument();
$document->setData($collection);
} elseif ($data instanceof ResourceItemInterface) {
$item = $this->hydrator->hydrateItem($jsonApiDocument->get('data'));
if ($data instanceof ResourceItemInterface) {
$item = $this->hydrator->hydrateItem($data);
$allHydratedItems->push($item);
$allJsonApiItems->push($jsonApiDocument->get('data'));
$allJsonApiItems->push($data);

$document = new ItemDocument();
$document->setData($item);
} elseif ($data instanceof ResourceCollectionInterface) {
$collection = $this->hydrator->hydrateCollection($data);
$allHydratedItems = $allHydratedItems->concat($collection);
$allJsonApiItems = $allJsonApiItems->concat(new Collection($data->asArray()));

$document = new CollectionDocument();
$document->setData($collection);
} else {
throw new \DomainException('Data is not Collection or Item');
}
Expand All @@ -131,7 +130,7 @@ protected function buildDataDocument(Art4JsonApiDocumentInterface $jsonApiDocume
if ($includedInDocument) {
$included = $this->hydrator->hydrateCollection($includedInDocument);
$allHydratedItems = $allHydratedItems->concat($included);
$allJsonApiItems = $allJsonApiItems->concat($includedInDocument->asArray());
$allJsonApiItems = $allJsonApiItems->concat(new Collection($includedInDocument->asArray()));
}

$this->hydrator->hydrateRelationships($allJsonApiItems, $allHydratedItems);
Expand Down
4 changes: 2 additions & 2 deletions src/Providers/TypeMapperServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace Swis\JsonApi\Client\Providers;

use Illuminate\Support\ServiceProvider;
use Illuminate\Support\ServiceProvider as BaseServiceProvider;
use Swis\JsonApi\Client\Interfaces\TypeMapperInterface;

class TypeMapperServiceProvider extends ServiceProvider
class TypeMapperServiceProvider extends BaseServiceProvider
{
/**
* A list of class names implementing \Swis\JsonApi\Client\Interfaces\ItemInterface.
Expand Down

0 comments on commit e97f858

Please sign in to comment.