Skip to content

Commit edca381

Browse files
authored
Merge pull request #151 from voku/copilot/find-and-fix-deprecated-code
Fix deprecated PHP patterns for PHP 8.2–8.5+ compatibility
2 parents e88173f + f833480 commit edca381

13 files changed

Lines changed: 49 additions & 53 deletions

.github/workflows/ci.yml

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,12 @@ jobs:
1717
fail-fast: false
1818
matrix:
1919
php: [
20-
7.0,
21-
7.1,
22-
7.2,
23-
7.3,
24-
7.4,
2520
8.0,
2621
8.1
2722
]
2823
composer: [basic]
2924
include:
30-
- php: 7.3
25+
- php: 8.0
3126
composer: lowest
3227
timeout-minutes: 10
3328
steps:
@@ -44,10 +39,10 @@ jobs:
4439

4540
- name: Determine composer cache directory
4641
id: composer-cache
47-
run: echo "::set-output name=directory::$(composer config cache-dir)"
42+
run: echo "directory=$(composer config cache-dir)" >> $GITHUB_OUTPUT
4843

4944
- name: Cache composer dependencies
50-
uses: actions/cache@v3.3.1
45+
uses: actions/cache@v4
5146
with:
5247
path: ${{ steps.composer-cache.outputs.directory }}
5348
key: ${{ matrix.php }}-composer-${{ hashFiles('**/composer.lock') }}
@@ -94,7 +89,7 @@ jobs:
9489

9590
- name: Archive logs artifacts
9691
if: ${{ failure() }}
97-
uses: actions/upload-artifact@v3
92+
uses: actions/upload-artifact@v4
9893
with:
9994
name: logs_composer-${{ matrix.composer }}_php-${{ matrix.php }}
10095
path: |

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@
2020
}
2121
],
2222
"require": {
23-
"php": ">=7.0.0",
23+
"php": ">=8.0.0",
2424
"ext-json": "*",
2525
"symfony/polyfill-mbstring": "~1.0",
2626
"phpdocumentor/reflection-docblock": "~4.3 || ~5.0"
2727
},
2828
"require-dev": {
29-
"phpunit/phpunit": "~6.0 || ~7.0 || ~9.0"
29+
"phpunit/phpunit": "~6.0 || ~7.0 || ~9.0",
30+
"phpstan/phpstan": "^1.0"
3031
},
3132
"support": {
3233
"docs": "https://voku.github.io/Arrayy/",

phpstan.neon

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
parameters:
22
level: 8
33
reportUnmatchedIgnoredErrors: false
4-
checkGenericClassInNonGenericObjectType: true
5-
checkMissingIterableValueType: false
64
paths:
75
- %currentWorkingDirectory%/src/
86
- %currentWorkingDirectory%/tests/

phpunit.xml.dist

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit backupGlobals="false"
3-
backupStaticAttributes="false"
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.6/phpunit.xsd"
4+
backupGlobals="false"
45
colors="true"
5-
convertErrorsToExceptions="true"
6-
convertNoticesToExceptions="true"
7-
convertWarningsToExceptions="true"
86
processIsolation="false"
97
stopOnFailure="false"
108
bootstrap="tests/bootstrap.php"
@@ -13,12 +11,15 @@
1311
<testsuite name="Arrayy Test Suite">
1412
<directory>tests</directory>
1513
</testsuite>
16-
<filter>
17-
<whitelist processUncoveredFilesFromWhitelist="true">
18-
<directory suffix=".php">./src/</directory>
19-
</whitelist>
20-
</filter>
2114
<logging>
22-
<log type="coverage-clover" target="build/logs/clover.xml"/>
15+
<junit outputFile="build/logs/junit.xml"/>
2316
</logging>
17+
<coverage processUncoveredFiles="true">
18+
<include>
19+
<directory suffix=".php">./src/</directory>
20+
</include>
21+
<report>
22+
<clover outputFile="build/logs/clover.xml"/>
23+
</report>
24+
</coverage>
2425
</phpunit>

src/Arrayy.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1941,7 +1941,7 @@ public static function createFromObjectVars($object): self
19411941
* @phpstan-return static<int,string>
19421942
* @psalm-mutation-free
19431943
*/
1944-
public static function createFromString(string $str, string $delimiter = null, string $regEx = null): self
1944+
public static function createFromString(string $str, ?string $delimiter = null, ?string $regEx = null): self
19451945
{
19461946
if ($regEx) {
19471947
\preg_match_all($regEx, $str, $array);
@@ -2648,7 +2648,7 @@ public function filter($closure = null, int $flag = \ARRAY_FILTER_USE_BOTH)
26482648
public function filterBy(
26492649
string $property,
26502650
$value,
2651-
string $comparisonOp = null
2651+
?string $comparisonOp = null
26522652
): self {
26532653
if (!$comparisonOp) {
26542654
$comparisonOp = \is_array($value) ? 'contains' : 'eq';
@@ -2834,7 +2834,7 @@ public function firstKey()
28342834
* @phpstan-return static<TKey,T>
28352835
* @psalm-mutation-free
28362836
*/
2837-
public function firstsImmutable(int $number = null): self
2837+
public function firstsImmutable(?int $number = null): self
28382838
{
28392839
$arrayTmp = $this->toArray();
28402840

@@ -2863,7 +2863,7 @@ public function firstsImmutable(int $number = null): self
28632863
* @phpstan-return static<array-key,TKey>
28642864
* @psalm-mutation-free
28652865
*/
2866-
public function firstsKeys(int $number = null): self
2866+
public function firstsKeys(?int $number = null): self
28672867
{
28682868
$arrayTmp = $this->keys()->toArray();
28692869

@@ -2895,7 +2895,7 @@ public function firstsKeys(int $number = null): self
28952895
*
28962896
* @phpstan-return ($number is null ? static<int,T> : static<TKey,T>)
28972897
*/
2898-
public function firstsMutable(int $number = null): self
2898+
public function firstsMutable(?int $number = null): self
28992899
{
29002900
$this->generatorToArray();
29012901

@@ -2972,7 +2972,7 @@ public function flip(): self
29722972
public function get(
29732973
$key = null,
29742974
$fallback = null,
2975-
array $array = null,
2975+
?array $array = null,
29762976
bool $useByReference = false
29772977
) {
29782978
if ($array === null && $key === null) {
@@ -4265,7 +4265,7 @@ public function lastKey()
42654265
* @phpstan-return static<TKey,T>
42664266
* @psalm-mutation-free
42674267
*/
4268-
public function lastsImmutable(int $number = null): self
4268+
public function lastsImmutable(?int $number = null): self
42694269
{
42704270
if ($this->isEmpty()) {
42714271
return static::create(
@@ -4310,7 +4310,7 @@ public function lastsImmutable(int $number = null): self
43104310
*
43114311
* @phpstan-return static<TKey,T>
43124312
*/
4313-
public function lastsMutable(int $number = null): self
4313+
public function lastsMutable(?int $number = null): self
43144314
{
43154315
if ($this->isEmpty()) {
43164316
return $this;
@@ -4724,7 +4724,7 @@ public function mostUsedValue()
47244724
* @phpstan-return static<array-key,T>
47254725
* @psalm-mutation-free
47264726
*/
4727-
public function mostUsedValues(int $number = null): self
4727+
public function mostUsedValues(?int $number = null): self
47284728
{
47294729
return $this->countValues()->arsortImmutable()->firstsKeys($number);
47304730
}
@@ -5230,7 +5230,7 @@ public function push(...$args)
52305230
*
52315231
* @phpstan-return static<array-key,T>
52325232
*/
5233-
public function randomImmutable(int $number = null): self
5233+
public function randomImmutable(?int $number = null): self
52345234
{
52355235
$this->generatorToArray();
52365236

@@ -5347,7 +5347,7 @@ public function randomKeys(int $number): self
53475347
*
53485348
* @phpstan-return static<TKey,T>
53495349
*/
5350-
public function randomMutable(int $number = null): self
5350+
public function randomMutable(?int $number = null): self
53515351
{
53525352
$this->generatorToArray();
53535353

@@ -5429,7 +5429,7 @@ public function randomValues(int $number): self
54295429
* @phpstan-param array<(int&T)|(string&T),int> $array
54305430
* @phpstan-return static<array-key,T>
54315431
*/
5432-
public function randomWeighted(array $array, int $number = null): self
5432+
public function randomWeighted(array $array, ?int $number = null): self
54335433
{
54345434
// init
54355435
$options = [];
@@ -6248,7 +6248,7 @@ public function shift()
62486248
* @phpstan-param array<TKey,T> $array
62496249
* @phpstan-return static<TKey,T>
62506250
*/
6251-
public function shuffle(bool $secure = false, array $array = null): self
6251+
public function shuffle(bool $secure = false, ?array $array = null): self
62526252
{
62536253
if ($array === null) {
62546254
$array = $this->toArray(false);
@@ -6454,7 +6454,7 @@ public function sizeRecursive(): int
64546454
* @phpstan-return static<array-key,T>
64556455
* @psalm-mutation-free
64566456
*/
6457-
public function slice(int $offset, int $length = null, bool $preserveKeys = false)
6457+
public function slice(int $offset, ?int $length = null, bool $preserveKeys = false)
64586458
{
64596459
return static::create(
64606460
\array_slice(
@@ -6719,7 +6719,7 @@ static function ($value) use ($sorter) {
67196719
* @phpstan-return static<TKey,T>
67206720
* @psalm-mutation-free
67216721
*/
6722-
public function splice(int $offset, int $length = null, $replacement = []): self
6722+
public function splice(int $offset, ?int $length = null, $replacement = []): self
67236723
{
67246724
$tmpArray = $this->toArray();
67256725

@@ -6967,7 +6967,7 @@ public function toJson(int $options = 0, int $depth = 512): string
69676967
*
69686968
* @phpstan-return static<int, static<TKey,T>>
69696969
*/
6970-
public function toPermutation(array $items = null, array $helper = []): self
6970+
public function toPermutation(?array $items = null, array $helper = []): self
69716971
{
69726972
// init
69736973
$return = [];
@@ -7891,7 +7891,7 @@ protected static function objectToArray($object)
78917891
/**
78927892
* @psalm-suppress PossiblyInvalidArgument - the parameter is always some kind of array - false-positive from psalm?
78937893
*/
7894-
return \array_map(['static', 'objectToArray'], $object);
7894+
return \array_map([static::class, 'objectToArray'], $object);
78957895
}
78967896

78977897
/**

src/ArrayyMeta.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Arrayy;
66

7+
#[\AllowDynamicProperties]
78
final class ArrayyMeta
89
{
910
/** @noinspection MagicMethodsValidityInspection */

src/ArrayyRewindableExtendedGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class ArrayyRewindableExtendedGenerator extends ArrayyRewindableGenerator
1515
{
1616
public function __construct(
1717
callable $generatorConstructionFunction,
18-
callable $onRewind = null,
18+
?callable $onRewind = null,
1919
string $class = ''
2020
) {
2121
parent::__construct(

src/ArrayyRewindableGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class ArrayyRewindableGenerator extends \ArrayIterator
4949
*/
5050
public function __construct(
5151
callable $generatorConstructionFunction,
52-
callable $onRewind = null,
52+
?callable $onRewind = null,
5353
string $class = ''
5454
) {
5555
$this->class = $class;

src/Collection/Collection.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ class Collection extends AbstractCollection
102102
*/
103103
public function __construct(
104104
$data = [],
105-
string $iteratorClass = null,
106-
bool $checkPropertiesInConstructor = null,
107-
TypeInterface $type = null
105+
?string $iteratorClass = null,
106+
?bool $checkPropertiesInConstructor = null,
107+
?TypeInterface $type = null
108108
) {
109109
// fallback
110110
if ($iteratorClass === null) {

src/Collection/CollectionInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ public function set($key, $value);
496496
*
497497
* @phpstan-return CollectionInterface<array-key|TKey,T>
498498
*/
499-
public function slice(int $offset, int $length = null, bool $preserveKeys = false);
499+
public function slice(int $offset, ?int $length = null, bool $preserveKeys = false);
500500

501501
/**
502502
* Gets a native PHP array representation of the collection.

0 commit comments

Comments
 (0)