Skip to content

Commit

Permalink
feat: Support PHP 8.1 (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
alekitto authored Sep 28, 2022
1 parent 6976424 commit 3faff22
Show file tree
Hide file tree
Showing 115 changed files with 635 additions and 940 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cscheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
uses: shivammathur/setup-php@v2
with:
coverage: none
php-version: "7.4"
php-version: "8.1"
tools: cs2pr

- name: Install dependencies with composer
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
uses: shivammathur/setup-php@v2
with:
coverage: none
php-version: "8.0"
php-version: "8.1"
tools: cs2pr

- name: Install dependencies with composer
Expand Down
13 changes: 4 additions & 9 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,8 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
composer_flags:
- ''
- '--prefer-lowest'

php_version:
- '7.4'
- '8.0'
- '8.1'

name: PHP ${{ matrix.php_version }}
steps:
Expand All @@ -30,13 +25,13 @@ jobs:
extensions: :opcache, mongodb

- run: composer remove --no-update --dev roave/security-advisories solido/php-coding-standards
- run: composer update --with-all-dependencies ${{ matrix.composer_flags }}
- run: composer update --with-all-dependencies

- run: vendor/bin/phpunit
if: matrix.php_version != '8.0' || matrix.composer_flags == '--prefer-lowest'
if: matrix.php_version != '8.1'

- run: vendor/bin/phpunit --coverage-clover coverage.xml
if: matrix.php_version == '8.0' && matrix.composer_flags == ''
if: matrix.php_version == '8.1'
env:
XDEBUG_MODE: coverage

Expand Down
56 changes: 30 additions & 26 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
}
],
"require": {
"php": "^7.4 | ^8.0",
"php": "^8.1",
"composer-runtime-api": "^2.0",
"doctrine/common": "^2.0 | ^3.0",
"doctrine/common": "^2.0 || ^3.0",
"doctrine/instantiator": "^1.0",
"doctrine/inflector": "^1.0 | ^2.0",
"doctrine/inflector": "^1.0 || ^2.0",
"doctrine/lexer": "^1.0",
"kcs/metadata": "^2.0 | ^3.0 | ^4.0",
"kcs/metadata": "^2.0 || ^3.0 || ^4.0",
"psr/event-dispatcher": "^1.0",
"symfony/polyfill-php80": "^1.15",
"thecodingmachine/safe": "^1.1"
Expand All @@ -41,35 +41,35 @@
"doctrine/orm": "^2.3",
"doctrine/persistence": "^2.0",
"doctrine/phpcr-odm": "^1.0",
"friendsofphp/proxy-manager-lts": "^1.0",
"jackalope/jackalope-doctrine-dbal": "^1.0",
"nikic/php-parser": "^4.10.0",
"ocramius/proxy-manager": "^2.6",
"phpcollection/phpcollection": "^0.5.0",
"phpdocumentor/reflection-docblock": "^3.0|^4.0|^5.0",
"phpdocumentor/type-resolver": ">=0.1.8,<1.0|^1.0",
"phpdocumentor/reflection-docblock": "^3.0 || ^4.0 || ^5.0",
"phpdocumentor/type-resolver": ">=0.1.8,<1.0 || ^1.0",
"phpspec/prophecy-phpunit": "^2.0",
"phpunit/phpunit": "^9.4",
"psr/log": "^1.1",
"ramsey/uuid": "^4.0|^3.6",
"ramsey/uuid": "^4.0 || ^3.6",
"roave/security-advisories": "dev-master",
"solido/php-coding-standards": "dev-master",
"symfony/browser-kit": "^4.4|^5.0",
"symfony/config": "^4.4.12|^5.1.4",
"symfony/contracts": "^1.1|^2.0",
"symfony/css-selector": "^4.4|^5.0",
"symfony/dependency-injection": "^4.4.12|^5.1.4",
"symfony/dom-crawler": "^4.4.12|^5.1.4",
"symfony/event-dispatcher": "^4.4|^5.0",
"symfony/form": "^4.4|^5.0",
"symfony/framework-bundle": "^4.4|^5.0",
"symfony/http-kernel": "^4.4|^5.0",
"symfony/property-info": "^4.4|^5.0",
"symfony/serializer": "^4.4|^5.0",
"symfony/translation": "^4.4|^5.0",
"symfony/validator": "^4.4|^5.0",
"symfony/web-profiler-bundle": "^4.4|^5.0",
"symfony/yaml": "^4.4|^5.0",
"twig/twig": "^1.12|^2.0|^3.0"
"symfony/browser-kit": "^4.4 || ^5.0",
"symfony/config": "^4.4.12 || ^5.1.4",
"symfony/contracts": "^1.1 || ^2.0",
"symfony/css-selector": "^4.4 || ^5.0",
"symfony/dependency-injection": "^4.4.12 || ^5.1.4",
"symfony/dom-crawler": "^4.4.12 || ^5.1.4",
"symfony/event-dispatcher": "^4.4 || ^5.0",
"symfony/form": "^4.4 || ^5.0",
"symfony/framework-bundle": "^4.4 || ^5.0",
"symfony/http-kernel": "^4.4 || ^5.0",
"symfony/property-info": "^4.4 || ^5.0",
"symfony/serializer": "^4.4 || ^5.0",
"symfony/translation": "^4.4 || ^5.0",
"symfony/validator": "^4.4 || ^5.0",
"symfony/web-profiler-bundle": "^4.4 || ^5.0",
"symfony/yaml": "^4.4 || ^5.0",
"twig/twig": "^1.12 || ^2.0 || ^3.0"
},
"autoload": {
"psr-4": {
Expand All @@ -90,7 +90,11 @@
"csfix": "vendor/bin/phpcbf --standard=Solido src/"
},
"config": {
"sort-packages": true
"sort-packages": true,
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true,
"phpstan/extension-installer": true
}
},
"extra": {
"branch-alias": {
Expand Down
18 changes: 9 additions & 9 deletions docs/reference/php_attributes.md
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,15 @@ No arguments.
objects with this attribute. Also, AccessorOrder will be using the name of the property
to determine the order.

Immutable
--------
This attribute can be defined on a property or a class to indicate that the data of the property
is read only and cannot be set during deserialization.

A property can be marked as non-immutable with `Immutable(false)` attribute (useful when a class is marked as immutable).

No arguments.

MaxDepth
--------
This attribute can be defined on a property to limit the depth to which the
Expand All @@ -299,15 +308,6 @@ Arguments:
| ---------------- | ------ | -------- | ---------------------------------- |
| policy (default) | string | yes | The behavior to apply on exclusion |

ReadOnly
--------
This attribute can be defined on a property or a class to indicate that the data of the property
is read only and cannot be set during deserialization.

A property can be marked as non read only with `ReadOnly(false)` attribute (useful when a class is marked as read only).

No arguments.

SerializedName
--------------
This attribute can be defined on a property to define the serialized name for a
Expand Down
4 changes: 2 additions & 2 deletions docs/reference/xml_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ For additional information of attributes and elements, see [PHP attributes refer
<?xml version="1.0" encoding="UTF-8" ?>
<serializer>
<class name="Fully\Qualified\ClassName" exclusion-policy="ALL" exclude="true"
access-type="public_method" read-only="false">
access-type="public_method" immutable="false">
<accessor-order order="custom" custom="propertyName1,propertyName2,...,propertyNameN"/>
<xml-root name="foo-bar" namespace="http://foo.bar/2016/ns" />
<xml-namespace prefix="atom" uri="http://www.w3.org/2005/Atom" />
Expand All @@ -29,7 +29,7 @@ For additional information of attributes and elements, see [PHP attributes refer
accessor-getter="getSomeProperty"
accessor-setter="setSomeProperty"
inline="true"
read-only="true"
immutable="true"
groups="foo,bar"
xml-key-value-pairs="true"
xml-attribute-map="true"
Expand Down
4 changes: 2 additions & 2 deletions docs/reference/yml_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Vendor\MyBundle\Model\ClassName:
name: foobar
namespace: http://your.default.namespace
exclude: true
read_only: false
immutable: false
access_type: public_method # defaults to property
accessor_order:
order: custom
Expand Down Expand Up @@ -57,7 +57,7 @@ Vendor\MyBundle\Model\ClassName:
namespace: http://www.w3.org/2005/Atom
xml_value: true
inline: true
read_only: true
immutable: true
xml_key_value_pairs: true
xml_list:
inline: true
Expand Down
12 changes: 2 additions & 10 deletions src/AbstractVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,12 @@ public function getNamingStrategy(): PropertyNamingStrategyInterface
return $this->namingStrategy;
}

/**
* @param mixed $data
*
* @return mixed
*/
public function prepare($data)
public function prepare(mixed $data): mixed
{
return $data;
}

/**
* {@inheritdoc}
*/
public function visitCustom(callable $handler, $data, Type $type, Context $context)
public function visitCustom(callable $handler, mixed $data, Type $type, Context $context): mixed
{
return $handler($this, $data, $type, $context);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Annotation/AccessType.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ final class AccessType
* @param array<string, mixed>|string $type
* @phpstan-param array{type?: string, value?: string}|string $type
*/
public function __construct($type)
public function __construct(array|string $type)
{
if (is_string($type)) {
$data = ['type' => $type];
Expand Down
7 changes: 1 addition & 6 deletions src/Annotation/Accessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,9 @@
namespace Kcs\Serializer\Annotation;

use Attribute;
use TypeError;

use function get_debug_type;
use function is_array;
use function is_string;
use function Safe\sprintf;

/**
* @Annotation
Expand All @@ -26,14 +23,12 @@ final class Accessor
* @param array<string, mixed>|string|null $getter
* @phpstan-param array{getter?: string, value?: string, setter?: string}|string|null $getter
*/
public function __construct($getter = null, ?string $setter = null)
public function __construct(array | string | null $getter = null, ?string $setter = null)
{
if (is_string($getter)) {
$data = ['getter' => $getter];
} elseif (is_array($getter)) {
$data = $getter;
} elseif ($getter !== null) {
throw new TypeError(sprintf('Argument #1 passed to %s must be a string. %s passed', __METHOD__, get_debug_type($getter)));
}

$this->getter = $data['getter'] ?? $data['value'] ?? null;
Expand Down
4 changes: 2 additions & 2 deletions src/Annotation/AccessorOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ final class AccessorOrder
public string $order;

/** @var string|string[] */
public $custom = [];
public string|array $custom = [];

/**
* @param array<string, mixed>|string $order
* @phpstan-param array{order?: string, value?: string, custom?: string|string[]}|string $order
*/
public function __construct($order, ?array $custom = null)
public function __construct(array|string $order, ?array $custom = null)
{
if (is_string($order)) {
$data = ['order' => $order];
Expand Down
2 changes: 1 addition & 1 deletion src/Annotation/AdditionalField.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ final class AdditionalField
* @param array<string, mixed>|string $name
* @phpstan-param array{name?: string, value?: string, attributes?: object[]|array{string, string}[]}|string $name
*/
public function __construct($name, ?array $attributes = null)
public function __construct(array|string $name, ?array $attributes = null)
{
if (is_string($name)) {
$data = ['name' => $name];
Expand Down
7 changes: 1 addition & 6 deletions src/Annotation/Csv.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,9 @@
namespace Kcs\Serializer\Annotation;

use Attribute;
use TypeError;

use function get_debug_type;
use function is_array;
use function is_string;
use function Safe\sprintf;

/**
* @Annotation
Expand All @@ -31,14 +28,12 @@ final class Csv
* @param array<string, mixed>|string $delimiter
* @phpstan-param array{delimiter?: string, value?: string, enclosure?: string, escapeChar?: string, escapeFormulas?: bool, keySeparator?: string, printHeaders?: bool, outputBom?: bool}|string $delimiter
*/
public function __construct($delimiter, ?string $enclosure = null, ?string $escapeChar = null, ?bool $escapeFormulas = null, ?string $keySeparator = null, ?bool $printHeaders = null, ?bool $outputBom = null)
public function __construct(array|string|null $delimiter = null, ?string $enclosure = null, ?string $escapeChar = null, ?bool $escapeFormulas = null, ?string $keySeparator = null, ?bool $printHeaders = null, ?bool $outputBom = null)
{
if (is_string($delimiter)) {
$data = ['delimiter' => $delimiter];
} elseif (is_array($delimiter)) {
$data = $delimiter;
} elseif ($delimiter !== null) {
throw new TypeError(sprintf('Argument #1 passed to %s must be a string or null. %s passed', __METHOD__, get_debug_type($delimiter)));
}

$this->delimiter = $data['delimiter'] ?? $data['value'] ?? null;
Expand Down
4 changes: 2 additions & 2 deletions src/Annotation/Discriminator.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ final class Discriminator

public bool $disabled = false;

/** @var string|string[] */
public $groups;
/** @var string|string[]|null */
public string|array|null $groups;

/**
* @param array<string, mixed> $map
Expand Down
2 changes: 1 addition & 1 deletion src/Annotation/ExclusionPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ final class ExclusionPolicy
* @param array<string, mixed>|string $policy
* @phpstan-param array{policy?: string, value?: string}|string $policy
*/
public function __construct($policy)
public function __construct(array|string $policy)
{
if (is_string($policy)) {
$data = ['policy' => $policy];
Expand Down
2 changes: 1 addition & 1 deletion src/Annotation/Groups.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ final class Groups
* @param array<string, mixed>|string[]|string $groups
* @phpstan-param array{groups?: string[]|array<string, mixed>, value?: string[]|array<string, mixed>}|array<string, mixed>|string[]|string $groups
*/
public function __construct($groups)
public function __construct(array|string $groups)
{
if (is_string($groups)) {
$data = ['groups' => [$groups]];
Expand Down
39 changes: 39 additions & 0 deletions src/Annotation/Immutable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

namespace Kcs\Serializer\Annotation;

use Attribute;
use TypeError;

use function get_debug_type;
use function is_array;
use function is_bool;
use function Safe\sprintf;

/**
* @Annotation
* @Target({"CLASS","PROPERTY"})
*/
#[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_PROPERTY)]
final class Immutable
{
public bool $immutable = true;

/**
* @param array<string, mixed>|bool $immutable
*/
public function __construct(array|bool $immutable = true)
{
if (is_bool($immutable)) {
$data = ['immutable' => $immutable];
} elseif (is_array($immutable)) {
$data = $immutable;
} elseif ($immutable !== null) {
throw new TypeError(sprintf('Argument #1 passed to %s must be a bool. %s passed', __METHOD__, get_debug_type($immutable)));
}

$this->immutable = $data['immutable'] ?? $data['value'] ?? true;
}
}
2 changes: 1 addition & 1 deletion src/Annotation/MaxDepth.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ final class MaxDepth
* @param array<string, mixed>|int $depth
* @phpstan-param array{depth?: int, value?: int}|int $depth
*/
public function __construct($depth)
public function __construct(array|int $depth)
{
if (is_int($depth)) {
$data = ['depth' => $depth];
Expand Down
Loading

0 comments on commit 3faff22

Please sign in to comment.