diff --git a/.github/workflows/php-integration-tests.yml b/.github/workflows/php-integration-tests.yml index 338cf1f..3f13a32 100644 --- a/.github/workflows/php-integration-tests.yml +++ b/.github/workflows/php-integration-tests.yml @@ -22,7 +22,7 @@ jobs: strategy: fail-fast: false matrix: - php-service: [ '72', '73', '74', '80', '81', '82' ] + php-service: [ '81', '82' ] steps: - name: Checkout uses: actions/checkout@v3 diff --git a/.github/workflows/php-static-analysis.yml b/.github/workflows/php-static-analysis.yml index dedcd5b..1bed93c 100644 --- a/.github/workflows/php-static-analysis.yml +++ b/.github/workflows/php-static-analysis.yml @@ -31,12 +31,19 @@ jobs: uses: inpsyde/reusable-workflows/.github/workflows/lint-php.yml@main if: ${{ (github.event_name != 'workflow_dispatch') || ((github.event.inputs.jobs == 'Run all') || (github.event.inputs.jobs == 'Run lint only')) }} with: - PHP_MATRIX: '["7.2", "7.3", "7.4", "8.0", "8.1", "8.2"]' + PHP_MATRIX: '["8.1", "8.2"]' coding-standards-analysis-php: if: ${{ (github.event_name != 'workflow_dispatch') || ((github.event.inputs.jobs == 'Run all') || (github.event.inputs.jobs == 'Run PHPCS only')) }} uses: inpsyde/reusable-workflows/.github/workflows/coding-standards-php.yml@main + with: + PHP_VERSION: '8.1' static-code-analysis-php: if: ${{ (github.event_name != 'workflow_dispatch') || ((github.event.inputs.jobs == 'Run all') || (github.event.inputs.jobs == 'Run Psalm only')) }} uses: inpsyde/reusable-workflows/.github/workflows/static-analysis-php.yml@main + strategy: + matrix: + php-version: [ '8.1', '8.2' ] + with: + PHP_VERSION: ${{ matrix.php-version }} diff --git a/.github/workflows/php-unit-tests.yml b/.github/workflows/php-unit-tests.yml index 1953aff..24be9b0 100644 --- a/.github/workflows/php-unit-tests.yml +++ b/.github/workflows/php-unit-tests.yml @@ -25,7 +25,8 @@ jobs: strategy: fail-fast: false matrix: - php-versions: [ '7.2', '7.3', '7.4', '8.0', '8.1', '8.2' ] + php-versions: [ '8.1', '8.2' ] + dependency-versions: ['highest', 'lowest'] steps: - name: Checkout @@ -44,6 +45,8 @@ jobs: - name: Install Composer dependencies uses: ramsey/composer-install@v2 + with: + dependency-versions: ${{ matrix.dependency-versions }} - name: Run unit tests run: composer tests:unit:${{ ((env.USE_COVERAGE == 'yes') && 'codecov') || 'no-cov' }} diff --git a/.gitignore b/.gitignore index a57a787..6c97b07 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,10 @@ # Docker .github/workflows/docker/php*/*.sh + +# Adding a folder to put things temporarily +temp/ + +# IDE +.idea/ + diff --git a/composer.json b/composer.json index 4a5c981..45c9747 100644 --- a/composer.json +++ b/composer.json @@ -37,22 +37,23 @@ } ], "require": { - "php": ">=7.2 < 8.3", - "psr/log": "^1.1.4", + "php": ">=8.1 < 8.3", + "psr/log": "^2.0||^3.0", "wecodemore/wordpress-early-hook": "^1.1.0", "monolog/monolog": "^2.3.5" }, "require-dev": { - "phpunit/phpunit": "^8.5.33", "brain/monkey": "^2.6.1", "mockery/mockery": "^1.3.6", "mikey179/vfsstream": "~v1.6.11", "inpsyde/php-coding-standards": "^1", - "vimeo/psalm": "^4.30.0", "inpsyde/wp-stubs-versions": "dev-latest", "roots/wordpress-no-content": ">=6.1.1", "symfony/process": "^v4.4.44", - "globalis/wp-cli-bin": "^2.7.1" + "globalis/wp-cli-bin": "^2.7.1", + "vimeo/psalm": "^5.15", + "phpunit/phpunit": "^9.6", + "fig/log-test": "^1.1" }, "provide": { "psr/log-implementation": "1.0.0" diff --git a/phpunit.xml.dist b/phpunit.xml.dist index d2d7421..85875ac 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,34 +1,30 @@ - - - - - - - - - tests/unit - - - tests/integration - - - - - - src - - + + + + src + + + + + + + + tests/unit + + + tests/integration + + diff --git a/src/Data/FailedLogin.php b/src/Data/FailedLogin.php index 8daec23..101b4e6 100644 --- a/src/Data/FailedLogin.php +++ b/src/Data/FailedLogin.php @@ -107,15 +107,25 @@ private function countAttempts(int $ttl = 300): void || !isset($attempts[$userIp]['count']) || !isset($attempts[$userIp]['last_logged']) ) { - $attempts[$userIp] = ['count' => 0, 'last_logged' => 0]; + /** + * @var array $data + */ + $data = ['count' => 0, 'last_logged' => 0]; + $attempts[$userIp] = $data; } /** @psalm-suppress MixedOperand */ $attempts[$userIp]['count']++; - /** @psalm-suppress PropertyTypeCoercion */ + /** @psalm-suppress InvalidPropertyAssignmentValue */ $this->attemptsData = $attempts; + /** + * Psalm warns us about count and last_logged possibly being bool to int converted + * We assume the value retrieved when calling get_site_transient is an integer on both + * @psalm-suppress RiskyCast + */ $count = (int)$attempts[$userIp]['count']; + /** @psalm-suppress RiskyCast */ $lastLogged = (int)$attempts[$userIp]['last_logged']; /** diff --git a/src/DefaultHandler/LogsFolder.php b/src/DefaultHandler/LogsFolder.php index ef4736b..0954531 100644 --- a/src/DefaultHandler/LogsFolder.php +++ b/src/DefaultHandler/LogsFolder.php @@ -35,7 +35,11 @@ public static function determineFolder(?string $customFolder = null): ?string * them, and package could be fully functional even if failures happen. * Silence looks like best option here. * + * Also for some reason __return_true seems not to be a valid argument? + * I found this related issue https://github.com/vimeo/psalm/issues/3571 + * * phpcs:disable WordPress.PHP.DevelopmentFunctions.error_log_set_error_handler + * @psalm-suppress PossiblyInvalidArgument */ set_error_handler('__return_true'); diff --git a/src/HookListener/CronDebugListener.php b/src/HookListener/CronDebugListener.php index 7e3d43c..1e17b78 100644 --- a/src/HookListener/CronDebugListener.php +++ b/src/HookListener/CronDebugListener.php @@ -83,7 +83,7 @@ private function registerEventListener(LogActionUpdater $updater): void } $cronArray = _get_cron_array(); - /** @psalm-suppress DocblockTypeContradiction */ + /** @psalm-suppress TypeDoesNotContainType,DocblockTypeContradiction */ if (!$cronArray || !is_array($cronArray)) { return; } diff --git a/src/PsrBridge.php b/src/PsrBridge.php index d2eaf65..182a7fc 100644 --- a/src/PsrBridge.php +++ b/src/PsrBridge.php @@ -72,7 +72,7 @@ public function withDefaultChannel(string $defaultChannel): PsrBridge * * phpcs:disable Generic.Metrics.CyclomaticComplexity */ - public function log($level, $message, array $context = []) + public function log($level, $message, array $context = []): void { // phpcs:enable Generic.Metrics.CyclomaticComplexity $throwable = null; diff --git a/tests/unit/HookListener/CronDebugListenerTest.php b/tests/unit/HookListener/CronDebugListenerTest.php index ae5eebf..0df22a5 100644 --- a/tests/unit/HookListener/CronDebugListenerTest.php +++ b/tests/unit/HookListener/CronDebugListenerTest.php @@ -109,8 +109,8 @@ static function (LogData $log) use (&$logs): void { $regxp = '~^Cron action "%s" performed\. Duration: [0|1]\.[0-9]+ seconds\.$~'; - static::assertRegExp(sprintf($regxp, 'wp_scheduled_delete'), $logs[0]); - static::assertRegExp(sprintf($regxp, 'wp_update_plugins'), $logs[1]); - static::assertRegExp(sprintf($regxp, 'wp_version_check'), $logs[2]); + static::assertMatchesRegularExpression(sprintf($regxp, 'wp_scheduled_delete'), $logs[0]); + static::assertMatchesRegularExpression(sprintf($regxp, 'wp_update_plugins'), $logs[1]); + static::assertMatchesRegularExpression(sprintf($regxp, 'wp_version_check'), $logs[2]); } }