Skip to content

Commit e34075c

Browse files
authored
PHP 8 (#112)
1 parent ba2c50d commit e34075c

Some content is hidden

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

80 files changed

+538
-826
lines changed

Diff for: .gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ composer.phar
33
/vendor/
44
/composer.lock
55
/.php_cs.cache
6+
.php-cs-fixer.cache
7+
.phpunit.result.cache

Diff for: .php-cs-fixer.php

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
$finder = PhpCsFixer\Finder::create()
4+
->exclude('somedir')
5+
->notPath('src/Symfony/Component/Translation/Tests/fixtures/resources.php')
6+
->in(__DIR__);
7+
8+
$config = new PhpCsFixer\Config();
9+
return $config->setRules([
10+
'@PSR12' => true,
11+
'array_syntax' => ['syntax' => 'short'],
12+
'braces' => [
13+
'allow_single_line_closure' => true,
14+
'position_after_functions_and_oop_constructs' => 'same'],
15+
])
16+
->setFinder($finder);

Diff for: .php_cs.dist

-53
This file was deleted.

Diff for: .travis.yml

-14
This file was deleted.

Diff for: CHANGELOG.md

+10-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
66

77
## [Unreleased]
88

9+
## [3.0.0] - 2022-07-26
10+
### Changed
11+
- The package is migrated to PHP 8.1
12+
13+
### Removed
14+
- Support for PHP 7 and older versions
15+
- Compound document validation logic is dropped
16+
917
## [2.2.0] - 2020-10-12
1018
### Added
1119
- `NewResourceObject` to allow omitting `id` in resources to-be-created (#108)
@@ -30,7 +38,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
3038
### Added
3139
- v2 initial release
3240

33-
[Unreleased]: https://github.com/json-api-php/json-api/compare/2.2.0...HEAD
41+
[Unreleased]: https://github.com/json-api-php/json-api/compare/3.0.0...HEAD
42+
[3.0.0]: https://github.com/json-api-php/json-api/compare/2.2.2...3.0.0
3443
[2.2.0]: https://github.com/json-api-php/json-api/compare/2.1.2...2.2.0
3544
[2.1.2]: https://github.com/json-api-php/json-api/compare/2.1.1...2.1.2
3645
[2.1.1]: https://github.com/json-api-php/json-api/compare/2.1.0...2.1.1

Diff for: composer.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "json-api-php/json-api",
3-
"description": "An attempt to express JSON API specs (jsonapi.org) in object-oriented way as a set of PHP 7 classes",
3+
"description": "JSON API specs (jsonapi.org) as a set of PHP classes",
44
"type": "library",
55
"prefer-stable": true,
66
"license": "MIT",
@@ -11,12 +11,12 @@
1111
}
1212
],
1313
"require": {
14-
"php": ">=7.1",
14+
"php": ">=8.1",
1515
"ext-json": "*"
1616
},
1717
"require-dev": {
18-
"phpunit/phpunit": "^7.0||^8.0",
19-
"friendsofphp/php-cs-fixer": "^2.13"
18+
"phpunit/phpunit": "^9.0",
19+
"friendsofphp/php-cs-fixer": "^3.9"
2020
},
2121
"autoload": {
2222
"psr-4": {

Diff for: examples/compound_doc.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
<?php declare(strict_types=1);
1+
<?php
2+
3+
declare(strict_types=1);
24

35
use JsonApiPhp\JsonApi\Attribute;
46
use JsonApiPhp\JsonApi\CompoundDocument;

Diff for: examples/simple_doc.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
<?php declare(strict_types=1);
1+
<?php
2+
3+
declare(strict_types=1);
24
require_once __DIR__.'/../vendor/autoload.php';
35

46
use JsonApiPhp\JsonApi\Attribute;

Diff for: phpunit.xml.dist

+12-16
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
1-
<?xml version="1.0" encoding="UTF-8" ?>
2-
<phpunit
3-
bootstrap="vendor/autoload.php"
4-
stopOnFailure="false"
5-
verbose="true"
6-
colors="true">
7-
<testsuites>
8-
<testsuite name="Main">
9-
<directory>./test</directory>
10-
</testsuite>
11-
</testsuites>
12-
<filter>
13-
<whitelist>
14-
<directory suffix=".php">./src/</directory>
15-
</whitelist>
16-
</filter>
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" stopOnFailure="false" verbose="true" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
3+
<coverage>
4+
<include>
5+
<directory suffix=".php">./src/</directory>
6+
</include>
7+
</coverage>
8+
<testsuites>
9+
<testsuite name="Main">
10+
<directory>./test</directory>
11+
</testsuite>
12+
</testsuites>
1713
</phpunit>

Diff for: src/Attribute.php

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
<?php declare(strict_types=1);
1+
<?php
2+
3+
declare(strict_types=1);
24

35
namespace JsonApiPhp\JsonApi;
46

@@ -8,13 +10,12 @@
810
/**
911
* @see http://jsonapi.org/format/#document-resource-object-attributes
1012
*/
11-
final class Attribute implements ResourceField
12-
{
13+
final class Attribute implements ResourceField {
1314
use ResourceFieldTrait;
14-
private $val;
1515

16-
public function __construct(string $name, $val)
17-
{
16+
private string|int|float|bool|null|array|object $val;
17+
18+
public function __construct(string $name, $val) {
1819
$this->validateFieldName($name);
1920
$this->name = $name;
2021
$this->val = $val;
@@ -24,8 +25,7 @@ public function __construct(string $name, $val)
2425
* @param object $o
2526
* @internal
2627
*/
27-
public function attachTo($o): void
28-
{
28+
public function attachTo(object $o): void {
2929
child($o, 'attributes')->{$this->name} = $this->val;
3030
}
3131
}

Diff for: src/CompoundDocument.php

+8-10
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,25 @@
1-
<?php declare(strict_types=1);
1+
<?php
2+
3+
declare(strict_types=1);
24

35
namespace JsonApiPhp\JsonApi;
46

57
use JsonApiPhp\JsonApi\Internal\DataDocumentMember;
68
use JsonApiPhp\JsonApi\Internal\PrimaryData;
9+
use JsonSerializable;
710

811
/**
912
* A Document with the "included" member
1013
* @see http://jsonapi.org/format/#document-compound-documents
1114
*/
12-
final class CompoundDocument implements \JsonSerializable
13-
{
14-
private $doc;
15+
final class CompoundDocument implements JsonSerializable {
16+
private object $doc;
1517

16-
public function __construct(PrimaryData $data, Included $included, DataDocumentMember ...$members)
17-
{
18-
$included->validateLinkage($data);
18+
public function __construct(PrimaryData $data, Included $included, DataDocumentMember ...$members) {
1919
$this->doc = combine($data, $included, ...$members);
2020
}
2121

22-
#[\ReturnTypeWillChange]
23-
public function jsonSerialize()
24-
{
22+
public function jsonSerialize(): object {
2523
return $this->doc;
2624
}
2725
}

Diff for: src/DataDocument.php

+8-9
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
1-
<?php declare(strict_types=1);
1+
<?php
2+
3+
declare(strict_types=1);
24

35
namespace JsonApiPhp\JsonApi;
46

57
use JsonApiPhp\JsonApi\Internal\DataDocumentMember;
68
use JsonApiPhp\JsonApi\Internal\PrimaryData;
9+
use JsonSerializable;
710

811
/**
912
* A Document containing the "data" member
1013
* @see http://jsonapi.org/format/#document-top-level
1114
*/
12-
final class DataDocument implements \JsonSerializable
13-
{
14-
private $value;
15+
final class DataDocument implements JsonSerializable {
16+
private object $value;
1517

16-
public function __construct(PrimaryData $data, DataDocumentMember ...$members)
17-
{
18+
public function __construct(PrimaryData $data, DataDocumentMember ...$members) {
1819
$this->value = combine($data, ...$members);
1920
}
2021

21-
#[\ReturnTypeWillChange]
22-
public function jsonSerialize()
23-
{
22+
public function jsonSerialize(): object {
2423
return $this->value;
2524
}
2625
}

Diff for: src/EmptyRelationship.php

+11-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
<?php declare(strict_types=1);
1+
<?php
2+
3+
declare(strict_types=1);
24

35
namespace JsonApiPhp\JsonApi;
46

@@ -9,24 +11,24 @@
911
/**
1012
* A relationship with no data
1113
*/
12-
class EmptyRelationship implements ResourceField
13-
{
14+
class EmptyRelationship implements ResourceField {
1415
use ResourceFieldTrait;
1516

16-
private $obj;
17+
private object $obj;
1718

18-
public function __construct(string $name, RelationshipMember $member, RelationshipMember ...$members)
19-
{
20-
$this->name = $name;
19+
public function __construct(
20+
private readonly string $name,
21+
RelationshipMember $member,
22+
RelationshipMember ...$members
23+
) {
2124
$this->obj = combine($member, ...$members);
2225
}
2326

2427
/**
2528
* @param object $o
2629
* @internal
2730
*/
28-
public function attachTo($o): void
29-
{
31+
public function attachTo(object $o): void {
3032
child($o, 'relationships')->{$this->name} = $this->obj;
3133
}
3234
}

Diff for: src/Error.php

+8-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
<?php declare(strict_types=1);
1+
<?php
2+
3+
declare(strict_types=1);
24

35
namespace JsonApiPhp\JsonApi;
46

@@ -9,13 +11,11 @@
911
* An Error Object
1012
* @see
1113
*/
12-
final class Error implements ErrorDocumentMember
13-
{
14-
private $error;
14+
final class Error implements ErrorDocumentMember {
15+
private readonly object $error;
1516

16-
public function __construct(ErrorMember ...$members)
17-
{
18-
$this->error = (object) [];
17+
public function __construct(ErrorMember ...$members) {
18+
$this->error = (object)[];
1919
foreach ($members as $member) {
2020
$member->attachTo($this->error);
2121
}
@@ -25,8 +25,7 @@ public function __construct(ErrorMember ...$members)
2525
* @param object $o
2626
* @internal
2727
*/
28-
public function attachTo($o): void
29-
{
28+
public function attachTo(object $o): void {
3029
$o->errors[] = $this->error;
3130
}
3231
}

0 commit comments

Comments
 (0)