Skip to content

Commit 8ecd5db

Browse files
authored
Upgrade PHPStan to v2 (#274)
1 parent c04f96c commit 8ecd5db

8 files changed

+20
-15
lines changed

Diff for: composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"nikic/php-parser": "^4.13",
1515
"php-stubs/generator": "^0.8.3",
1616
"phpdocumentor/reflection-docblock": "^5.4.1",
17-
"phpstan/phpstan": "^1.11",
17+
"phpstan/phpstan": "^2.1",
1818
"phpunit/phpunit": "^9.5",
1919
"szepeviktor/phpcs-psr-12-neutron-hybrid-ruleset": "^1.1.1",
2020
"wp-coding-standards/wpcs": "3.1.0 as 2.3.0"

Diff for: phpstan.neon.dist

+8-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ parameters:
77
- tests/
88
excludePaths:
99
- tests/data/
10+
phpVersion:
11+
min: 80000
12+
max: 80300
1013
level: 9
11-
featureToggles:
12-
alwaysTrueAlwaysReported: true
13-
listType: true
14+
ignoreErrors:
15+
-
16+
path: tests/Faker.php
17+
identifier: class.notFound
18+
count: 8

Diff for: tests/Faker.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,10 @@ public static function list($type = null): array
8888
* @template T
8989
* @param T ...$types
9090
* @return T
91+
*
92+
* @phpcs:disable NeutronStandard.Functions.TypeHint
9193
*/
92-
public static function union(...$types): mixed
94+
public static function union(...$types)
9395
{
9496
return $types[0];
9597
}

Diff for: tests/data/Faker.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
assertType('non-empty-string', Faker::nonEmptyString());
2727

2828
// Arrays with default values
29-
assertType('array', Faker::array());
29+
assertType('array<mixed>', Faker::array());
3030
assertType('array<int, mixed>', Faker::intArray());
3131
assertType('array<string, mixed>', Faker::strArray());
3232
assertType('list<mixed>', Faker::list());
@@ -44,8 +44,8 @@
4444
assertType('array<int, int>|bool|int|string', Faker::union(Faker::bool(), Faker::int(), Faker::string(), Faker::intArray(Faker::int())));
4545
assertType('array<int|string, int|string>', Faker::union(Faker::intArray(Faker::int()), Faker::strArray(Faker::string())));
4646
assertType('array<int|string>', Faker::union(Faker::array(Faker::int()), Faker::strArray(Faker::string())));
47-
assertType('array', Faker::union(Faker::array(), Faker::strArray()));
48-
assertType('array', Faker::union(Faker::array(), Faker::intArray()));
47+
assertType('array<mixed>', Faker::union(Faker::array(), Faker::strArray()));
48+
assertType('array<mixed>', Faker::union(Faker::array(), Faker::intArray()));
4949
assertType('string|null', Faker::union(Faker::string(), null));
5050

5151
// Other

Diff for: tests/data/_wp_json_sanity_check.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111
assertType('bool', _wp_json_sanity_check(Faker::bool(), 1));
1212
assertType('int', _wp_json_sanity_check(Faker::int(), 1));
1313
assertType('string', _wp_json_sanity_check(Faker::string(), 1));
14-
assertType('array', _wp_json_sanity_check(Faker::array(), 1));
14+
assertType('array<mixed>', _wp_json_sanity_check(Faker::array(), 1));
1515
assertType('stdClass', _wp_json_sanity_check(Faker::stdClass(), 1));
1616
assertType('mixed', _wp_json_sanity_check(Faker::mixed(), 1));

Diff for: tests/data/stripslashes.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
assertType('int', stripslashes_deep(Faker::int()));
1414
assertType('float', stripslashes_deep(Faker::float()));
1515
assertType('string', stripslashes_deep(Faker::string()));
16-
assertType('array', stripslashes_deep(Faker::array()));
16+
assertType('array<mixed>', stripslashes_deep(Faker::array()));
1717
assertType('resource', stripslashes_deep(Faker::resource()));
1818
assertType('object', stripslashes_deep(Faker::object()));
1919

@@ -22,6 +22,6 @@
2222
assertType('int', stripslashes_from_strings_only(Faker::int()));
2323
assertType('float', stripslashes_from_strings_only(Faker::float()));
2424
assertType('string', stripslashes_from_strings_only(Faker::string()));
25-
assertType('array', stripslashes_from_strings_only(Faker::array()));
25+
assertType('array<mixed>', stripslashes_from_strings_only(Faker::array()));
2626
assertType('resource', stripslashes_from_strings_only(Faker::resource()));
2727
assertType('object', stripslashes_from_strings_only(Faker::object()));

Diff for: tests/data/wpdb.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
// wpdb::get_row()
1111
assertType('stdClass|null', wpdb::get_row());
1212
assertType('stdClass|null', wpdb::get_row(null, 'OBJECT'));
13-
assertType('array|null', wpdb::get_row(null, 'ARRAY_A'));
13+
assertType('array<mixed>|null', wpdb::get_row(null, 'ARRAY_A'));
1414
assertType('list<mixed>|null', wpdb::get_row(null, 'ARRAY_N'));
1515

1616
// wpdb::get_results()
17-
assertType('list<array>|null', wpdb::get_results(null, 'ARRAY_A'));
17+
assertType('list<array<mixed>>|null', wpdb::get_results(null, 'ARRAY_A'));
1818
assertType('list<array<int, mixed>>|null', wpdb::get_results(null, 'ARRAY_N'));
1919
assertType('list<stdClass>|null', wpdb::get_results());
2020
assertType('list<stdClass>|null', wpdb::get_results(null, 'OBJECT'));

Diff for: tests/phpstan.neon

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
parameters:
22
bootstrapFiles:
33
- ../wordpress-stubs.php
4-
featureToggles:
5-
listType: true

0 commit comments

Comments
 (0)