Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade PHPStan to v2 #274

Merged
merged 16 commits into from
Feb 12, 2025
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"nikic/php-parser": "^4.13",
"php-stubs/generator": "^0.8.3",
"phpdocumentor/reflection-docblock": "^5.4.1",
"phpstan/phpstan": "^1.11",
"phpstan/phpstan": "^2.1",
"phpunit/phpunit": "^9.5",
"szepeviktor/phpcs-psr-12-neutron-hybrid-ruleset": "^1.1.1",
"wp-coding-standards/wpcs": "3.1.0 as 2.3.0"
Expand Down
11 changes: 8 additions & 3 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ parameters:
- tests/
excludePaths:
- tests/data/
phpVersion:
min: 80000
max: 80300
level: 9
featureToggles:
alwaysTrueAlwaysReported: true
listType: true
ignoreErrors:
-
path: tests/Faker.php
identifier: class.notFound
count: 8
4 changes: 3 additions & 1 deletion tests/Faker.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,10 @@ public static function list($type = null): array
* @template T
* @param T ...$types
* @return T
*
* @phpcs:disable NeutronStandard.Functions.TypeHint
*/
public static function union(...$types): mixed
public static function union(...$types)
{
return $types[0];
}
Expand Down
6 changes: 3 additions & 3 deletions tests/data/Faker.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
assertType('non-empty-string', Faker::nonEmptyString());

// Arrays with default values
assertType('array', Faker::array());
assertType('array<mixed>', Faker::array());
assertType('array<int, mixed>', Faker::intArray());
assertType('array<string, mixed>', Faker::strArray());
assertType('list<mixed>', Faker::list());
Expand All @@ -44,8 +44,8 @@
assertType('array<int, int>|bool|int|string', Faker::union(Faker::bool(), Faker::int(), Faker::string(), Faker::intArray(Faker::int())));
assertType('array<int|string, int|string>', Faker::union(Faker::intArray(Faker::int()), Faker::strArray(Faker::string())));
assertType('array<int|string>', Faker::union(Faker::array(Faker::int()), Faker::strArray(Faker::string())));
assertType('array', Faker::union(Faker::array(), Faker::strArray()));
assertType('array', Faker::union(Faker::array(), Faker::intArray()));
assertType('array<mixed>', Faker::union(Faker::array(), Faker::strArray()));
assertType('array<mixed>', Faker::union(Faker::array(), Faker::intArray()));
assertType('string|null', Faker::union(Faker::string(), null));

// Other
Expand Down
2 changes: 1 addition & 1 deletion tests/data/_wp_json_sanity_check.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
assertType('bool', _wp_json_sanity_check(Faker::bool(), 1));
assertType('int', _wp_json_sanity_check(Faker::int(), 1));
assertType('string', _wp_json_sanity_check(Faker::string(), 1));
assertType('array', _wp_json_sanity_check(Faker::array(), 1));
assertType('array<mixed>', _wp_json_sanity_check(Faker::array(), 1));
assertType('stdClass', _wp_json_sanity_check(Faker::stdClass(), 1));
assertType('mixed', _wp_json_sanity_check(Faker::mixed(), 1));
4 changes: 2 additions & 2 deletions tests/data/stripslashes.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
assertType('int', stripslashes_deep(Faker::int()));
assertType('float', stripslashes_deep(Faker::float()));
assertType('string', stripslashes_deep(Faker::string()));
assertType('array', stripslashes_deep(Faker::array()));
assertType('array<mixed>', stripslashes_deep(Faker::array()));
assertType('resource', stripslashes_deep(Faker::resource()));
assertType('object', stripslashes_deep(Faker::object()));

Expand All @@ -22,6 +22,6 @@
assertType('int', stripslashes_from_strings_only(Faker::int()));
assertType('float', stripslashes_from_strings_only(Faker::float()));
assertType('string', stripslashes_from_strings_only(Faker::string()));
assertType('array', stripslashes_from_strings_only(Faker::array()));
assertType('array<mixed>', stripslashes_from_strings_only(Faker::array()));
assertType('resource', stripslashes_from_strings_only(Faker::resource()));
assertType('object', stripslashes_from_strings_only(Faker::object()));
4 changes: 2 additions & 2 deletions tests/data/wpdb.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
// wpdb::get_row()
assertType('stdClass|null', wpdb::get_row());
assertType('stdClass|null', wpdb::get_row(null, 'OBJECT'));
assertType('array|null', wpdb::get_row(null, 'ARRAY_A'));
assertType('array<mixed>|null', wpdb::get_row(null, 'ARRAY_A'));
assertType('list<mixed>|null', wpdb::get_row(null, 'ARRAY_N'));

// wpdb::get_results()
assertType('list<array>|null', wpdb::get_results(null, 'ARRAY_A'));
assertType('list<array<mixed>>|null', wpdb::get_results(null, 'ARRAY_A'));
assertType('list<array<int, mixed>>|null', wpdb::get_results(null, 'ARRAY_N'));
assertType('list<stdClass>|null', wpdb::get_results());
assertType('list<stdClass>|null', wpdb::get_results(null, 'OBJECT'));
Expand Down
2 changes: 0 additions & 2 deletions tests/phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
parameters:
bootstrapFiles:
- ../wordpress-stubs.php
featureToggles:
listType: true