Upgrade PHPStan to version 1.0

[MAILPOET-3932]
This commit is contained in:
Oluwaseun Olorunsola
2022-01-11 15:57:27 +01:00
committed by Veljko V
parent 5e5beb1402
commit 092f6ea9ff
10 changed files with 6022 additions and 71 deletions

View File

@@ -26,7 +26,7 @@ class BatchIterator implements \Iterator, \Countable {
$this->batchSize = (int)$batchSize;
}
public function rewind() {
public function rewind(): void {
$this->lastProcessedId = 0;
}
@@ -44,15 +44,15 @@ class BatchIterator implements \Iterator, \Countable {
return null;
}
public function next() {
public function next(): void {
$this->lastProcessedId = $this->batchLastId;
}
public function valid() {
public function valid(): bool {
return $this->count() > 0;
}
public function count() {
public function count(): int {
return $this->getSubscribers()->count();
}

View File

@@ -1,10 +1,10 @@
{
"require": {
"php-stubs/woocommerce-stubs": "^5.8",
"phpstan/phpstan": "0.12.99",
"phpstan/phpstan-doctrine": "0.12.44",
"phpstan/phpstan-phpunit": "0.12.22",
"szepeviktor/phpstan-wordpress": "^0.7.7"
"phpstan/phpstan": "1.2.0",
"phpstan/phpstan-doctrine": "1.0.2",
"phpstan/phpstan-phpunit": "1.0.0",
"szepeviktor/phpstan-wordpress": "1.0.2"
},
"autoload": {
"psr-4": {
@@ -15,7 +15,14 @@
"sort-packages": true
},
"scripts": {
"post-install-cmd": "php prefix-phpstan-doctrine.php",
"post-update-cmd": "php prefix-phpstan-doctrine.php"
"post-install-cmd": [
"php prefix-phpstan-doctrine.php",
"php fix-WPStubs-for-PHP-8_1.php"
],
"post-update-cmd": [
"php prefix-phpstan-doctrine.php",
"php fix-WPStubs-for-PHP-8_1.php"
]
}
}

View File

@@ -4,20 +4,20 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "d50d0f174a8f5174aae12bf0bf03e954",
"content-hash": "d1001ca07b73790fffa8fd9c59908da8",
"packages": [
{
"name": "php-stubs/woocommerce-stubs",
"version": "v5.8.0",
"version": "v5.9.0",
"source": {
"type": "git",
"url": "https://github.com/php-stubs/woocommerce-stubs.git",
"reference": "e3978c519fb1e51585e8c86b489b802aa0c64cee"
"reference": "a7204cfbb5fa90720773122cb68530087de5bc78"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-stubs/woocommerce-stubs/zipball/e3978c519fb1e51585e8c86b489b802aa0c64cee",
"reference": "e3978c519fb1e51585e8c86b489b802aa0c64cee",
"url": "https://api.github.com/repos/php-stubs/woocommerce-stubs/zipball/a7204cfbb5fa90720773122cb68530087de5bc78",
"reference": "a7204cfbb5fa90720773122cb68530087de5bc78",
"shasum": ""
},
"require": {
@@ -46,22 +46,22 @@
],
"support": {
"issues": "https://github.com/php-stubs/woocommerce-stubs/issues",
"source": "https://github.com/php-stubs/woocommerce-stubs/tree/v5.8.0"
"source": "https://github.com/php-stubs/woocommerce-stubs/tree/v5.9.0"
},
"time": "2021-10-15T14:13:09+00:00"
"time": "2021-11-05T10:02:27+00:00"
},
{
"name": "php-stubs/wordpress-stubs",
"version": "v5.8.1",
"version": "v5.8.2",
"source": {
"type": "git",
"url": "https://github.com/php-stubs/wordpress-stubs.git",
"reference": "8b333464d3183bccde2fdbb814e3cae592434943"
"reference": "67fd773742b7be5b4463f40318b0b4890a07033b"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-stubs/wordpress-stubs/zipball/8b333464d3183bccde2fdbb814e3cae592434943",
"reference": "8b333464d3183bccde2fdbb814e3cae592434943",
"url": "https://api.github.com/repos/php-stubs/wordpress-stubs/zipball/67fd773742b7be5b4463f40318b0b4890a07033b",
"reference": "67fd773742b7be5b4463f40318b0b4890a07033b",
"shasum": ""
},
"replace": {
@@ -90,22 +90,22 @@
],
"support": {
"issues": "https://github.com/php-stubs/wordpress-stubs/issues",
"source": "https://github.com/php-stubs/wordpress-stubs/tree/v5.8.1"
"source": "https://github.com/php-stubs/wordpress-stubs/tree/v5.8.2"
},
"time": "2021-09-09T22:10:19+00:00"
"time": "2021-11-11T13:57:00+00:00"
},
{
"name": "phpstan/phpstan",
"version": "0.12.99",
"version": "1.2.0",
"source": {
"type": "git",
"url": "https://github.com/phpstan/phpstan.git",
"reference": "b4d40f1d759942f523be267a1bab6884f46ca3f7"
"reference": "cbe085f9fdead5b6d62e4c022ca52dc9427a10ee"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpstan/phpstan/zipball/b4d40f1d759942f523be267a1bab6884f46ca3f7",
"reference": "b4d40f1d759942f523be267a1bab6884f46ca3f7",
"url": "https://api.github.com/repos/phpstan/phpstan/zipball/cbe085f9fdead5b6d62e4c022ca52dc9427a10ee",
"reference": "cbe085f9fdead5b6d62e4c022ca52dc9427a10ee",
"shasum": ""
},
"require": {
@@ -121,7 +121,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "0.12-dev"
"dev-master": "1.2-dev"
}
},
"autoload": {
@@ -136,7 +136,7 @@
"description": "PHPStan - PHP Static Analysis Tool",
"support": {
"issues": "https://github.com/phpstan/phpstan/issues",
"source": "https://github.com/phpstan/phpstan/tree/0.12.99"
"source": "https://github.com/phpstan/phpstan/tree/1.2.0"
},
"funding": [
{
@@ -156,25 +156,25 @@
"type": "tidelift"
}
],
"time": "2021-09-12T20:09:55+00:00"
"time": "2021-11-18T14:09:01+00:00"
},
{
"name": "phpstan/phpstan-doctrine",
"version": "0.12.44",
"version": "1.0.2",
"source": {
"type": "git",
"url": "https://github.com/phpstan/phpstan-doctrine.git",
"reference": "5fe9a9b15707d9bc5178fa7cf0899e904d112ccd"
"reference": "8805ca71119c736606be39ad6284a0cfddb89127"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpstan/phpstan-doctrine/zipball/5fe9a9b15707d9bc5178fa7cf0899e904d112ccd",
"reference": "5fe9a9b15707d9bc5178fa7cf0899e904d112ccd",
"url": "https://api.github.com/repos/phpstan/phpstan-doctrine/zipball/8805ca71119c736606be39ad6284a0cfddb89127",
"reference": "8805ca71119c736606be39ad6284a0cfddb89127",
"shasum": ""
},
"require": {
"php": "^7.1 || ^8.0",
"phpstan/phpstan": "^0.12.85"
"phpstan/phpstan": "^1.0"
},
"conflict": {
"doctrine/collections": "<1.0",
@@ -192,16 +192,17 @@
"doctrine/orm": "^2.9.1",
"doctrine/persistence": "^1.1 || ^2.0",
"nesbot/carbon": "^2.49",
"nikic/php-parser": "^4.13.0",
"php-parallel-lint/php-parallel-lint": "^1.2",
"phpstan/phpstan-phpunit": "^0.12.16",
"phpstan/phpstan-strict-rules": "^0.12.5",
"phpstan/phpstan-phpunit": "^1.0",
"phpstan/phpstan-strict-rules": "^1.0",
"phpunit/phpunit": "^9.5",
"ramsey/uuid-doctrine": "^1.5.0"
},
"type": "phpstan-extension",
"extra": {
"branch-alias": {
"dev-master": "0.12-dev"
"dev-master": "1.0-dev"
},
"phpstan": {
"includes": [
@@ -222,40 +223,41 @@
"description": "Doctrine extensions for PHPStan",
"support": {
"issues": "https://github.com/phpstan/phpstan-doctrine/issues",
"source": "https://github.com/phpstan/phpstan-doctrine/tree/0.12.44"
"source": "https://github.com/phpstan/phpstan-doctrine/tree/1.0.2"
},
"time": "2021-09-01T06:46:16+00:00"
"time": "2021-11-24T08:26:25+00:00"
},
{
"name": "phpstan/phpstan-phpunit",
"version": "0.12.22",
"version": "1.0.0",
"source": {
"type": "git",
"url": "https://github.com/phpstan/phpstan-phpunit.git",
"reference": "7c01ef93bf128b4ac8bdad38c54b2a4fd6b0b3cc"
"reference": "9eb88c9f689003a8a2a5ae9e010338ee94dc39b3"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpstan/phpstan-phpunit/zipball/7c01ef93bf128b4ac8bdad38c54b2a4fd6b0b3cc",
"reference": "7c01ef93bf128b4ac8bdad38c54b2a4fd6b0b3cc",
"url": "https://api.github.com/repos/phpstan/phpstan-phpunit/zipball/9eb88c9f689003a8a2a5ae9e010338ee94dc39b3",
"reference": "9eb88c9f689003a8a2a5ae9e010338ee94dc39b3",
"shasum": ""
},
"require": {
"php": "^7.1 || ^8.0",
"phpstan/phpstan": "^0.12.92"
"phpstan/phpstan": "^1.0"
},
"conflict": {
"phpunit/phpunit": "<7.0"
},
"require-dev": {
"nikic/php-parser": "^4.13.0",
"php-parallel-lint/php-parallel-lint": "^1.2",
"phpstan/phpstan-strict-rules": "^0.12.6",
"phpstan/phpstan-strict-rules": "^1.0",
"phpunit/phpunit": "^9.5"
},
"type": "phpstan-extension",
"extra": {
"branch-alias": {
"dev-master": "0.12-dev"
"dev-master": "1.0-dev"
},
"phpstan": {
"includes": [
@@ -276,22 +278,22 @@
"description": "PHPUnit extensions and rules for PHPStan",
"support": {
"issues": "https://github.com/phpstan/phpstan-phpunit/issues",
"source": "https://github.com/phpstan/phpstan-phpunit/tree/0.12.22"
"source": "https://github.com/phpstan/phpstan-phpunit/tree/1.0.0"
},
"time": "2021-08-12T10:53:43+00:00"
"time": "2021-10-14T08:03:54+00:00"
},
{
"name": "symfony/polyfill-php73",
"version": "v1.23.0",
"version": "v1.24.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-php73.git",
"reference": "fba8933c384d6476ab14fb7b8526e5287ca7e010"
"reference": "cc5db0e22b3cb4111010e48785a97f670b350ca5"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-php73/zipball/fba8933c384d6476ab14fb7b8526e5287ca7e010",
"reference": "fba8933c384d6476ab14fb7b8526e5287ca7e010",
"url": "https://api.github.com/repos/symfony/polyfill-php73/zipball/cc5db0e22b3cb4111010e48785a97f670b350ca5",
"reference": "cc5db0e22b3cb4111010e48785a97f670b350ca5",
"shasum": ""
},
"require": {
@@ -341,7 +343,7 @@
"shim"
],
"support": {
"source": "https://github.com/symfony/polyfill-php73/tree/v1.23.0"
"source": "https://github.com/symfony/polyfill-php73/tree/v1.24.0"
},
"funding": [
{
@@ -357,33 +359,34 @@
"type": "tidelift"
}
],
"time": "2021-02-19T12:13:01+00:00"
"time": "2021-06-05T21:20:04+00:00"
},
{
"name": "szepeviktor/phpstan-wordpress",
"version": "v0.7.7",
"version": "v1.0.2",
"source": {
"type": "git",
"url": "https://github.com/szepeviktor/phpstan-wordpress.git",
"reference": "bdbea69b2ba4a69998c3b6fe2b7106d78a23bd72"
"reference": "d44b5abcaa529698e138b2d21bc2a7cf9834039c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/szepeviktor/phpstan-wordpress/zipball/bdbea69b2ba4a69998c3b6fe2b7106d78a23bd72",
"reference": "bdbea69b2ba4a69998c3b6fe2b7106d78a23bd72",
"url": "https://api.github.com/repos/szepeviktor/phpstan-wordpress/zipball/d44b5abcaa529698e138b2d21bc2a7cf9834039c",
"reference": "d44b5abcaa529698e138b2d21bc2a7cf9834039c",
"shasum": ""
},
"require": {
"php": "^7.1 || ^8.0",
"php-stubs/wordpress-stubs": "^4.7 || ^5.0",
"phpstan/phpstan": "^0.12.26",
"phpstan/phpstan": "^1.0",
"symfony/polyfill-php73": "^1.12.0"
},
"require-dev": {
"composer/composer": "^1.10.22",
"composer/composer": "^1.10.23",
"dealerdirect/phpcodesniffer-composer-installer": "^0.7",
"php-parallel-lint/php-parallel-lint": "^1.1",
"phpstan/phpstan-strict-rules": "^0.12",
"phpstan/phpstan-strict-rules": "^1.0",
"phpunit/phpunit": "^7 || ^9",
"szepeviktor/phpcs-psr-12-neutron-hybrid-ruleset": "^0.6"
},
"type": "phpstan-extension",
@@ -413,7 +416,7 @@
],
"support": {
"issues": "https://github.com/szepeviktor/phpstan-wordpress/issues",
"source": "https://github.com/szepeviktor/phpstan-wordpress/tree/v0.7.7"
"source": "https://github.com/szepeviktor/phpstan-wordpress/tree/v1.0.2"
},
"funding": [
{
@@ -421,7 +424,7 @@
"type": "custom"
}
],
"time": "2021-07-14T09:19:15+00:00"
"time": "2021-11-19T12:47:11+00:00"
}
],
"packages-dev": [],

View File

@@ -0,0 +1,21 @@
<?php
// throw exception if anything fails
set_error_handler(function ($severity, $message, $file, $line) {
throw new ErrorException($message, 0, $severity, $file, $line);
});
$file = 'vendor/php-stubs/wordpress-stubs/wordpress-stubs.php';
$data = file_get_contents($file);
$search_term = 'function readonly';
if (! strpos($data, $search_term)) {
return;
}
// "readonly" is a reserved keyword in PHP 8.1,
// WP has a "function readonly", hence, we need to replace readonly with __readonly for the stub
$data = str_replace($search_term, 'function __readonly', $data);
file_put_contents($file, $data);

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,20 @@
<?php
declare(strict_types = 1);
$config = [];
$phpVersion = (int)getenv('ANALYSIS_PHP_VERSION') ?: PHP_VERSION_ID;
$config['parameters']['phpVersion'] = $phpVersion;
# PHPStan allows us to declare the currently reported list of errors as “the baseline” and cause it not being reported in subsequent runs.
# PHPStan will throw violations only in new and changed code.
# read more here: https://phpstan.org/user-guide/baseline
# we need to load different baseline file based on the php version
if ($phpVersion == 80100) {
$config['includes'][] = 'phpstan-8.1-baseline.neon';
} elseif ($phpVersion == 70100 || $phpVersion < 80000) {
$config['includes'][] = 'phpstan-7-baseline.neon';
} else {
$config['includes'][] = 'phpstan-8-baseline.neon';
}
return $config;

View File

@@ -1,5 +1,5 @@
parameters:
level: 8
level: 9
tmpDir: ../../temp/phpstan
bootstrapFiles:
- ../../vendor/autoload.php
@@ -30,7 +30,8 @@ parameters:
- '#Function members_register_.+ not found#'
- '#Call to an undefined method MailPoetVendor\\Idiorm\\IdiormResultSet::set\(\)#'
- '#Argument of an invalid type MailPoetVendor\\pQuery\\IQuery supplied for foreach, only iterables are supported#'
- '/(with|has) no (return )?typehint specified/' # exclude level 6 errors
- '/has no (return )?type specified/' # exclude level 6 errors
- '/has parameter (\$[_A-Z]{1}[_a-z]+)? with no type (specified)?/i' # exclude level 6 errors
- # Primary keys ScheduledTaskSubscriberEntity of are foreign keys and foreign keys may be null because of missing related record
message: '#Property MailPoet\\Entities\\[a-zA-Z]+::\$[a-z]+ type mapping mismatch: property can contain MailPoet\\Entities\\[a-zA-Z]+\|null but database expects MailPoet\\Entities\\[a-zA-Z]+.#'
path: ../../lib/Entities/ScheduledTaskSubscriberEntity.php
@@ -47,10 +48,12 @@ parameters:
# exclude level 6 errors
checkMissingIterableValueType: false
excludes_analyse:
excludePaths:
analyseAndScan:
- ../../lib/Config/PopulatorData/Templates # analysis of templates is extremely slow, let's skip them for now
- ../../tests/_support/_generated
- ../../tests/unit/Entities/SubscriberEntityTest.php
- vendor/php-stubs/wordpress-stubs/wordpress-stubs.php # does not yet offer support for PHP 8.1
includes:
- extensions/CodeceptionExtension/extension.neon
- vendor/phpstan/phpstan-doctrine/extension.neon
@@ -58,3 +61,4 @@ includes:
- vendor/phpstan/phpstan-doctrine/rules.neon
- vendor/szepeviktor/phpstan-wordpress/extension.neon
- php-version-dependent-config.php # PHP version detection + configuraton dependent on PHP version
- phpstan-baseline-fix-lib.php # include baseline files

View File

@@ -13,7 +13,7 @@ foreach ($files as $file) {
// when string 'Doctrine' is prefixed by a whitespace, ', ", or ( plus zero or more \, and suffixed by
// one or more \, prefix it with 'MailPoetDoctrine' + the number of trailing \ in the original string
$data = preg_replace('/([\'"\s(]\\\\*)(Doctrine)(\\\\+)/', '$1MailPoetVendor$3$2$3', $data);
$data = preg_replace('/([\'"\s(?]\\\\*)(Doctrine)(\\\\+)/', '$1MailPoetVendor$3$2$3', $data);
file_put_contents($file, $data);
}
}