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

Add a bunch of necessary fixes to get phar scoping working on PHP 7.4

This commit is contained in:
Matthew Brown 2022-03-07 16:06:38 -05:00
parent 50565c658a
commit 4311386122
3 changed files with 46 additions and 18 deletions

View File

@ -1,6 +1,27 @@
<?php
use Composer\Autoload\ClassLoader;
use Isolated\Symfony\Component\Finder\Finder;
$polyfillsBootstraps = array_map(
static fn (SplFileInfo $fileInfo) => $fileInfo->getPathname(),
iterator_to_array(
Finder::create()
->files()
->in(__DIR__ . '/vendor/symfony/polyfill-*')
->name('bootstrap*.php'),
false,
),
);
$polyfillsStubs = array_map(
static fn (SplFileInfo $fileInfo) => $fileInfo->getPathname(),
iterator_to_array(
Finder::create()
->files()
->in(__DIR__ . '/vendor/symfony/polyfill-*/Resources/stubs')
->name('*.php'),
false,
),
);
return [
'patchers' => [
@ -49,17 +70,6 @@ return [
return $contents;
},
function ($filePath, $prefix, $contents) {
if (strpos($filePath, 'vendor/symfony/polyfill') === 0) {
return str_replace(
$prefix . '\\Stringable',
'Stringable',
$contents
);
}
return $contents;
},
function ($filePath, $prefix, $contents) {
if ($filePath === 'src/Psalm/Internal/Cli/Psalm.php') {
return str_replace(
@ -80,11 +90,26 @@ return [
return $ret;
},
],
'whitelist' => [
ClassLoader::class,
'Psalm\*',
'exclude-namespaces' => [
'Symfony\Polyfill',
'Psalm',
],
'files-whitelist' => [
'exclude-constants' => [
// Symfony global constants
// TODO: switch to the following regex once regexes are supported here
// https://github.com/humbug/php-scoper/issues/634
'/^SYMFONY\_[\p{L}_]+$/',
// Meanwhile:
'SYMFONY_GRAPHEME_CLUSTER_RX',
'PSALM_VERSION',
'PHP_PARSER_VERSION',
],
'exclude-files' => [
'src/spl_object_id.php',
...$polyfillsBootstraps,
...$polyfillsStubs,
],
'expose-classes' => [
\Composer\Autoload\ClassLoader::class,
],
];

View File

@ -67,7 +67,10 @@ final class CliUtils
if ($in_phar) {
// require this before anything else
require_once __DIR__ . '/../../../vendor/symfony/polyfill-php80/Resources/stubs/Stringable.php';
$stringable_path = __DIR__ . '/../../../vendor/symfony/polyfill-php80/Resources/stubs/Stringable.php';
if (\file_exists($stringable_path)) {
require_once $stringable_path;
}
require_once __DIR__ . '/../../../vendor/autoload.php';
// hack required for JsonMapper

View File

@ -2,7 +2,7 @@
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"humbug/box": "3.10.*"
"humbug/box": "3.16.*"
},
"config": {
"allow-plugins": {