Skip to content

Commit fee4bb5

Browse files
authored
Merge pull request #85 from lode/strict-typing
2 parents e8fbc1e + 8232126 commit fee4bb5

File tree

139 files changed

+1291
-1301
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

139 files changed

+1291
-1301
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,11 @@ use alsvanzelf\jsonapi\ResourceDocument;
175175
use alsvanzelf\jsonapi\interfaces\ExtensionInterface;
176176

177177
class ExampleExtension implements ExtensionInterface {
178-
public function getOfficialLink() {
178+
public function getOfficialLink(): string {
179179
return 'https://example.org/extension-documentation';
180180
}
181181

182-
public function getNamespace() {
182+
public function getNamespace(): string {
183183
return 'foo';
184184
}
185185
}

UPGRADE_2_TO_3.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Upgrade from library v2 to v3
2+
3+
## Checking links, ...
4+
5+
Objects more often use uninitialized properties. `has*()` helper methods have been added to support the new flow.
6+
7+
- `$object->links` to `if ($object->hasLinks()) $object->links`
8+
9+
## Interfaces
10+
11+
When extending interfaces, you'll have to add method argument types and return types.
12+
13+
Check [all interfaces](/src/interfaces) for the correct typing.
14+
15+
## Enums
16+
17+
Content types:
18+
- `Document::CONTENT_TYPE_OFFICIAL` to `ContentTypeEnum::Official`
19+
- `Document::CONTENT_TYPE_DEBUG` to `ContentTypeEnum::Debug`
20+
- `Document::CONTENT_TYPE_JSONP` to `ContentTypeEnum::Jsonp`
21+
22+
Jsonapi versions:
23+
- `Document::JSONAPI_VERSION_1_0` to `JsonapiVersionEnum::V_1_0`
24+
- `Document::JSONAPI_VERSION_1_1` to `JsonapiVersionEnum::V_1_1`
25+
- `Document::JSONAPI_VERSION_LATEST` to `JsonapiVersionEnum::Latest`
26+
27+
Document levels:
28+
- `Document::LEVEL_ROOT` to `DocumentLevelEnum::Root`
29+
- `Document::LEVEL_JSONAPI` to `DocumentLevelEnum::Jsonapi`
30+
- `Document::LEVEL_Resource` to `DocumentLevelEnum::Resource`
31+
32+
Sorting orders:
33+
- `RequestParser->getSortFields()` returns a `SortOrderEnum` instead of `string` for the `order` field
34+
35+
Relationship types:
36+
- `RelationshipObject::TO_ONE` to `RelationshipTypeEnum::ToOne`
37+
- `RelationshipObject::TO_MANY` to `RelationshipTypeEnum::ToMany`
38+
39+
## Internal
40+
41+
Enums:
42+
- `RequestParser::SORT_*` to `SortOrderEnum::*`
43+
- `Validator::OBJECT_CONTAINER_*` to `ObjectContainerEnum::*`

examples/atomic_operations_extension.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
use alsvanzelf\jsonapi\objects\ResourceObject;
46
use alsvanzelf\jsonapi\extensions\AtomicOperationsDocument;
57

examples/bootstrap_examples.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
use alsvanzelf\jsonapi\Document;
46
use alsvanzelf\jsonapi\ResourceDocument;
57
use alsvanzelf\jsonapi\interfaces\ExtensionInterface;
@@ -110,11 +112,11 @@ class ExampleVersionExtension implements ExtensionInterface {
110112
* the required method
111113
*/
112114

113-
public function getOfficialLink() {
115+
public function getOfficialLink(): string {
114116
return 'https://jsonapi.org/format/1.1/#extension-rules';
115117
}
116118

117-
public function getNamespace() {
119+
public function getNamespace(): string {
118120
return 'version';
119121
}
120122

@@ -141,7 +143,7 @@ class ExampleTimestampsProfile implements ProfileInterface {
141143
* the required method
142144
*/
143145

144-
public function getOfficialLink() {
146+
public function getOfficialLink(): string {
145147
return 'https://jsonapi.org/recommendations/#authoring-profiles';
146148
}
147149

examples/collection.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
use alsvanzelf\jsonapi\CollectionDocument;
46
use alsvanzelf\jsonapi\objects\ResourceObject;
57

examples/collection_canonical.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
use alsvanzelf\jsonapi\CollectionDocument;
46
use alsvanzelf\jsonapi\objects\ResourceObject;
57

examples/cursor_pagination_profile.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
use alsvanzelf\jsonapi\CollectionDocument;
46
use alsvanzelf\jsonapi\objects\ResourceObject;
57
use alsvanzelf\jsonapi\profiles\CursorPaginationProfile;

examples/errors_all_options.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
use alsvanzelf\jsonapi\ErrorsDocument;
46
use alsvanzelf\jsonapi\objects\ErrorObject;
57

examples/errors_exception_native.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
use alsvanzelf\jsonapi\ErrorsDocument;
46

57
require 'bootstrap_examples.php';

examples/extension.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
<?php
22

3-
use alsvanzelf\jsonapi\Document;
3+
declare(strict_types=1);
4+
45
use alsvanzelf\jsonapi\ResourceDocument;
6+
use alsvanzelf\jsonapi\enums\ContentTypeEnum;
57
use alsvanzelf\jsonapi\helpers\Converter;
68

79
require 'bootstrap_examples.php';
@@ -28,7 +30,7 @@
2830
* get the json
2931
*/
3032

31-
$contentType = Converter::prepareContentType(Document::CONTENT_TYPE_OFFICIAL, [$extension], []);
33+
$contentType = Converter::prepareContentType(ContentTypeEnum::Official, [$extension], []);
3234
echo '<code>Content-Type: '.$contentType.'</code>'.PHP_EOL;
3335

3436
$options = [

0 commit comments

Comments
 (0)