Skip to content

Commit b8f25df

Browse files
authored
Merge a7d1b48 into 5270798
2 parents 5270798 + a7d1b48 commit b8f25df

16 files changed

+208
-279
lines changed

CHANGELOG.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,23 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
66

77
## [Unreleased]
88

9-
* Nothing
9+
This release includes changes to some interfaces. This is a breaking change if you use these interfaces in your own code.
10+
11+
### Added
12+
13+
* Added `OneRelationInterface` and `ManyRelationInterface` to differentiate between singular and plural relations.
14+
15+
### Changed
16+
17+
* Moved `setType` and `getType` from `RelationInterface` to a separate interface; `TypedRelationInterface`.
18+
* Added type hints to `ItemInterface::setRelation`.
19+
* Added return type hints to `hasAttribute`, `hasOne`, `hasMany`, `morphTo` and `morphToMany` methods of `Item`.
20+
21+
### Removed
22+
23+
* Removed `RelationInterface` in favor of `OneRelationInterface` and `ManyRelationInterface`.
24+
* Removed `setId` and `getId` from `HasOneRelation` and `MorphToRelation`. These operations should be performed on the included item.
25+
* Removed `setType` and `getType` from morph relations. Use regular relations if you want to set the type.
1026

1127
## [0.13.0] - 2019-01-14
1228

src/Interfaces/ItemInterface.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,18 +78,16 @@ public function getAvailableRelations(): array;
7878
/**
7979
* Set the specific relationship in the model.
8080
*
81-
* @param string $relation
82-
* @param mixed $value
81+
* @param string $relation
82+
* @param DataInterface $value
8383
*
8484
* @return static
8585
*/
86-
public function setRelation($relation, $value);
86+
public function setRelation(string $relation, DataInterface $value);
8787

8888
/**
8989
* @TODO: MEGA TODO. Set up a serializer for the Item so that we can remove this, getRelationships etc
9090
*
91-
* @throws \Exception
92-
*
9391
* @return \Swis\JsonApi\Client\Collection
9492
*/
9593
public function getIncluded();
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
namespace Swis\JsonApi\Client\Interfaces;
4+
5+
use Swis\JsonApi\Client\Collection;
6+
7+
interface ManyRelationInterface
8+
{
9+
/**
10+
* @param \Swis\JsonApi\Client\Collection $included
11+
*
12+
* @return static
13+
*/
14+
public function associate(Collection $included);
15+
16+
/**
17+
* @return static
18+
*/
19+
public function dissociate();
20+
21+
/**
22+
* @return bool
23+
*/
24+
public function hasIncluded(): bool;
25+
26+
/**
27+
* @return \Swis\JsonApi\Client\Collection
28+
*/
29+
public function getIncluded(): Collection;
30+
31+
/**
32+
* @param bool $omitIncluded
33+
*
34+
* @return static
35+
*/
36+
public function setOmitIncluded(bool $omitIncluded);
37+
38+
/**
39+
* @return bool
40+
*/
41+
public function shouldOmitIncluded(): bool;
42+
}

src/Interfaces/RelationInterface.php renamed to src/Interfaces/OneRelationInterface.php

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

33
namespace Swis\JsonApi\Client\Interfaces;
44

5-
interface RelationInterface
5+
interface OneRelationInterface
66
{
77
/**
8-
* @return string
9-
*/
10-
public function getType(): string;
11-
12-
/**
13-
* @param string $type
14-
*
15-
* @return static
16-
*/
17-
public function setType(string $type);
18-
19-
/**
20-
* @param \Swis\JsonApi\Client\Interfaces\DataInterface $included
8+
* @param \Swis\JsonApi\Client\Interfaces\ItemInterface $included
219
*
2210
* @return static
2311
*/
24-
public function associate(DataInterface $included);
12+
public function associate(ItemInterface $included);
2513

2614
/**
2715
* @return static
2816
*/
2917
public function dissociate();
3018

31-
/**
32-
* @return \Swis\JsonApi\Client\Collection|\Swis\JsonApi\Client\Interfaces\DataInterface|\Swis\JsonApi\Client\Interfaces\ItemInterface|null
33-
*/
34-
public function getIncluded();
35-
3619
/**
3720
* @return bool
3821
*/
3922
public function hasIncluded(): bool;
4023

4124
/**
42-
* @return bool
25+
* @return \Swis\JsonApi\Client\Interfaces\ItemInterface|null
4326
*/
44-
public function shouldOmitIncluded(): bool;
27+
public function getIncluded();
4528

4629
/**
4730
* @param bool $omitIncluded
4831
*
4932
* @return static
5033
*/
5134
public function setOmitIncluded(bool $omitIncluded);
35+
36+
/**
37+
* @return bool
38+
*/
39+
public function shouldOmitIncluded(): bool;
5240
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace Swis\JsonApi\Client\Interfaces;
4+
5+
interface TypedRelationInterface
6+
{
7+
/**
8+
* @return string
9+
*/
10+
public function getType(): string;
11+
12+
/**
13+
* @param string $type
14+
*
15+
* @return static
16+
*/
17+
public function setType(string $type);
18+
}

0 commit comments

Comments
 (0)