Skip to content

Commit e97f858

Browse files
authored
Merge pull request #19 from swisnl/fix-code-smell
Fix code smell/style
2 parents 2a9ed58 + f81018d commit e97f858

File tree

3 files changed

+18
-19
lines changed

3 files changed

+18
-19
lines changed

src/ItemHydrator.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
class ItemHydrator
1515
{
1616
/**
17-
* @var \Swis\JsonApi\Client\TypeMapper
17+
* @var \Swis\JsonApi\Client\Interfaces\TypeMapperInterface
1818
*/
19-
private $typeMapper;
19+
protected $typeMapper;
2020

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

4545
/**
4646
* @param \Swis\JsonApi\Client\Interfaces\ItemInterface $item
47-
* @param array|null $attributes
47+
* @param array $attributes
4848
*/
49-
protected function fill(ItemInterface $item, array $attributes = null)
49+
protected function fill(ItemInterface $item, array $attributes)
5050
{
5151
$item->fill(array_diff_key($attributes, array_combine($item->getAvailableRelations(), $item->getAvailableRelations())));
5252
}
@@ -59,7 +59,7 @@ protected function fill(ItemInterface $item, array $attributes = null)
5959
*
6060
* @throws \Exception
6161
*/
62-
protected function fillRelations(ItemInterface $item, array $attributes = null)
62+
protected function fillRelations(ItemInterface $item, array $attributes)
6363
{
6464
// Fill Relations
6565
foreach ($item->getAvailableRelations() as $availableRelation) {

src/JsonApi/Parser.php

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ public function deserialize(string $json): DocumentInterface
8484
*/
8585
private function getJsonApiDocument(string $json): Art4JsonApiDocumentInterface
8686
{
87-
/** @var \Art4\JsonApiClient\DocumentInterface $jsonApiDocument */
8887
$jsonApiDocument = $this->manager->parse($json);
8988

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

112-
if ($data instanceof ResourceCollectionInterface) {
113-
$collection = $this->hydrator->hydrateCollection($jsonApiDocument->get('data'));
114-
$allHydratedItems = $allHydratedItems->concat($collection);
115-
$allJsonApiItems = $allJsonApiItems->concat($jsonApiDocument->get('data')->asArray());
116-
117-
$document = new CollectionDocument();
118-
$document->setData($collection);
119-
} elseif ($data instanceof ResourceItemInterface) {
120-
$item = $this->hydrator->hydrateItem($jsonApiDocument->get('data'));
111+
if ($data instanceof ResourceItemInterface) {
112+
$item = $this->hydrator->hydrateItem($data);
121113
$allHydratedItems->push($item);
122-
$allJsonApiItems->push($jsonApiDocument->get('data'));
114+
$allJsonApiItems->push($data);
123115

124116
$document = new ItemDocument();
125117
$document->setData($item);
118+
} elseif ($data instanceof ResourceCollectionInterface) {
119+
$collection = $this->hydrator->hydrateCollection($data);
120+
$allHydratedItems = $allHydratedItems->concat($collection);
121+
$allJsonApiItems = $allJsonApiItems->concat(new Collection($data->asArray()));
122+
123+
$document = new CollectionDocument();
124+
$document->setData($collection);
126125
} else {
127126
throw new \DomainException('Data is not Collection or Item');
128127
}
@@ -131,7 +130,7 @@ protected function buildDataDocument(Art4JsonApiDocumentInterface $jsonApiDocume
131130
if ($includedInDocument) {
132131
$included = $this->hydrator->hydrateCollection($includedInDocument);
133132
$allHydratedItems = $allHydratedItems->concat($included);
134-
$allJsonApiItems = $allJsonApiItems->concat($includedInDocument->asArray());
133+
$allJsonApiItems = $allJsonApiItems->concat(new Collection($includedInDocument->asArray()));
135134
}
136135

137136
$this->hydrator->hydrateRelationships($allJsonApiItems, $allHydratedItems);

src/Providers/TypeMapperServiceProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
namespace Swis\JsonApi\Client\Providers;
44

5-
use Illuminate\Support\ServiceProvider;
5+
use Illuminate\Support\ServiceProvider as BaseServiceProvider;
66
use Swis\JsonApi\Client\Interfaces\TypeMapperInterface;
77

8-
class TypeMapperServiceProvider extends ServiceProvider
8+
class TypeMapperServiceProvider extends BaseServiceProvider
99
{
1010
/**
1111
* A list of class names implementing \Swis\JsonApi\Client\Interfaces\ItemInterface.

0 commit comments

Comments
 (0)