1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 20:34:47 +01:00

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](ee80567a83/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
This commit is contained in:
Bruce Weirdan 2019-12-28 02:06:09 +02:00 committed by Matthew Brown
parent bdb2f3c2be
commit 4110ec351b
5 changed files with 20 additions and 7 deletions

View File

@ -49,6 +49,7 @@
"prefer-stable": true, "prefer-stable": true,
"require-dev": { "require-dev": {
"phpunit/phpunit": "^7.5 || ^8.0", "phpunit/phpunit": "^7.5 || ^8.0",
"phpspec/prophecy": ">=1.9.0",
"squizlabs/php_codesniffer": "^3.5", "squizlabs/php_codesniffer": "^3.5",
"bamarni/composer-bin-plugin": "^1.2", "bamarni/composer-bin-plugin": "^1.2",
"psalm/plugin-phpunit": "^0.6", "psalm/plugin-phpunit": "^0.6",

View File

@ -1153,7 +1153,7 @@ class ProjectAnalyzer
*/ */
public function setPhpVersion(string $version) 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'); throw new \UnexpectedValueException('Expecting a version number in the format x.y');
} }

View File

@ -4,6 +4,7 @@ namespace Psalm\Internal\Codebase;
use function array_shift; use function array_shift;
use function assert; use function assert;
use function count; use function count;
use function file_exists;
use PhpParser; use PhpParser;
use Psalm\Codebase; use Psalm\Codebase;
use Psalm\Internal\Analyzer\ProjectAnalyzer; use Psalm\Internal\Analyzer\ProjectAnalyzer;
@ -13,6 +14,7 @@ use Psalm\Type;
use Psalm\Type\Atomic\TCallable; use Psalm\Type\Atomic\TCallable;
use function strtolower; use function strtolower;
use function substr; use function substr;
use function version_compare;
/** /**
* @internal * @internal
@ -23,6 +25,7 @@ class CallMap
{ {
const PHP_MAJOR_VERSION = 7; const PHP_MAJOR_VERSION = 7;
const PHP_MINOR_VERSION = 3; const PHP_MINOR_VERSION = 3;
const LOWEST_AVAILABLE_DELTA = 71;
/** /**
* @var ?int * @var ?int
@ -321,6 +324,12 @@ class CallMap
$analyzer_major_version = $codebase->php_major_version; $analyzer_major_version = $codebase->php_major_version;
$analyzer_minor_version = $codebase->php_minor_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 if (self::$call_map !== null
&& $analyzer_major_version === self::$loaded_php_major_version && $analyzer_major_version === self::$loaded_php_major_version
&& $analyzer_minor_version === self::$loaded_php_minor_version && $analyzer_minor_version === self::$loaded_php_minor_version
@ -338,8 +347,13 @@ class CallMap
self::$call_map[$cased_key] = $value; self::$call_map[$cased_key] = $value;
} }
if ($analyzer_minor_version < self::PHP_MINOR_VERSION) { if (version_compare($analyzer_version, $current_version, '<')) {
for ($i = self::PHP_MINOR_VERSION; $i > $analyzer_minor_version; --$i) { // 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{ * @var array{
* old: array<string, array<int|string, string>>, * old: array<string, array<int|string, string>>,
@ -347,7 +361,7 @@ class CallMap
* } * }
* @psalm-suppress UnresolvableInclude * @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 => $_) { foreach ($diff_call_map['new'] as $key => $_) {
$cased_key = strtolower($key); $cased_key = strtolower($key);

View File

@ -181,7 +181,7 @@ return [
], ],
'domdocument' => [ 'domdocument' => [
'actualEncoding' => 'string', 'actualEncoding' => 'string',
'config' => 'DOMConfiguration', 'config' => 'null',
'doctype' => 'DOMDocumentType', 'doctype' => 'DOMDocumentType',
'documentElement' => 'DOMElement', 'documentElement' => 'DOMElement',
'documentURI' => 'string', 'documentURI' => 'string',

View File

@ -1,8 +1,6 @@
<?php <?php
namespace Psalm\Tests\FileManipulation; namespace Psalm\Tests\FileManipulation;
use const PHP_VERSION;
class UnnecessaryVarAnnotationManipulationTest extends FileManipulationTest class UnnecessaryVarAnnotationManipulationTest extends FileManipulationTest
{ {
/** /**