Skip to content

Commit

Permalink
Update the requirement checker PHP-Scoper configuration (#426)
Browse files Browse the repository at this point in the history
Closes #421
  • Loading branch information
theofidry authored Jun 5, 2019
1 parent 6f8b747 commit d134334
Showing 1 changed file with 4 additions and 31 deletions.
35 changes: 4 additions & 31 deletions requirement-checker/scoper.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,48 +71,21 @@ function get_prefix(): string
'prefix' => get_prefix(),

'whitelist-global-classes' => false,
'whitelist-global-constants' => false,
'whitelist-global-functions' => false,
'whitelist' => [
\Composer\Semver\Semver::class,
],

'patchers' => [
// `stream_isatty()` is a PHP 7.2 function hence not defined in PHP 7.1. Unlike its function call, the string
// in `function_exists()` is prefixed because the name can be resolved to a FQCN and appears as a user-land
// function.
//
// Function whitelisting is not used here since most checks are in the form of:
//
// ```
// if (function_exists('stream_isatty') return @stream_isatty($stream);
// ```
//
// If the function is simply whitelisted, then it will check if the function `Humbug\stream_isatty` exists which
// it will always even though the underlying function may not exists.
//
// The following patcher can be safely removed however once https://github.com/humbug/php-scoper/issues/278 is
// fixed.
//
// TODO: report back the missing sapi_windows_vt100_support to JetBrains stubs
static function (string $filePath, string $prefix, string $contents): string {
$files = [
'vendor/symfony/console/Output/StreamOutput.php',
'vendor/symfony/phpunit-bridge/DeprecationErrorHandler.php',
'vendor/symfony/polyfill-php72/bootstrap.php',
'vendor/symfony/polyfill-php72/Php72.php',
'vendor/symfony/var-dumper/Dumper/CliDumper.php',
'vendor/composer/xdebug-handler/src/Process.php',
'vendor/sebastian/environment/src/Console.php',
'src/IO.php',
];

if (false === in_array($filePath, $files, true)) {
return $contents;
}

$contents = preg_replace(
'/function_exists\(\''.$prefix.'\\\\(\\\\)?stream_isatty\'\)/',
"function_exists('stream_isatty')",
$contents
);

$contents = preg_replace(
'/function_exists\(\''.$prefix.'\\\\(\\\\)?sapi_windows_vt100_support\'\)/',
"function_exists('sapi_windows_vt100_support')",
Expand Down

0 comments on commit d134334

Please sign in to comment.