Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move from deprecated Composer 1 to Composer 2 runtime api #7239

Merged
merged 4 commits into from Jan 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions composer.json
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
1 change: 0 additions & 1 deletion psalm.xml.dist
Expand Up @@ -58,7 +58,6 @@
</DeprecatedMethod>
<DeprecatedClass>
<errorLevel type="suppress">
<referencedClass name="PackageVersions\Versions"/>
<referencedClass name="Psalm\Plugin\Hook\*" />
</errorLevel>
</DeprecatedClass>
Expand Down
7 changes: 7 additions & 0 deletions scoper.inc.php
Expand Up @@ -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(
Expand Down
11 changes: 9 additions & 2 deletions src/Psalm/Internal/Cli/Plugin.php
Expand Up @@ -2,7 +2,8 @@

namespace Psalm\Internal\Cli;

use PackageVersions\Versions;
use Composer\InstalledVersions;
use OutOfBoundsException;
use Psalm\Internal\CliUtils;
use Psalm\Internal\PluginManager\Command\DisableCommand;
use Psalm\Internal\PluginManager\Command\EnableCommand;
Expand All @@ -29,7 +30,13 @@ 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'));
$version = null;
try {
$version = InstalledVersions::getVersion('vimeo/psalm') ;
} catch (OutOfBoundsException $e) {
}

$app = new Application('psalm-plugin', $version ?? 'UNKNOWN');

$psalm_root = dirname(__DIR__, 4) . DIRECTORY_SEPARATOR;

Expand Down
14 changes: 10 additions & 4 deletions src/Psalm/Internal/CliUtils.php
Expand Up @@ -3,14 +3,14 @@
namespace Psalm\Internal;

use Composer\Autoload\ClassLoader;
use PackageVersions\Versions;
use Composer\InstalledVersions;
use OutOfBoundsException;
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;
Expand Down Expand Up @@ -147,8 +147,14 @@ public static function requireAutoloaders(
exit(1);
}

define('PSALM_VERSION', Versions::getVersion('vimeo/psalm'));
define('PHP_PARSER_VERSION', Versions::getVersion('nikic/php-parser'));
$version = null;
try {
DeyV marked this conversation as resolved.
Show resolved Hide resolved
$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;
}
Expand Down