From 4110ec351bf6d8d30c8cf89a44f03daddcb5ac50 Mon Sep 17 00:00:00 2001 From: Bruce Weirdan Date: Sat, 28 Dec 2019 02:06:09 +0200 Subject: [PATCH] Make travis green again (#2518) * Bumped phpspec/prophecy version to prevent 7.4 deprecations * Fix DOMDocument::$config type This property was documented as containing DOMConfiguration object, but in fact always returned `null` (see [php source](https://github.com/php/php-src/blame/ee80567a83b5092b48b5ef00a16cdb73db4ef25a/ext/dom/document.c#L542)). DOMConfiguration class is removed in PHP 8. * Dropped unused use * Allow to set PHP 8.0 as current version * Fix CallMap issues for PHP 8.0 - Use both major and minor version to load deltas - Don't load non-existent deltas - Stop at lowest possible delta --- composer.json | 1 + .../Internal/Analyzer/ProjectAnalyzer.php | 2 +- src/Psalm/Internal/Codebase/CallMap.php | 20 ++++++++++++++++--- src/Psalm/Internal/PropertyMap.php | 2 +- ...necessaryVarAnnotationManipulationTest.php | 2 -- 5 files changed, 20 insertions(+), 7 deletions(-) diff --git a/composer.json b/composer.json index 9f48a2dc2..ede7b37f9 100644 --- a/composer.json +++ b/composer.json @@ -49,6 +49,7 @@ "prefer-stable": true, "require-dev": { "phpunit/phpunit": "^7.5 || ^8.0", + "phpspec/prophecy": ">=1.9.0", "squizlabs/php_codesniffer": "^3.5", "bamarni/composer-bin-plugin": "^1.2", "psalm/plugin-phpunit": "^0.6", diff --git a/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php b/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php index f44ab86de..ee00dde79 100644 --- a/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php @@ -1153,7 +1153,7 @@ class ProjectAnalyzer */ public function setPhpVersion(string $version) { - if (!preg_match('/^(5\.[456]|7\.[01234])(\..*)?$/', $version)) { + if (!preg_match('/^(5\.[456]|7\.[01234]|8\.[0])(\..*)?$/', $version)) { throw new \UnexpectedValueException('Expecting a version number in the format x.y'); } diff --git a/src/Psalm/Internal/Codebase/CallMap.php b/src/Psalm/Internal/Codebase/CallMap.php index 598f411c5..65535821e 100644 --- a/src/Psalm/Internal/Codebase/CallMap.php +++ b/src/Psalm/Internal/Codebase/CallMap.php @@ -4,6 +4,7 @@ namespace Psalm\Internal\Codebase; use function array_shift; use function assert; use function count; +use function file_exists; use PhpParser; use Psalm\Codebase; use Psalm\Internal\Analyzer\ProjectAnalyzer; @@ -13,6 +14,7 @@ use Psalm\Type; use Psalm\Type\Atomic\TCallable; use function strtolower; use function substr; +use function version_compare; /** * @internal @@ -23,6 +25,7 @@ class CallMap { const PHP_MAJOR_VERSION = 7; const PHP_MINOR_VERSION = 3; + const LOWEST_AVAILABLE_DELTA = 71; /** * @var ?int @@ -321,6 +324,12 @@ class CallMap $analyzer_major_version = $codebase->php_major_version; $analyzer_minor_version = $codebase->php_minor_version; + $analyzer_version = $analyzer_major_version . '.' . $analyzer_minor_version; + $current_version = self::PHP_MAJOR_VERSION . '.' . self::PHP_MINOR_VERSION; + + $analyzer_version_int = (int) ($analyzer_major_version . $analyzer_minor_version); + $current_version_int = (int) (self::PHP_MAJOR_VERSION . self::PHP_MINOR_VERSION); + if (self::$call_map !== null && $analyzer_major_version === self::$loaded_php_major_version && $analyzer_minor_version === self::$loaded_php_minor_version @@ -338,8 +347,13 @@ class CallMap self::$call_map[$cased_key] = $value; } - if ($analyzer_minor_version < self::PHP_MINOR_VERSION) { - for ($i = self::PHP_MINOR_VERSION; $i > $analyzer_minor_version; --$i) { + if (version_compare($analyzer_version, $current_version, '<')) { + // the following assumes both minor and major versions a single digits + for ($i = $current_version_int; $i > $analyzer_version_int && $i >= self::LOWEST_AVAILABLE_DELTA; --$i) { + $delta_file = __DIR__ . '/../CallMap_' . $i . '_delta.php'; + if (!file_exists($delta_file)) { + continue; + } /** * @var array{ * old: array>, @@ -347,7 +361,7 @@ class CallMap * } * @psalm-suppress UnresolvableInclude */ - $diff_call_map = require(__DIR__ . '/../CallMap_7' . $i . '_delta.php'); + $diff_call_map = require($delta_file); foreach ($diff_call_map['new'] as $key => $_) { $cased_key = strtolower($key); diff --git a/src/Psalm/Internal/PropertyMap.php b/src/Psalm/Internal/PropertyMap.php index 81eba5835..7ad2a483e 100644 --- a/src/Psalm/Internal/PropertyMap.php +++ b/src/Psalm/Internal/PropertyMap.php @@ -181,7 +181,7 @@ return [ ], 'domdocument' => [ 'actualEncoding' => 'string', - 'config' => 'DOMConfiguration', + 'config' => 'null', 'doctype' => 'DOMDocumentType', 'documentElement' => 'DOMElement', 'documentURI' => 'string', diff --git a/tests/FileManipulation/UnnecessaryVarAnnotationManipulationTest.php b/tests/FileManipulation/UnnecessaryVarAnnotationManipulationTest.php index a44841d43..980be036a 100644 --- a/tests/FileManipulation/UnnecessaryVarAnnotationManipulationTest.php +++ b/tests/FileManipulation/UnnecessaryVarAnnotationManipulationTest.php @@ -1,8 +1,6 @@