Skip to content
Merged

PHP 8 #112

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ composer.phar
/vendor/
/composer.lock
/.php_cs.cache
.php-cs-fixer.cache
.phpunit.result.cache
16 changes: 16 additions & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

$finder = PhpCsFixer\Finder::create()
->exclude('somedir')
->notPath('src/Symfony/Component/Translation/Tests/fixtures/resources.php')
->in(__DIR__);

$config = new PhpCsFixer\Config();
return $config->setRules([
'@PSR12' => true,
'array_syntax' => ['syntax' => 'short'],
'braces' => [
'allow_single_line_closure' => true,
'position_after_functions_and_oop_constructs' => 'same'],
])
->setFinder($finder);
53 changes: 0 additions & 53 deletions .php_cs.dist

This file was deleted.

14 changes: 0 additions & 14 deletions .travis.yml

This file was deleted.

11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

## [3.0.0] - 2022-07-26
### Changed
- The package is migrated to PHP 8.1

### Removed
- Support for PHP 7 and older versions
- Compound document validation logic is dropped

## [2.2.0] - 2020-10-12
### Added
- `NewResourceObject` to allow omitting `id` in resources to-be-created (#108)
Expand All @@ -30,7 +38,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Added
- v2 initial release

[Unreleased]: https://github.com/json-api-php/json-api/compare/2.2.0...HEAD
[Unreleased]: https://github.com/json-api-php/json-api/compare/3.0.0...HEAD
[3.0.0]: https://github.com/json-api-php/json-api/compare/2.2.2...3.0.0
[2.2.0]: https://github.com/json-api-php/json-api/compare/2.1.2...2.2.0
[2.1.2]: https://github.com/json-api-php/json-api/compare/2.1.1...2.1.2
[2.1.1]: https://github.com/json-api-php/json-api/compare/2.1.0...2.1.1
Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "json-api-php/json-api",
"description": "An attempt to express JSON API specs (jsonapi.org) in object-oriented way as a set of PHP 7 classes",
"description": "JSON API specs (jsonapi.org) as a set of PHP classes",
"type": "library",
"prefer-stable": true,
"license": "MIT",
Expand All @@ -11,12 +11,12 @@
}
],
"require": {
"php": ">=7.1",
"php": ">=8.1",
"ext-json": "*"
},
"require-dev": {
"phpunit/phpunit": "^7.0||^8.0",
"friendsofphp/php-cs-fixer": "^2.13"
"phpunit/phpunit": "^9.0",
"friendsofphp/php-cs-fixer": "^3.9"
},
"autoload": {
"psr-4": {
Expand Down
4 changes: 3 additions & 1 deletion examples/compound_doc.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

use JsonApiPhp\JsonApi\Attribute;
use JsonApiPhp\JsonApi\CompoundDocument;
Expand Down
4 changes: 3 additions & 1 deletion examples/simple_doc.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);
require_once __DIR__.'/../vendor/autoload.php';

use JsonApiPhp\JsonApi\Attribute;
Expand Down
28 changes: 12 additions & 16 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
<?xml version="1.0" encoding="UTF-8" ?>
<phpunit
bootstrap="vendor/autoload.php"
stopOnFailure="false"
verbose="true"
colors="true">
<testsuites>
<testsuite name="Main">
<directory>./test</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">./src/</directory>
</whitelist>
</filter>
<?xml version="1.0" encoding="UTF-8"?>
<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">
<coverage>
<include>
<directory suffix=".php">./src/</directory>
</include>
</coverage>
<testsuites>
<testsuite name="Main">
<directory>./test</directory>
</testsuite>
</testsuites>
</phpunit>
16 changes: 8 additions & 8 deletions src/Attribute.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

namespace JsonApiPhp\JsonApi;

Expand All @@ -8,13 +10,12 @@
/**
* @see http://jsonapi.org/format/#document-resource-object-attributes
*/
final class Attribute implements ResourceField
{
final class Attribute implements ResourceField {
use ResourceFieldTrait;
private $val;

public function __construct(string $name, $val)
{
private string|int|float|bool|null|array|object $val;

public function __construct(string $name, $val) {
$this->validateFieldName($name);
$this->name = $name;
$this->val = $val;
Expand All @@ -24,8 +25,7 @@ public function __construct(string $name, $val)
* @param object $o
* @internal
*/
public function attachTo($o): void
{
public function attachTo(object $o): void {
child($o, 'attributes')->{$this->name} = $this->val;
}
}
18 changes: 8 additions & 10 deletions src/CompoundDocument.php
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

namespace JsonApiPhp\JsonApi;

use JsonApiPhp\JsonApi\Internal\DataDocumentMember;
use JsonApiPhp\JsonApi\Internal\PrimaryData;
use JsonSerializable;

/**
* A Document with the "included" member
* @see http://jsonapi.org/format/#document-compound-documents
*/
final class CompoundDocument implements \JsonSerializable
{
private $doc;
final class CompoundDocument implements JsonSerializable {
private object $doc;

public function __construct(PrimaryData $data, Included $included, DataDocumentMember ...$members)
{
$included->validateLinkage($data);
public function __construct(PrimaryData $data, Included $included, DataDocumentMember ...$members) {
$this->doc = combine($data, $included, ...$members);
}

#[\ReturnTypeWillChange]
public function jsonSerialize()
{
public function jsonSerialize(): object {
return $this->doc;
}
}
17 changes: 8 additions & 9 deletions src/DataDocument.php
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

namespace JsonApiPhp\JsonApi;

use JsonApiPhp\JsonApi\Internal\DataDocumentMember;
use JsonApiPhp\JsonApi\Internal\PrimaryData;
use JsonSerializable;

/**
* A Document containing the "data" member
* @see http://jsonapi.org/format/#document-top-level
*/
final class DataDocument implements \JsonSerializable
{
private $value;
final class DataDocument implements JsonSerializable {
private object $value;

public function __construct(PrimaryData $data, DataDocumentMember ...$members)
{
public function __construct(PrimaryData $data, DataDocumentMember ...$members) {
$this->value = combine($data, ...$members);
}

#[\ReturnTypeWillChange]
public function jsonSerialize()
{
public function jsonSerialize(): object {
return $this->value;
}
}
20 changes: 11 additions & 9 deletions src/EmptyRelationship.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

namespace JsonApiPhp\JsonApi;

Expand All @@ -9,24 +11,24 @@
/**
* A relationship with no data
*/
class EmptyRelationship implements ResourceField
{
class EmptyRelationship implements ResourceField {
use ResourceFieldTrait;

private $obj;
private object $obj;

public function __construct(string $name, RelationshipMember $member, RelationshipMember ...$members)
{
$this->name = $name;
public function __construct(
private readonly string $name,
RelationshipMember $member,
RelationshipMember ...$members
) {
$this->obj = combine($member, ...$members);
}

/**
* @param object $o
* @internal
*/
public function attachTo($o): void
{
public function attachTo(object $o): void {
child($o, 'relationships')->{$this->name} = $this->obj;
}
}
17 changes: 8 additions & 9 deletions src/Error.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

namespace JsonApiPhp\JsonApi;

Expand All @@ -9,13 +11,11 @@
* An Error Object
* @see
*/
final class Error implements ErrorDocumentMember
{
private $error;
final class Error implements ErrorDocumentMember {
private readonly object $error;

public function __construct(ErrorMember ...$members)
{
$this->error = (object) [];
public function __construct(ErrorMember ...$members) {
$this->error = (object)[];
foreach ($members as $member) {
$member->attachTo($this->error);
}
Expand All @@ -25,8 +25,7 @@ public function __construct(ErrorMember ...$members)
* @param object $o
* @internal
*/
public function attachTo($o): void
{
public function attachTo(object $o): void {
$o->errors[] = $this->error;
}
}
Loading