-
Notifications
You must be signed in to change notification settings - Fork 27
Add support for generics #108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,10 +36,6 @@ | |
}, | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Hendrik Nijmeijer", | ||
"email": "[email protected]" | ||
}, | ||
{ | ||
"name": "Jasper Zonneveld", | ||
"email": "[email protected]", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,21 +7,38 @@ | |
use Swis\JsonApi\Client\Links; | ||
use Swis\JsonApi\Client\Meta; | ||
|
||
/** | ||
* @template TItem of \Swis\JsonApi\Client\Interfaces\ItemInterface | ||
*/ | ||
interface OneRelationInterface | ||
{ | ||
/** | ||
* @param TItem|null $data | ||
* @return static | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same static comment. |
||
*/ | ||
public function setData(?ItemInterface $data); | ||
|
||
/** | ||
* @return TItem|null | ||
*/ | ||
public function getData(): ?ItemInterface; | ||
|
||
public function hasData(): bool; | ||
|
||
/** | ||
* @param TItem|null $included | ||
*/ | ||
public function setIncluded(?ItemInterface $included); | ||
|
||
/** | ||
* @return TItem|null | ||
*/ | ||
public function getIncluded(): ?ItemInterface; | ||
|
||
public function hasIncluded(): bool; | ||
|
||
/** | ||
* @param TItem $included | ||
* @return static | ||
*/ | ||
public function associate(ItemInterface $included); | ||
|
@@ -31,6 +48,9 @@ public function associate(ItemInterface $included); | |
*/ | ||
public function dissociate(); | ||
|
||
/** | ||
* @return TItem|null | ||
*/ | ||
public function getAssociated(): ?ItemInterface; | ||
|
||
public function hasAssociated(): bool; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,20 +4,23 @@ | |
|
||
namespace Swis\JsonApi\Client\Interfaces; | ||
|
||
/** | ||
* @template TItem of \Swis\JsonApi\Client\Interfaces\ItemInterface | ||
*/ | ||
interface RepositoryInterface | ||
{ | ||
/** | ||
* @return \Swis\JsonApi\Client\Interfaces\CollectionDocumentInterface | ||
* @return \Swis\JsonApi\Client\Interfaces\CollectionDocumentInterface<TItem> | ||
*/ | ||
public function all(); | ||
|
||
/** | ||
* @return \Swis\JsonApi\Client\Interfaces\ItemDocumentInterface | ||
* @return \Swis\JsonApi\Client\Interfaces\ItemDocumentInterface<TItem> | ||
*/ | ||
public function find(string $id); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When i check the tests, i think this return type is not correct. It seems this can also return a DocumentInterface. See This could also mean the interface on the Document is wrong. seems a little weird, since ItemDocument is pretty much the same class with the extra getData method. Think there is something wrong here. @JaZo any insights? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I had the same questions, but I didnt want to touch actual code in this PR… ItemDocument seems to follow the spec though… There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would probably make it documentinterface, since itemdocumentinterface does extend documentinterface. But that will mean some errors later with phpstan when we are calling getData. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would also make this PR mostly obsolete if find() would not resolve to an Item 😋 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The primary reason to have a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I’m fine with that |
||
|
||
/** | ||
* @return \Swis\JsonApi\Client\Interfaces\ItemDocumentInterface | ||
* @return \Swis\JsonApi\Client\Interfaces\ItemDocumentInterface<TItem> | ||
*/ | ||
public function save(ItemInterface $item); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Return static also points at a little weirdness, why isn't that type hinted? And should it be?