Skip to content

Commit

Permalink
Bleeding edge - stricter functionMap
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Apr 5, 2023
1 parent 711c66b commit 06b746d
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 1 deletion.
1 change: 1 addition & 0 deletions conf/bleedingEdge.neon
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ parameters:
strictStaticMethodTemplateTypeVariance: true
propertyVariance: true
genericPrototypeMessage: true
stricterFunctionMap: true
4 changes: 4 additions & 0 deletions conf/config.neon
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ parameters:
strictStaticMethodTemplateTypeVariance: false
propertyVariance: false
genericPrototypeMessage: false
stricterFunctionMap: false
fileExtensions:
- php
checkAdvancedIsset: false
Expand Down Expand Up @@ -302,6 +303,7 @@ parametersSchema:
strictStaticMethodTemplateTypeVariance: bool()
propertyVariance: bool()
genericPrototypeMessage: bool()
stricterFunctionMap: bool()
])
fileExtensions: listOf(string())
checkAdvancedIsset: bool()
Expand Down Expand Up @@ -936,6 +938,8 @@ services:

-
class: PHPStan\Reflection\SignatureMap\FunctionSignatureMapProvider
arguments:
stricterFunctionMap: %featureToggles.stricterFunctionMap%
autowired:
- PHPStan\Reflection\SignatureMap\FunctionSignatureMapProvider

Expand Down
10 changes: 10 additions & 0 deletions resources/functionMap_bleedingEdge.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php // phpcs:ignoreFile

return [
'new' => [

],
'old' => [

]
];
10 changes: 10 additions & 0 deletions src/Reflection/SignatureMap/FunctionSignatureMapProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public function __construct(
private SignatureMapParser $parser,
private InitializerExprTypeResolver $initializerExprTypeResolver,
private PhpVersion $phpVersion,
private bool $stricterFunctionMap,
)
{
}
Expand Down Expand Up @@ -178,6 +179,15 @@ public function getSignatureMap(): array

$signatureMap = array_change_key_case($signatureMap, CASE_LOWER);

if ($this->stricterFunctionMap) {
$stricterFunctionMap = require __DIR__ . '/../../../resources/functionMap_bleedingEdge.php';
if (!is_array($stricterFunctionMap)) {
throw new ShouldNotHappenException('Signature map could not be loaded.');
}

$signatureMap = $this->computeSignatureMap($signatureMap, $stricterFunctionMap);
}

if ($this->phpVersion->getVersionId() >= 70400) {
$php74MapDelta = require __DIR__ . '/../../../resources/functionMap_php74delta.php';
if (!is_array($php74MapDelta)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ private function createProvider(): Php8SignatureMapProvider
self::getContainer()->getByType(SignatureMapParser::class),
self::getContainer()->getByType(InitializerExprTypeResolver::class),
$phpVersion,
true,
),
self::getContainer()->getByType(FileNodesFetcher::class),
self::getContainer()->getByType(FileTypeMapper::class),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ public function dataParseAll(): array
public function testParseAll(int $phpVersionId): void
{
$parser = self::getContainer()->getByType(SignatureMapParser::class);
$provider = new FunctionSignatureMapProvider($parser, self::getContainer()->getByType(InitializerExprTypeResolver::class), new PhpVersion($phpVersionId));
$provider = new FunctionSignatureMapProvider($parser, self::getContainer()->getByType(InitializerExprTypeResolver::class), new PhpVersion($phpVersionId), true);
$signatureMap = $provider->getSignatureMap();
$reflector = self::getContainer()->getByType(Reflector::class);

Expand Down

0 comments on commit 06b746d

Please sign in to comment.