From 19c26f726387d171adfe2379e15a4e3036401e52 Mon Sep 17 00:00:00 2001 From: Dawid 'DeyV' Polak Date: Wed, 29 Dec 2021 16:17:56 +0100 Subject: [PATCH 1/4] Move from deprecated Composer 1 to Composer 2 runtime api --- composer.json | 4 ++-- psalm.xml.dist | 1 - src/Psalm/Internal/Cli/Plugin.php | 4 ++-- src/Psalm/Internal/CliUtils.php | 7 +++---- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/composer.json b/composer.json index ef2f427692b..94bb0c5eff9 100644 --- a/composer.json +++ b/composer.json @@ -22,9 +22,9 @@ "ext-libxml": "*", "ext-mbstring": "*", "ext-tokenizer": "*", + "composer-runtime-api": "^2.0.0", "amphp/amp": "^2.4.2", "amphp/byte-stream": "^1.5", - "composer/package-versions-deprecated": "^1.8.0", "composer/semver": "^1.4 || ^2.0 || ^3.0", "composer/xdebug-handler": "^1.1 || ^2.0 || ^3.0", "dnoegel/php-xdg-base-dir": "^0.1.1", @@ -49,7 +49,7 @@ "phpmyadmin/sql-parser": "5.1.0||dev-master", "phpspec/prophecy": ">=1.9.0", "phpunit/phpunit": "^9.0", - "psalm/plugin-phpunit": "^0.16", + "psalm/plugin-phpunit": "^0.16.1", "slevomat/coding-standard": "^7.0", "squizlabs/php_codesniffer": "^3.5", "symfony/process": "^4.3 || ^5.0 || ^6.0", diff --git a/psalm.xml.dist b/psalm.xml.dist index 135cadc6691..cfc85255e5f 100644 --- a/psalm.xml.dist +++ b/psalm.xml.dist @@ -58,7 +58,6 @@ - diff --git a/src/Psalm/Internal/Cli/Plugin.php b/src/Psalm/Internal/Cli/Plugin.php index 3e180d5af6d..b853af016e4 100644 --- a/src/Psalm/Internal/Cli/Plugin.php +++ b/src/Psalm/Internal/Cli/Plugin.php @@ -2,7 +2,7 @@ namespace Psalm\Internal\Cli; -use PackageVersions\Versions; +use Composer\InstalledVersions; use Psalm\Internal\CliUtils; use Psalm\Internal\PluginManager\Command\DisableCommand; use Psalm\Internal\PluginManager\Command\EnableCommand; @@ -29,7 +29,7 @@ public static function run(): void $vendor_dir = CliUtils::getVendorDir($current_dir); CliUtils::requireAutoloaders($current_dir, false, $vendor_dir); - $app = new Application('psalm-plugin', Versions::getVersion('vimeo/psalm')); + $app = new Application('psalm-plugin', InstalledVersions::getVersion('vimeo/psalm') ?? 'UNKNOWN'); $psalm_root = dirname(__DIR__, 4) . DIRECTORY_SEPARATOR; diff --git a/src/Psalm/Internal/CliUtils.php b/src/Psalm/Internal/CliUtils.php index 810a8581a13..baafae45c1e 100644 --- a/src/Psalm/Internal/CliUtils.php +++ b/src/Psalm/Internal/CliUtils.php @@ -3,14 +3,13 @@ namespace Psalm\Internal; use Composer\Autoload\ClassLoader; -use PackageVersions\Versions; +use Composer\InstalledVersions; use Phar; use Psalm\Config; use Psalm\Config\Creator; use Psalm\Exception\ConfigException; use Psalm\Exception\ConfigNotFoundException; use Psalm\Internal\Analyzer\ProjectAnalyzer; -use Psalm\Internal\Composer; use Psalm\Report; use function array_slice; @@ -147,8 +146,8 @@ public static function requireAutoloaders( exit(1); } - define('PSALM_VERSION', Versions::getVersion('vimeo/psalm')); - define('PHP_PARSER_VERSION', Versions::getVersion('nikic/php-parser')); + define('PSALM_VERSION', InstalledVersions::getVersion('vimeo/psalm')); + define('PHP_PARSER_VERSION', InstalledVersions::getVersion('nikic/php-parser')); return $first_autoloader; } From 43dea65b889c77c7dcfb65bd2cd0dccfb828b47d Mon Sep 17 00:00:00 2001 From: Dawid 'DeyV' Polak Date: Fri, 31 Dec 2021 14:47:11 +0100 Subject: [PATCH 2/4] Fixing bug *\Composer\InstalledVersions in builded phar --- scoper.inc.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/scoper.inc.php b/scoper.inc.php index 6dee3af89c1..b726189806d 100644 --- a/scoper.inc.php +++ b/scoper.inc.php @@ -27,6 +27,13 @@ function ($filePath, $prefix, $contents) { $contents ); }, + function ($filePath, $prefix, $contents) { + return str_replace( + '\\'.$prefix.'\Composer\InstalledVersions', + '\Composer\InstalledVersions', + $contents + ); + }, function ($filePath, $prefix, $contents) { if (strpos($filePath, 'src/Psalm') === 0) { return str_replace( From d43f2beed8cbcae1fc7fda8ff1f76af3eff1fa6f Mon Sep 17 00:00:00 2001 From: Dawid 'DeyV' Polak Date: Fri, 31 Dec 2021 15:15:04 +0100 Subject: [PATCH 3/4] Fixed problems with test-with-real-projects --- src/Psalm/Internal/Cli/Plugin.php | 8 +++++++- src/Psalm/Internal/CliUtils.php | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Psalm/Internal/Cli/Plugin.php b/src/Psalm/Internal/Cli/Plugin.php index b853af016e4..2524b0d196e 100644 --- a/src/Psalm/Internal/Cli/Plugin.php +++ b/src/Psalm/Internal/Cli/Plugin.php @@ -3,6 +3,7 @@ namespace Psalm\Internal\Cli; use Composer\InstalledVersions; +use OutOfBoundsException; use Psalm\Internal\CliUtils; use Psalm\Internal\PluginManager\Command\DisableCommand; use Psalm\Internal\PluginManager\Command\EnableCommand; @@ -29,7 +30,12 @@ public static function run(): void $vendor_dir = CliUtils::getVendorDir($current_dir); CliUtils::requireAutoloaders($current_dir, false, $vendor_dir); - $app = new Application('psalm-plugin', InstalledVersions::getVersion('vimeo/psalm') ?? 'UNKNOWN'); + try { + $version = InstalledVersions::getVersion('vimeo/psalm') ; + } catch (OutOfBoundsException $e) { + } + + $app = new Application('psalm-plugin', $version ?? 'UNKNOWN'); $psalm_root = dirname(__DIR__, 4) . DIRECTORY_SEPARATOR; diff --git a/src/Psalm/Internal/CliUtils.php b/src/Psalm/Internal/CliUtils.php index baafae45c1e..23903cf47eb 100644 --- a/src/Psalm/Internal/CliUtils.php +++ b/src/Psalm/Internal/CliUtils.php @@ -4,6 +4,7 @@ use Composer\Autoload\ClassLoader; use Composer\InstalledVersions; +use OutOfBoundsException; use Phar; use Psalm\Config; use Psalm\Config\Creator; @@ -146,7 +147,12 @@ public static function requireAutoloaders( exit(1); } - define('PSALM_VERSION', InstalledVersions::getVersion('vimeo/psalm')); + try { + $version = InstalledVersions::getVersion('vimeo/psalm') ; + } catch (OutOfBoundsException $e) { + } + + define('PSALM_VERSION', $version ?? 'UNKNOWN'); define('PHP_PARSER_VERSION', InstalledVersions::getVersion('nikic/php-parser')); return $first_autoloader; From 7172f4bdbefbc55bdd4332c8d1e83f0c766bcec9 Mon Sep 17 00:00:00 2001 From: Dawid 'DeyV' Polak Date: Sun, 2 Jan 2022 18:13:02 +0100 Subject: [PATCH 4/4] missing default value for $version --- src/Psalm/Internal/Cli/Plugin.php | 1 + src/Psalm/Internal/CliUtils.php | 1 + 2 files changed, 2 insertions(+) diff --git a/src/Psalm/Internal/Cli/Plugin.php b/src/Psalm/Internal/Cli/Plugin.php index 2524b0d196e..9fa4ee6ce4d 100644 --- a/src/Psalm/Internal/Cli/Plugin.php +++ b/src/Psalm/Internal/Cli/Plugin.php @@ -30,6 +30,7 @@ public static function run(): void $vendor_dir = CliUtils::getVendorDir($current_dir); CliUtils::requireAutoloaders($current_dir, false, $vendor_dir); + $version = null; try { $version = InstalledVersions::getVersion('vimeo/psalm') ; } catch (OutOfBoundsException $e) { diff --git a/src/Psalm/Internal/CliUtils.php b/src/Psalm/Internal/CliUtils.php index 23903cf47eb..05b537ce7db 100644 --- a/src/Psalm/Internal/CliUtils.php +++ b/src/Psalm/Internal/CliUtils.php @@ -147,6 +147,7 @@ public static function requireAutoloaders( exit(1); } + $version = null; try { $version = InstalledVersions::getVersion('vimeo/psalm') ; } catch (OutOfBoundsException $e) {