From 8f8c1af790395a07eb46016ec20f20485bc42c66 Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Wed, 5 Jul 2023 14:09:55 +0200 Subject: [PATCH] Register `json_validate` stub only on PHP 8.3+ --- conf/config.neon | 6 ++++- src/Php/PhpVersion.php | 5 ++++ src/PhpDoc/JsonValidateStubFilesExtension.php | 23 +++++++++++++++++++ stubs/{json.stub => json_validate.stub} | 0 4 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 src/PhpDoc/JsonValidateStubFilesExtension.php rename stubs/{json.stub => json_validate.stub} (100%) diff --git a/conf/config.neon b/conf/config.neon index 78f3011ec4..1d26e086bb 100644 --- a/conf/config.neon +++ b/conf/config.neon @@ -166,7 +166,6 @@ parameters: - ../stubs/arrayFunctions.stub - ../stubs/core.stub - ../stubs/typeCheckingFunctions.stub - - ../stubs/json.stub earlyTerminatingMethodCalls: [] earlyTerminatingFunctionCalls: [] memoryLimitFile: %tmpDir%/.memory_limit @@ -630,6 +629,11 @@ services: autowired: - PHPStan\PhpDoc\StubFilesProvider + - + class: PHPStan\PhpDoc\JsonValidateStubFilesExtension + tags: + - phpstan.stubFilesExtension + - class: PHPStan\Analyser\Analyser arguments: diff --git a/src/Php/PhpVersion.php b/src/Php/PhpVersion.php index ca921fddb9..aeb9fc0d2b 100644 --- a/src/Php/PhpVersion.php +++ b/src/Php/PhpVersion.php @@ -227,4 +227,9 @@ public function supportsCallableInstanceMethods(): bool return $this->versionId < 80000; } + public function supportsJsonValidate(): bool + { + return $this->versionId >= 80300; + } + } diff --git a/src/PhpDoc/JsonValidateStubFilesExtension.php b/src/PhpDoc/JsonValidateStubFilesExtension.php new file mode 100644 index 0000000000..19c1f824d0 --- /dev/null +++ b/src/PhpDoc/JsonValidateStubFilesExtension.php @@ -0,0 +1,23 @@ +phpVersion->supportsJsonValidate()) { + return []; + } + + return [__DIR__ . '/../../stubs/json_validate.stub']; + } + +} diff --git a/stubs/json.stub b/stubs/json_validate.stub similarity index 100% rename from stubs/json.stub rename to stubs/json_validate.stub