Skip to content

Commit 2ba023c

Browse files
authored
Merge pull request #89 from Art4/83-check-compatability-with-json-api-11
Check compatability with JSON:API 1.1
2 parents 593b78e + 83bddb0 commit 2ba023c

35 files changed

+9634
-75
lines changed

README.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ Format: [JSON API 1.0](http://jsonapi.org/format/1.0/)
1212

1313
## :checkered_flag: Goals
1414

15-
* :heavy_check_mark: Be 100% JSON API spec conform
16-
* :heavy_check_mark: Be open for new spec versions
17-
* :heavy_check_mark: Handle/validate a server response body
18-
* :heavy_check_mark: Handle/validate a client request body
19-
* :heavy_check_mark: Offer an easy way to retrieve the data
20-
* :heavy_check_mark: Allow extendability and injection of classes/models
15+
* Be 100% JSON API 1.0 spec conform
16+
* Be open for new spec minor versions (see [#90](https://github.com/Art4/json-api-client/issues/90))
17+
* Handle/validate a server response body
18+
* Handle/validate a client request body
19+
* Offer an easy way to retrieve the data
20+
* Allow extendability and injection of classes/models
2121

2222
## :package: Install
2323

@@ -170,7 +170,7 @@ composer run reuse-annotate
170170

171171
## :heart: Credits
172172

173-
- [Artur Weigandt](https://github.com/Art4) [![Twitter](http://img.shields.io/badge/[email protected])](https://twitter.com/weigandtlabs)
173+
- [Artur Weigandt](https://github.com/Art4)
174174
- [All Contributors](../../contributors)
175175

176176
## :page_facing_up: License

src/Helper/AccessableTrait.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ final public function getKeys(): array
5555
*/
5656
final public function has($key): bool
5757
{
58-
if (! is_int($key) && ! is_string($key) && (! is_object($key) || ! $key instanceof AccessKey)) {
58+
if (!is_int($key) && !is_string($key) && (!is_object($key) || !$key instanceof AccessKey)) {
5959
trigger_error(sprintf(
6060
'%s::has(): Providing Argument #1 ($key) as `%s` is deprecated since 1.2.0, please provide as `int|string` instead.',
6161
get_class($this),
@@ -74,14 +74,14 @@ final public function has($key): bool
7474
return array_key_exists($string, $this->data);
7575
}
7676

77-
if (! array_key_exists($string, $this->data)) {
77+
if (!array_key_exists($string, $this->data)) {
7878
return false;
7979
}
8080

8181
$value = $this->getValue($string);
8282

8383
// #TODO Handle other objects and arrays
84-
if (! $value instanceof Accessable) {
84+
if (!$value instanceof Accessable) {
8585
// throw new AccessException('The existance for the key "' . $key->raw . '" could\'nt be checked.');
8686
return false;
8787
}
@@ -98,7 +98,7 @@ final public function has($key): bool
9898
*/
9999
public function get($key)
100100
{
101-
if (! is_int($key) && ! is_string($key) && (! is_object($key) || ! $key instanceof AccessKey)) {
101+
if (!is_int($key) && !is_string($key) && (!is_object($key) || !$key instanceof AccessKey)) {
102102
trigger_error(sprintf(
103103
'%s::get(): Providing Argument #1 ($key) as `%s` is deprecated since 1.2.0, please provide as `int|string` instead.',
104104
get_class($this),
@@ -120,7 +120,7 @@ public function get($key)
120120
}
121121

122122
// #TODO Handle other objects and arrays
123-
if (! $value instanceof Accessable) {
123+
if (!$value instanceof Accessable) {
124124
throw new AccessException('Could not get the value for the key "' . $key->raw . '".');
125125
}
126126

src/Input/RequestStringInput.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function getAsObject(): \stdClass
4343
{
4444
$data = $this->decodeJson($this->rawString);
4545

46-
if (! $data instanceof \stdClass) {
46+
if (!$data instanceof \stdClass) {
4747
throw new InputException('JSON must contain an object (e.g. `{}`).');
4848
}
4949

src/Input/ResponseStringInput.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function getAsObject(): \stdClass
4343
{
4444
$data = $this->decodeJson($this->rawString);
4545

46-
if (! $data instanceof \stdClass) {
46+
if (!$data instanceof \stdClass) {
4747
throw new InputException('JSON must contain an object (e.g. `{}`).');
4848
}
4949

src/Input/StringInputTrait.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ trait StringInputTrait
2727
*/
2828
final public function prepareString($string): string
2929
{
30-
if (! is_string($string)) {
30+
if (!is_string($string)) {
3131
throw new InputException(sprintf(
3232
'$string must be a string, "%s" given.',
3333
gettype($string)

src/Serializer/ArraySerializer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function serialize(Accessable $data): ?array
6969
*/
7070
private function objectTransform($val)
7171
{
72-
if (! is_object($val)) {
72+
if (!is_object($val)) {
7373
return $val;
7474
} elseif ($val instanceof Accessable) {
7575
return $this->serialize($val);

src/V1/Attributes.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ final class Attributes extends AbstractElement
2929
*/
3030
protected function parse($object): void
3131
{
32-
if (! is_object($object)) {
32+
if (!is_object($object)) {
3333
throw new ValidationException('Attributes has to be an object, "' . gettype($object) . '" given.');
3434
}
3535

src/V1/Document.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ final class Document extends AbstractElement
3030
*/
3131
protected function parse($object): void
3232
{
33-
if (! is_object($object)) {
33+
if (!is_object($object)) {
3434
throw new ValidationException('Document has to be an object, "' . gettype($object) . '" given.');
3535
}
3636

37-
if (! property_exists($object, 'data') and ! property_exists($object, 'meta') and ! property_exists($object, 'errors')) {
37+
if (!property_exists($object, 'data') and !property_exists($object, 'meta') and !property_exists($object, 'errors')) {
3838
throw new ValidationException('Document MUST contain at least one of the following properties: data, errors, meta');
3939
}
4040

@@ -55,7 +55,7 @@ protected function parse($object): void
5555
}
5656

5757
if (property_exists($object, 'included')) {
58-
if (! property_exists($object, 'data')) {
58+
if (!property_exists($object, 'data')) {
5959
throw new ValidationException('If Document does not contain a `data` property, the `included` property MUST NOT be present either.');
6060
}
6161

@@ -104,7 +104,7 @@ private function parseData($data): Accessable
104104
return $this->create('ResourceCollection', $data);
105105
}
106106

107-
if (! is_object($data)) {
107+
if (!is_object($data)) {
108108
throw new ValidationException('Data value has to be null or an object, "' . gettype($data) . '" given.');
109109
}
110110

src/V1/DocumentLink.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ final class DocumentLink extends AbstractElement
3434
*/
3535
protected function parse($object): void
3636
{
37-
if (! is_object($object)) {
37+
if (!is_object($object)) {
3838
throw new ValidationException(
3939
'DocumentLink has to be an object, "' . gettype($object) . '" given.'
4040
);
@@ -43,7 +43,7 @@ protected function parse($object): void
4343
$links = get_object_vars($object);
4444

4545
if (array_key_exists('self', $links)) {
46-
if (! is_string($links['self']) and ! is_object($links['self'])) {
46+
if (!is_string($links['self']) and !is_object($links['self'])) {
4747
throw new ValidationException(
4848
'property "self" has to be a string or object, "' .
4949
gettype($links['self']) . '" given.'
@@ -56,7 +56,7 @@ protected function parse($object): void
5656
}
5757

5858
if (array_key_exists('related', $links)) {
59-
if (! is_string($links['related']) and ! is_object($links['related'])) {
59+
if (!is_string($links['related']) and !is_object($links['related'])) {
6060
throw new ValidationException(
6161
'property "related" has to be a string or object, "' .
6262
gettype($links['related']) . '" given.'
@@ -125,7 +125,7 @@ public function get($key)
125125
*/
126126
private function setPaginationLink(string $name, $value): void
127127
{
128-
if (! is_object($value) and ! is_string($value) and ! is_null($value)) {
128+
if (!is_object($value) and !is_string($value) and !is_null($value)) {
129129
throw new ValidationException(
130130
'property "' . $name . '" has to be an object, a string or null, "' .
131131
gettype($value) . '" given.'
@@ -147,7 +147,7 @@ private function setPaginationLink(string $name, $value): void
147147
*/
148148
private function setLink(string $name, $link): void
149149
{
150-
if (! is_string($link) and ! is_object($link)) {
150+
if (!is_string($link) and !is_object($link)) {
151151
throw new ValidationException(
152152
'Link attribute has to be an object or string, "' .
153153
gettype($link) . '" given.'

src/V1/Error.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ final class Error extends AbstractElement
2929
*/
3030
protected function parse($object): void
3131
{
32-
if (! is_object($object)) {
32+
if (!is_object($object)) {
3333
throw new ValidationException(
3434
'Error has to be an object, "' . gettype($object) . '" given.'
3535
);
3636
}
3737

3838
if (property_exists($object, 'id')) {
39-
if (! is_string($object->id)) {
39+
if (!is_string($object->id)) {
4040
throw new ValidationException(
4141
'property "id" has to be a string, "' .
4242
gettype($object->id) . '" given.'
@@ -51,7 +51,7 @@ protected function parse($object): void
5151
}
5252

5353
if (property_exists($object, 'status')) {
54-
if (! is_string($object->status)) {
54+
if (!is_string($object->status)) {
5555
throw new ValidationException(
5656
'property "status" has to be a string, "' .
5757
gettype($object->status) . '" given.'
@@ -62,7 +62,7 @@ protected function parse($object): void
6262
}
6363

6464
if (property_exists($object, 'code')) {
65-
if (! is_string($object->code)) {
65+
if (!is_string($object->code)) {
6666
throw new ValidationException(
6767
'property "code" has to be a string, "' .
6868
gettype($object->code) . '" given.'
@@ -73,7 +73,7 @@ protected function parse($object): void
7373
}
7474

7575
if (property_exists($object, 'title')) {
76-
if (! is_string($object->title)) {
76+
if (!is_string($object->title)) {
7777
throw new ValidationException(
7878
'property "title" has to be a string, "' .
7979
gettype($object->title) . '" given.'
@@ -84,7 +84,7 @@ protected function parse($object): void
8484
}
8585

8686
if (property_exists($object, 'detail')) {
87-
if (! is_string($object->detail)) {
87+
if (!is_string($object->detail)) {
8888
throw new ValidationException(
8989
'property "detail" has to be a string, "' .
9090
gettype($object->detail) . '" given.'

src/V1/ErrorCollection.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ final class ErrorCollection extends AbstractElement
2929
*/
3030
protected function parse($object): void
3131
{
32-
if (! is_array($object)) {
32+
if (!is_array($object)) {
3333
throw new ValidationException('Errors for a collection has to be in an array, "' . gettype($object) . '" given.');
3434
}
3535

src/V1/ErrorLink.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,17 @@ final class ErrorLink extends AbstractElement
3333
*/
3434
protected function parse($object): void
3535
{
36-
if (! is_object($object)) {
36+
if (!is_object($object)) {
3737
throw new ValidationException('Link has to be an object, "' . gettype($object) . '" given.');
3838
}
3939

4040
$links = get_object_vars($object);
4141

42-
if (! array_key_exists('about', $links)) {
42+
if (!array_key_exists('about', $links)) {
4343
throw new ValidationException('ErrorLink MUST contain these properties: about');
4444
}
4545

46-
if (! is_string($links['about']) and ! is_object($links['about'])) {
46+
if (!is_string($links['about']) and !is_object($links['about'])) {
4747
throw new ValidationException('Link has to be an object or string, "' . gettype($links['about']) . '" given.');
4848
}
4949

@@ -85,7 +85,7 @@ public function get($key)
8585
*/
8686
private function setLink(string $name, $link): void
8787
{
88-
if (! is_string($link) and ! is_object($link)) {
88+
if (!is_string($link) and !is_object($link)) {
8989
throw new ValidationException('Link attribute has to be an object or string, "' . gettype($link) . '" given.');
9090
}
9191

src/V1/ErrorSource.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,20 @@ final class ErrorSource extends AbstractElement
2929
*/
3030
protected function parse($object): void
3131
{
32-
if (! is_object($object)) {
32+
if (!is_object($object)) {
3333
throw new ValidationException('ErrorSource has to be an object, "' . gettype($object) . '" given.');
3434
}
3535

3636
if (property_exists($object, 'pointer')) {
37-
if (! is_string($object->pointer)) {
37+
if (!is_string($object->pointer)) {
3838
throw new ValidationException('property "pointer" has to be a string, "' . gettype($object->pointer) . '" given.');
3939
}
4040

4141
$this->set('pointer', strval($object->pointer));
4242
}
4343

4444
if (property_exists($object, 'parameter')) {
45-
if (! is_string($object->parameter)) {
45+
if (!is_string($object->parameter)) {
4646
throw new ValidationException('property "parameter" has to be a string, "' . gettype($object->parameter) . '" given.');
4747
}
4848

src/V1/Factory.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,15 @@ public function __construct(array $overload = [])
5959
*/
6060
public function make(string $name, array $args = []): Accessable
6161
{
62-
if (! isset($this->classes[$name])) {
62+
if (!isset($this->classes[$name])) {
6363
throw new FactoryException('"' . $name . '" is not a registered class');
6464
}
6565

6666
$class = new \ReflectionClass($this->classes[$name]);
6767

6868
$object = $class->newInstanceArgs($args);
6969

70-
if (! $object instanceof Accessable) {
70+
if (!$object instanceof Accessable) {
7171
throw new FactoryException(sprintf(
7272
'%s must be instance of `%s`',
7373
$this->classes[$name],

src/V1/Jsonapi.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ final class Jsonapi extends AbstractElement
2929
*/
3030
protected function parse($object): void
3131
{
32-
if (! is_object($object)) {
32+
if (!is_object($object)) {
3333
throw new ValidationException('Jsonapi has to be an object, "' . gettype($object) . '" given.');
3434
}
3535

src/V1/Link.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ final class Link extends AbstractElement
2929
*/
3030
protected function parse($object): void
3131
{
32-
if (! is_object($object)) {
32+
if (!is_object($object)) {
3333
throw new ValidationException('Link has to be an object or string, "' . gettype($object) . '" given.');
3434
}
3535

36-
if (! property_exists($object, 'href')) {
36+
if (!property_exists($object, 'href')) {
3737
throw new ValidationException('Link must have a "href" attribute.');
3838
}
3939

@@ -72,7 +72,7 @@ private function setAsLink(string $name, $link): void
7272
}
7373

7474
// every link must be an URL
75-
if (! is_string($link)) {
75+
if (!is_string($link)) {
7676
throw new ValidationException('Every link attribute has to be a string, "' . gettype($link) . '" given.');
7777
}
7878

src/V1/Meta.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ final class Meta extends AbstractElement
2929
*/
3030
protected function parse($object): void
3131
{
32-
if (! is_object($object)) {
32+
if (!is_object($object)) {
3333
throw new ValidationException('Meta has to be an object, "' . gettype($object) . '" given.');
3434
}
3535

src/V1/Relationship.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ final class Relationship extends AbstractElement
2929
*/
3030
protected function parse($object): void
3131
{
32-
if (! is_object($object)) {
32+
if (!is_object($object)) {
3333
throw new ValidationException('Relationship has to be an object, "' . gettype($object) . '" given.');
3434
}
3535

36-
if (! property_exists($object, 'links') and ! property_exists($object, 'data') and ! property_exists($object, 'meta')) {
36+
if (!property_exists($object, 'links') and !property_exists($object, 'data') and !property_exists($object, 'meta')) {
3737
throw new ValidationException('A Relationship object MUST contain at least one of the following properties: links, data, meta');
3838
}
3939

src/V1/RelationshipCollection.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ final class RelationshipCollection extends AbstractElement
2929
*/
3030
protected function parse($object): void
3131
{
32-
if (! is_object($object)) {
32+
if (!is_object($object)) {
3333
throw new ValidationException('Relationships has to be an object, "' . gettype($object) . '" given.');
3434
}
3535

0 commit comments

Comments
 (0)