From 3b895b6987786e1ec4258e4788ecb13f48179bb5 Mon Sep 17 00:00:00 2001 From: Giovanni Giacobbi Date: Tue, 23 Jul 2024 11:22:58 +0200 Subject: [PATCH] Refactor function signature map files loading --- .../FunctionSignatureMapProvider.php | 70 ++++++------------- 1 file changed, 22 insertions(+), 48 deletions(-) diff --git a/src/Reflection/SignatureMap/FunctionSignatureMapProvider.php b/src/Reflection/SignatureMap/FunctionSignatureMapProvider.php index f76acfc34f..8d882ebae7 100644 --- a/src/Reflection/SignatureMap/FunctionSignatureMapProvider.php +++ b/src/Reflection/SignatureMap/FunctionSignatureMapProvider.php @@ -184,80 +184,54 @@ 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); + $signatureMap = $this->computeSignatureMapFile($signatureMap, 'functionMap_bleedingEdge.php'); } if ($this->phpVersion->getVersionId() >= 70400) { - $php74MapDelta = require __DIR__ . '/../../../resources/functionMap_php74delta.php'; - if (!is_array($php74MapDelta)) { - throw new ShouldNotHappenException('Signature map could not be loaded.'); - } - - $signatureMap = $this->computeSignatureMap($signatureMap, $php74MapDelta); + $signatureMap = $this->computeSignatureMapFile($signatureMap, 'functionMap_php74delta.php'); } if ($this->phpVersion->getVersionId() >= 80000) { - $php80MapDelta = require __DIR__ . '/../../../resources/functionMap_php80delta.php'; - if (!is_array($php80MapDelta)) { - throw new ShouldNotHappenException('Signature map could not be loaded.'); - } - - $signatureMap = $this->computeSignatureMap($signatureMap, $php80MapDelta); + $signatureMap = $this->computeSignatureMapFile($signatureMap, 'functionMap_php80delta.php'); if ($this->stricterFunctionMap) { - $php80StricterFunctionMapDelta = require __DIR__ . '/../../../resources/functionMap_php80delta_bleedingEdge.php'; - if (!is_array($php80StricterFunctionMapDelta)) { - throw new ShouldNotHappenException('Signature map could not be loaded.'); - } - - $signatureMap = $this->computeSignatureMap($signatureMap, $php80StricterFunctionMapDelta); + $signatureMap = $this->computeSignatureMapFile($signatureMap, 'functionMap_php80delta_bleedingEdge.php'); } } if ($this->phpVersion->getVersionId() >= 80100) { - $php81MapDelta = require __DIR__ . '/../../../resources/functionMap_php81delta.php'; - if (!is_array($php81MapDelta)) { - throw new ShouldNotHappenException('Signature map could not be loaded.'); - } - - $signatureMap = $this->computeSignatureMap($signatureMap, $php81MapDelta); + $signatureMap = $this->computeSignatureMapFile($signatureMap, 'functionMap_php81delta.php'); } if ($this->phpVersion->getVersionId() >= 80200) { - $php82MapDelta = require __DIR__ . '/../../../resources/functionMap_php82delta.php'; - if (!is_array($php82MapDelta)) { - throw new ShouldNotHappenException('Signature map could not be loaded.'); - } - - $signatureMap = $this->computeSignatureMap($signatureMap, $php82MapDelta); + $signatureMap = $this->computeSignatureMapFile($signatureMap, 'functionMap_php82delta.php'); } if ($this->phpVersion->getVersionId() >= 80300) { - $php83MapDelta = require __DIR__ . '/../../../resources/functionMap_php83delta.php'; - if (!is_array($php83MapDelta)) { - throw new ShouldNotHappenException('Signature map could not be loaded.'); - } - - $signatureMap = $this->computeSignatureMap($signatureMap, $php83MapDelta); + $signatureMap = $this->computeSignatureMapFile($signatureMap, 'functionMap_php83delta.php'); } if ($this->phpVersion->getVersionId() >= 80400) { - $php84MapDelta = require __DIR__ . '/../../../resources/functionMap_php84delta.php'; - if (!is_array($php84MapDelta)) { - throw new ShouldNotHappenException('Signature map could not be loaded.'); - } - - $signatureMap = $this->computeSignatureMap($signatureMap, $php84MapDelta); + $signatureMap = $this->computeSignatureMapFile($signatureMap, 'functionMap_php84delta.php'); } return self::$signatureMaps[$cacheKey] = $signatureMap; } + /** + * @param array $signatureMap + * @return array + */ + private function computeSignatureMapFile(array $signatureMap, string $file): array + { + $signatureMapDelta = include __DIR__ . '/../../../resources/' . $file; + if (!is_array($signatureMapDelta)) { + throw new ShouldNotHappenException(sprintf('Signature map file "%s" could not be loaded.', $file)); + } + + return $this->computeSignatureMap($signatureMap, $signatureMapDelta); + } + /** * @param array $signatureMap * @param array> $delta