Skip to content

Commit d2f48a9

Browse files
authored
Merge pull request #86 from lode/upgrade-php-features
2 parents fee4bb5 + bf7c572 commit d2f48a9

81 files changed

Lines changed: 1865 additions & 2237 deletions

File tree

Some content is hidden

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

.github/workflows/lint.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
name: lint
22
on:
33
pull_request:
4+
types: [opened, synchronize, reopened, ready_for_review]
45
paths:
56
- "**.php"
67

.github/workflows/test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
name: test
22
on:
33
pull_request:
4+
types: [opened, synchronize, reopened, ready_for_review]
45
paths:
56
- "**.php"
67

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ If you used v1 of this library, see [UPGRADE_1_TO_2.md](/UPGRADE_1_TO_2.md) on h
3232
```php
3333
use alsvanzelf\jsonapi\ResourceDocument;
3434

35-
$document = new ResourceDocument($type='user', $id=42);
35+
$document = new ResourceDocument(type: 'user', id: 42);
3636
$document->add('name', 'Zaphod Beeblebrox');
3737
$document->add('heads', 2);
3838
$document->sendResponse();

examples/collection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
$collection = [];
1717

1818
foreach ($users as $user) {
19-
$resource = ResourceObject::fromObject($user, $type='user', $user->id);
19+
$resource = ResourceObject::fromObject($user, type: 'user', id: $user->id);
2020

2121
if ($user->id == 42) {
2222
$ship = new ResourceObject('ship', 5);

examples/collection_canonical.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
}
5555

5656
$document->setSelfLink('http://example.com/articles');
57-
$document->setPaginationLinks($previous=null, $next='http://example.com/articles?page[offset]=2', $first=null, $last='http://example.com/articles?page[offset]=10');
57+
$document->setPaginationLinks(previousHref: null, nextHref: 'http://example.com/articles?page[offset]=2', firstHref: null, lastHref: 'http://example.com/articles?page[offset]=10');
5858
$document->unsetJsonapiObject();
5959

6060
/**

examples/cursor_pagination_profile.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
$document = CollectionDocument::fromResources($user1, $user2, $user42);
2626
$document->applyProfile($profile);
2727

28-
$profile->setCount($document, $exactTotal=3, $bestGuessTotal=10);
29-
$profile->setLinksFirstPage($document, $currentUrl='/users?sort=42&page[size]=10', $lastCursor='zaphod');
28+
$profile->setCount($document, exactTotal: 3, bestGuessTotal: 10);
29+
$profile->setLinksFirstPage($document, baseOrCurrentUrl: '/users?sort=42&page[size]=10', lastCursor: 'zaphod');
3030

3131
/**
3232
* get the json

examples/errors_all_options.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,37 +11,37 @@
1111
* setting all options
1212
*/
1313

14-
$errorHumanApi = new ErrorObject($genericCode='Invalid input', $genericTitle='Too much options', $specificDetails='Please, choose a bit less. Consult your ...', $specificAboutLink='https://www.example.com/explanation.html', $genericTypeLink='https://www.example.com/documentation.html');
14+
$errorHumanApi = new ErrorObject(genericCode: 'Invalid input', genericTitle: 'Too much options', specificDetails: 'Please, choose a bit less. Consult your ...', specificAboutLink: 'https://www.example.com/explanation.html', genericTypeLink: 'https://www.example.com/documentation.html');
1515

1616
$errorSpecApi = new ErrorObject();
1717

1818
// mark the cause of the error
19-
$errorSpecApi->blameJsonPointer($pointer='/data/attributes/title');
20-
$errorSpecApi->blameQueryParameter($parameter='filter');
21-
$errorSpecApi->blameHeader($headerName='X-Foo');
19+
$errorSpecApi->blameJsonPointer(pointer: '/data/attributes/title');
20+
$errorSpecApi->blameQueryParameter(parameter: 'filter');
21+
$errorSpecApi->blameHeader(headerName: 'X-Foo');
2222

2323
// an identifier useful for helpdesk purposes
24-
$errorSpecApi->setUniqueIdentifier($id=42);
24+
$errorSpecApi->setUniqueIdentifier(id: 42);
2525

2626
// add meta data as you would on a normal json response
27-
$errorSpecApi->addMeta($key='foo', $value='bar');
27+
$errorSpecApi->addMeta(key: 'foo', value: 'bar');
2828

2929
// or as object
3030
$metaObject = new \stdClass();
3131
$metaObject->property = 'value';
32-
$errorSpecApi->addMeta($key='object', $metaObject);
32+
$errorSpecApi->addMeta(key: 'object', value: $metaObject);
3333

3434
// the http status code
3535
// @note it is better to set this on the jsonapi\errors object ..
3636
// .. as only a single one can be consumed by the browser
37-
$errorSpecApi->setHttpStatusCode($httpStatusCode=404);
37+
$errorSpecApi->setHttpStatusCode(httpStatusCode: 404);
3838

3939
// if not set during construction, set them here
40-
$errorSpecApi->setApplicationCode($genericCode='Invalid input');
41-
$errorSpecApi->setHumanTitle($genericTitle='Too much options');
42-
$errorSpecApi->setHumanDetails($specificDetails='Please, choose a bit less. Consult your ...');
43-
$errorSpecApi->setAboutLink($specificAboutLink='https://www.example.com/explanation.html', ['foo'=>'bar']);
44-
$errorSpecApi->setTypeLink($genericTypeLink='https://www.example.com/documentation.html', ['foo'=>'bar']);
40+
$errorSpecApi->setApplicationCode(genericCode: 'Invalid input');
41+
$errorSpecApi->setHumanTitle(genericTitle: 'Too much options');
42+
$errorSpecApi->setHumanDetails(specificDetails: 'Please, choose a bit less. Consult your ...');
43+
$errorSpecApi->setAboutLink(href: 'https://www.example.com/explanation.html', meta: ['foo'=>'bar']);
44+
$errorSpecApi->setTypeLink(href: 'https://www.example.com/documentation.html', meta: ['foo'=>'bar']);
4545

4646
/**
4747
* prepare multiple error objects for the errors response
@@ -68,7 +68,7 @@
6868
$document->addErrorObject($errorSpecApi);
6969
$document->addErrorObject($anotherError);
7070
$document->addException($someException);
71-
$document->add($genericCode='Authentication error', $genericTitle='Not logged in');
71+
$document->add(genericCode: 'Authentication error', genericTitle: 'Not logged in');
7272
$document->addLink('redirect', '/login', ['label'=>'Log in']);
7373

7474
$document->setHttpStatusCode(400);

examples/extension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
* get the json
3131
*/
3232

33-
$contentType = Converter::prepareContentType(ContentTypeEnum::Official, [$extension], []);
33+
$contentType = Converter::prepareContentType(ContentTypeEnum::Official, extensions: [$extension], profiles: []);
3434
echo '<code>Content-Type: '.$contentType.'</code>'.PHP_EOL;
3535

3636
$options = [

examples/output.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
echo '<h2>Get the array</h2>';
1818
echo '<pre style="font-size: large;">$document->toArray();</pre>';
19-
echo '<pre>'.var_export($document->toArray(), true).'</pre>';
19+
echo '<pre>'.var_export($document->toArray(), return: true).'</pre>';
2020

2121
/**
2222
* get the json
@@ -25,16 +25,16 @@
2525
$options = ['prettyPrint' => true];
2626
echo '<h2>Get the json</h2>';
2727
echo '<pre style="font-size: large;">$document->toJson();</pre>';
28-
echo '<pre>'.var_export($document->toJson($options), true).'</pre>';
28+
echo '<pre>'.var_export($document->toJson($options), return: true).'</pre>';
2929

3030
/**
3131
* use own json_encode
3232
*/
3333

3434
$options = ['prettyPrint' => true];
3535
echo '<h2>Use own <code>json_encode()</code></h2>';
36-
echo '<pre style="font-size: large;">json_encode($document, JSON_PRETTY_PRINT);</pre>';
37-
echo '<pre>'.var_export(json_encode($document, JSON_PRETTY_PRINT), true).'</pre>';
36+
echo '<pre style="font-size: large;">json_encode($document, flags: JSON_PRETTY_PRINT);</pre>';
37+
echo '<pre>'.var_export(json_encode($document, flags: JSON_PRETTY_PRINT), return: true).'</pre>';
3838

3939
/**
4040
* get custom json (for a non-spec array)
@@ -51,7 +51,7 @@
5151
echo '$options = [\'array\' => $customArray];'.PHP_EOL;
5252
echo '$document->toJson($options);'.PHP_EOL;
5353
echo '</pre>';
54-
echo '<pre>'.var_export($document->toJson($options), true).'</pre>';
54+
echo '<pre>'.var_export($document->toJson($options), return: true).'</pre>';
5555

5656
/**
5757
* get jsonp with callback
@@ -63,7 +63,7 @@
6363
echo '$options = [\'jsonpCallback\' => \'callback\'];'.PHP_EOL;
6464
echo '$document->toJson($options);'.PHP_EOL;
6565
echo '</pre>';
66-
echo '<pre>'.var_export($document->toJson($options), true).'</pre>';
66+
echo '<pre>'.var_export($document->toJson($options), return: true).'</pre>';
6767

6868
/**
6969
* send json response

examples/profile.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
* get the json
3333
*/
3434

35-
$contentType = Converter::prepareContentType(ContentTypeEnum::Official, [], [$profile]);
35+
$contentType = Converter::prepareContentType(ContentTypeEnum::Official, extensions: [], profiles: [$profile]);
3636
echo '<code>Content-Type: '.$contentType.'</code>'.PHP_EOL;
3737

3838
$options = [

0 commit comments

Comments
 (0)