Skip to content

Commit d7a2694

Browse files
Fix nullable types for PHP 8.4 (#9)
1 parent f15f6f7 commit d7a2694

11 files changed

Lines changed: 30 additions & 19 deletions

.cs.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
'array_syntax' => ['syntax' => 'short'],
2020
'cast_spaces' => ['space' => 'none'],
2121
'concat_space' => ['spacing' => 'one'],
22-
'compact_nullable_typehint' => true,
22+
'compact_nullable_type_declaration' => true,
2323
'declare_equal_normalize' => ['space' => 'single'],
2424
'general_phpdoc_annotation_remove' => [
2525
'annotations' => [
@@ -36,7 +36,11 @@
3636
'phpdoc_order' => true, // psr-5
3737
'phpdoc_no_useless_inheritdoc' => false,
3838
'protected_to_private' => false,
39-
'yoda_style' => false,
39+
'yoda_style' => [
40+
'equal' => false,
41+
'identical' => false,
42+
'less_and_greater' => false
43+
],
4044
'method_argument_space' => ['on_multiline' => 'ensure_fully_multiline'],
4145
'ordered_imports' => [
4246
'sort_algorithm' => 'alpha',

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2023 odan
3+
Copyright (c) 2025 odan
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ responses and many other things.
3131

3232
## Requirements
3333

34-
* PHP 8.1+
34+
* PHP 8.1 - 8.4
3535

3636
## Installation
3737

composer.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
],
1717
"homepage": "https://github.com/selective-php/transformer",
1818
"require": {
19-
"php": "^8.1"
19+
"php": "8.1.* || 8.2.* || 8.3.* || 8.4.*"
2020
},
2121
"require-dev": {
2222
"friendsofphp/php-cs-fixer": "^3",
23-
"phpstan/phpstan": "^1",
23+
"phpstan/phpstan": "^1 || ^2",
2424
"phpunit/phpunit": "^10",
2525
"squizlabs/php_codesniffer": "^3"
2626
},
@@ -49,13 +49,16 @@
4949
"sniffer:check": "phpcs --standard=phpcs.xml",
5050
"sniffer:fix": "phpcbf --standard=phpcs.xml",
5151
"stan": "phpstan analyse -c phpstan.neon --no-progress --ansi",
52-
"test": "phpunit --configuration phpunit.xml --do-not-cache-result --colors=always",
52+
"test": "phpunit --configuration phpunit.xml --do-not-cache-result --colors=always --display-warnings --display-deprecations --no-coverage",
5353
"test:all": [
5454
"@cs:check",
5555
"@sniffer:check",
5656
"@stan",
5757
"@test"
5858
],
59-
"test:coverage": "php -d xdebug.mode=coverage -r \"require 'vendor/bin/phpunit';\" -- --configuration phpunit.xml --do-not-cache-result --colors=always --coverage-clover build/logs/clover.xml --coverage-html build/coverage"
59+
"test:coverage": [
60+
"@putenv XDEBUG_MODE=coverage",
61+
"phpunit --configuration phpunit.xml --do-not-cache-result --colors=always --display-warnings --display-deprecations --coverage-clover build/coverage/clover.xml --coverage-html build/coverage --coverage-text"
62+
]
6063
}
6164
}

phpstan.neon

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
parameters:
22
level: 8
3-
checkMissingIterableValueType: false
43
reportUnmatchedIgnoredErrors: false
54
ignoreErrors:
65
- '#Parameter \#2 \$default of method Selective\\Transformer\\ArrayData::get\(\) expects null, mixed given.#'

src/ArrayData.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ final class ArrayData
1111
{
1212
/**
1313
* Internal representation of data data.
14+
*
15+
* @var array<mixed>
1416
*/
1517
private array $data = [];
1618

1719
/**
1820
* The constructor.
1921
*
20-
* @param array $data The data
22+
* @param array<mixed> $data The data
2123
*/
2224
public function __construct(array $data = [])
2325
{
@@ -93,7 +95,7 @@ public function get(string $key, $default = null)
9395
/**
9496
* Get all values.
9597
*
96-
* @return array The values
98+
* @return array<mixed> The values
9799
*/
98100
public function all(): array
99101
{

src/ArrayTransformer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ final class ArrayTransformer implements TransformerInterface
5151
*
5252
* @param ArrayTransformer|null $transformer The parent transformer
5353
*/
54-
public function __construct(ArrayTransformer $transformer = null)
54+
public function __construct(?ArrayTransformer $transformer = null)
5555
{
5656
$this->converter = new ArrayValueConverter();
5757

src/ArrayTransformerFilterItem.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,16 @@ final class ArrayTransformerFilterItem
99
{
1010
private string $name = '';
1111

12+
/**
13+
* @var array<mixed>
14+
*/
1215
private array $arguments = [];
1316

1417
/**
1518
* The constructor.
1619
*
1720
* @param string $name The filter to apply
18-
* @param array $arguments The parameters for the filter
21+
* @param array<mixed> $arguments The parameters for the filter
1922
*/
2023
public function __construct(string $name, array $arguments = [])
2124
{
@@ -36,7 +39,7 @@ public function getName(): string
3639
/**
3740
* Get filter parameters.
3841
*
39-
* @return array The params
42+
* @return array<mixed> The params
4043
*/
4144
public function getArguments(): array
4245
{

src/ArrayTransformerRule.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ final class ArrayTransformerRule
3232
*
3333
* @param ArrayTransformer|null $transformer The parent transformer
3434
*/
35-
public function __construct(ArrayTransformer $transformer = null)
35+
public function __construct(?ArrayTransformer $transformer = null)
3636
{
3737
$this->transformer = $transformer ?? new ArrayTransformer();
3838
}
@@ -222,7 +222,7 @@ public function number(int $decimals = 0, string $decimalSeparator = '.', string
222222
*
223223
* @return $this Self
224224
*/
225-
public function date(string $format = 'Y-m-d H:i:s', DateTimeZone $dateTimeZone = null): self
225+
public function date(string $format = 'Y-m-d H:i:s', ?DateTimeZone $dateTimeZone = null): self
226226
{
227227
return $this->filter('date', $format, $dateTimeZone);
228228
}

src/Filter/DateTimeFilter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ final class DateTimeFilter
2323
*
2424
* @return string The value
2525
*/
26-
public function __invoke($value, string $format = null, DateTimeZone $timezone = null)
26+
public function __invoke($value, ?string $format = null, ?DateTimeZone $timezone = null)
2727
{
2828
try {
2929
$format = $format ?? 'Y-m-d H:i:s';
@@ -52,7 +52,7 @@ public function __invoke($value, string $format = null, DateTimeZone $timezone =
5252
private function formatDateTime(
5353
DateTimeImmutable $value,
5454
string $format,
55-
DateTimeZone $timezone = null
55+
?DateTimeZone $timezone = null
5656
): string {
5757
if ($timezone) {
5858
// This would only with only work with UTC as default time zone.

0 commit comments

Comments
 (0)