Skip to content

Commit 8f8c1af

Browse files
committed
Register json_validate stub only on PHP 8.3+
1 parent 1ece38f commit 8f8c1af

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed

conf/config.neon

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,6 @@ parameters:
166166
- ../stubs/arrayFunctions.stub
167167
- ../stubs/core.stub
168168
- ../stubs/typeCheckingFunctions.stub
169-
- ../stubs/json.stub
170169
earlyTerminatingMethodCalls: []
171170
earlyTerminatingFunctionCalls: []
172171
memoryLimitFile: %tmpDir%/.memory_limit
@@ -630,6 +629,11 @@ services:
630629
autowired:
631630
- PHPStan\PhpDoc\StubFilesProvider
632631

632+
-
633+
class: PHPStan\PhpDoc\JsonValidateStubFilesExtension
634+
tags:
635+
- phpstan.stubFilesExtension
636+
633637
-
634638
class: PHPStan\Analyser\Analyser
635639
arguments:

src/Php/PhpVersion.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,4 +227,9 @@ public function supportsCallableInstanceMethods(): bool
227227
return $this->versionId < 80000;
228228
}
229229

230+
public function supportsJsonValidate(): bool
231+
{
232+
return $this->versionId >= 80300;
233+
}
234+
230235
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PHPStan\PhpDoc;
4+
5+
use PHPStan\Php\PhpVersion;
6+
7+
class JsonValidateStubFilesExtension implements StubFilesExtension
8+
{
9+
10+
public function __construct(private PhpVersion $phpVersion)
11+
{
12+
}
13+
14+
public function getFiles(): array
15+
{
16+
if (!$this->phpVersion->supportsJsonValidate()) {
17+
return [];
18+
}
19+
20+
return [__DIR__ . '/../../stubs/json_validate.stub'];
21+
}
22+
23+
}
File renamed without changes.

0 commit comments

Comments
 (0)