Skip to content

Commit

Permalink
Register json_validate stub only on PHP 8.3+
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Jul 5, 2023
1 parent 1ece38f commit 8f8c1af
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
6 changes: 5 additions & 1 deletion conf/config.neon
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ parameters:
- ../stubs/arrayFunctions.stub
- ../stubs/core.stub
- ../stubs/typeCheckingFunctions.stub
- ../stubs/json.stub
earlyTerminatingMethodCalls: []
earlyTerminatingFunctionCalls: []
memoryLimitFile: %tmpDir%/.memory_limit
Expand Down Expand Up @@ -630,6 +629,11 @@ services:
autowired:
- PHPStan\PhpDoc\StubFilesProvider

-
class: PHPStan\PhpDoc\JsonValidateStubFilesExtension
tags:
- phpstan.stubFilesExtension

-
class: PHPStan\Analyser\Analyser
arguments:
Expand Down
5 changes: 5 additions & 0 deletions src/Php/PhpVersion.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,4 +227,9 @@ public function supportsCallableInstanceMethods(): bool
return $this->versionId < 80000;
}

public function supportsJsonValidate(): bool
{
return $this->versionId >= 80300;
}

}
23 changes: 23 additions & 0 deletions src/PhpDoc/JsonValidateStubFilesExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php declare(strict_types = 1);

namespace PHPStan\PhpDoc;

use PHPStan\Php\PhpVersion;

class JsonValidateStubFilesExtension implements StubFilesExtension
{

public function __construct(private PhpVersion $phpVersion)
{
}

public function getFiles(): array
{
if (!$this->phpVersion->supportsJsonValidate()) {
return [];
}

return [__DIR__ . '/../../stubs/json_validate.stub'];
}

}
File renamed without changes.

0 comments on commit 8f8c1af

Please sign in to comment.