mirror of
https://github.com/danog/psalm.git
synced 2024-11-27 04:45:20 +01:00
Merge pull request #9942 from ygottschalk/fix/9886-glob-callmap-stub-crash
Fix glob CallMap and stub to prevent crash on alpine
This commit is contained in:
commit
086b943713
@ -3330,7 +3330,7 @@ return [
|
||||
'gettimeofday' => ['array<string, int>'],
|
||||
'gettimeofday\'1' => ['float', 'as_float='=>'true'],
|
||||
'gettype' => ['string', 'value'=>'mixed'],
|
||||
'glob' => ['false|list{0?:string, ...<non-empty-string>}', 'pattern'=>'string', 'flags='=>'int-mask<GLOB_MARK, GLOB_NOSORT, GLOB_NOCHECK, GLOB_NOESCAPE, GLOB_BRACE, GLOB_ONLYDIR, GLOB_ERR>'],
|
||||
'glob' => ['false|list{0?:string, ...<non-empty-string>}', 'pattern'=>'string', 'flags='=>'int<0, max>'],
|
||||
'GlobIterator::__construct' => ['void', 'pattern'=>'string', 'flags='=>'int'],
|
||||
'GlobIterator::count' => ['int'],
|
||||
'GlobIterator::current' => ['FilesystemIterator|SplFileInfo|string'],
|
||||
|
@ -10764,7 +10764,7 @@ return [
|
||||
'gettimeofday' => ['array<string, int>'],
|
||||
'gettimeofday\'1' => ['float', 'as_float='=>'true'],
|
||||
'gettype' => ['string', 'value'=>'mixed'],
|
||||
'glob' => ['false|list{0?:string, ...<non-empty-string>}', 'pattern'=>'string', 'flags='=>'int-mask<GLOB_MARK, GLOB_NOSORT, GLOB_NOCHECK, GLOB_NOESCAPE, GLOB_BRACE, GLOB_ONLYDIR, GLOB_ERR>'],
|
||||
'glob' => ['false|list{0?:string, ...<non-empty-string>}', 'pattern'=>'string', 'flags='=>'int<0, max>'],
|
||||
'gmdate' => ['string', 'format'=>'string', 'timestamp='=>'int'],
|
||||
'gmmktime' => ['int|false', 'hour='=>'int', 'minute='=>'int', 'second='=>'int', 'month='=>'int', 'day='=>'int', 'year='=>'int'],
|
||||
'gmp_abs' => ['GMP', 'num'=>'GMP|string|int'],
|
||||
|
@ -32,9 +32,12 @@ use Psalm\Internal\Scanner\UnresolvedConstantComponent;
|
||||
use ReflectionClass;
|
||||
use ReflectionFunction;
|
||||
|
||||
use function array_merge;
|
||||
use function array_values;
|
||||
use function assert;
|
||||
use function class_exists;
|
||||
use function function_exists;
|
||||
use function get_defined_constants;
|
||||
use function implode;
|
||||
use function in_array;
|
||||
use function interface_exists;
|
||||
@ -514,6 +517,19 @@ class ExpressionResolver
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($function->name->parts === ['defined']
|
||||
&& isset($function->getArgs()[0])
|
||||
&& $function->getArgs()[0]->value instanceof PhpParser\Node\Scalar\String_
|
||||
) {
|
||||
$predefined_constants = get_defined_constants(true);
|
||||
if (isset($predefined_constants['user'])) {
|
||||
unset($predefined_constants['user']);
|
||||
}
|
||||
$predefined_constants = array_merge(...array_values($predefined_constants));
|
||||
|
||||
return isset($predefined_constants[$function->getArgs()[0]->value->value]);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -1717,31 +1717,57 @@ function pg_escape_literal($string1, $string2 = null) {}
|
||||
*/
|
||||
function pg_escape_string($string1, $string2 = null) {}
|
||||
|
||||
/**
|
||||
* @psalm-template P of string
|
||||
* @psalm-template F of int-mask<GLOB_MARK, GLOB_NOSORT, GLOB_NOCHECK, GLOB_NOESCAPE, GLOB_BRACE, GLOB_ONLYDIR, GLOB_ERR>
|
||||
* @psalm-param P $pattern
|
||||
* @psalm-param F $flags
|
||||
* @psalm-return (
|
||||
* P is ''
|
||||
* ? (F is int-mask<GLOB_MARK, GLOB_NOSORT, GLOB_NOESCAPE, GLOB_BRACE, GLOB_ONLYDIR, GLOB_ERR>
|
||||
* ? false|list<never>
|
||||
* : (F is int-mask<GLOB_MARK, GLOB_NOSORT, GLOB_NOCHECK, GLOB_NOESCAPE, GLOB_BRACE, GLOB_ERR>
|
||||
* ? false|list{0:''}
|
||||
* : false|list<never>
|
||||
* )
|
||||
* )
|
||||
* : (F is int-mask<GLOB_MARK, GLOB_NOSORT, GLOB_NOESCAPE, GLOB_BRACE, GLOB_ONLYDIR, GLOB_ERR>
|
||||
* ? false|list<non-empty-string>
|
||||
* : (F is int-mask<GLOB_MARK, GLOB_NOSORT, GLOB_NOCHECK, GLOB_NOESCAPE, GLOB_BRACE, GLOB_ERR>
|
||||
* ? false|list{0:non-empty-string, ...<non-empty-string>}
|
||||
* : false|list<non-empty-string>
|
||||
* )
|
||||
* )
|
||||
* )
|
||||
* @psalm-ignore-falsable-return
|
||||
*/
|
||||
function glob (string $pattern, int $flags = 0): array|false {}
|
||||
|
||||
|
||||
if (defined('GLOB_BRACE')) {
|
||||
/**
|
||||
* @psalm-template P of string
|
||||
* @psalm-template F of int-mask<GLOB_MARK, GLOB_NOSORT, GLOB_NOCHECK, GLOB_NOESCAPE, GLOB_BRACE, GLOB_ONLYDIR, GLOB_ERR>
|
||||
* @psalm-param P $pattern
|
||||
* @psalm-param F $flags
|
||||
* @psalm-return (
|
||||
* P is ''
|
||||
* ? (F is int-mask<GLOB_MARK, GLOB_NOSORT, GLOB_NOESCAPE, GLOB_BRACE, GLOB_ONLYDIR, GLOB_ERR>
|
||||
* ? false|list<never>
|
||||
* : (F is int-mask<GLOB_MARK, GLOB_NOSORT, GLOB_NOCHECK, GLOB_NOESCAPE, GLOB_BRACE, GLOB_ERR>
|
||||
* ? false|list{0:''}
|
||||
* : false|list<never>
|
||||
* )
|
||||
* )
|
||||
* : (F is int-mask<GLOB_MARK, GLOB_NOSORT, GLOB_NOESCAPE, GLOB_BRACE, GLOB_ONLYDIR, GLOB_ERR>
|
||||
* ? false|list<non-empty-string>
|
||||
* : (F is int-mask<GLOB_MARK, GLOB_NOSORT, GLOB_NOCHECK, GLOB_NOESCAPE, GLOB_BRACE, GLOB_ERR>
|
||||
* ? false|list{0:non-empty-string, ...<non-empty-string>}
|
||||
* : false|list<non-empty-string>
|
||||
* )
|
||||
* )
|
||||
* )
|
||||
* @psalm-ignore-falsable-return
|
||||
*/
|
||||
function glob (string $pattern, int $flags = 0): array|false {}
|
||||
} else {
|
||||
/**
|
||||
* @psalm-template P of string
|
||||
* @psalm-template F of int-mask<GLOB_MARK, GLOB_NOSORT, GLOB_NOCHECK, GLOB_NOESCAPE, GLOB_ONLYDIR, GLOB_ERR>
|
||||
* @psalm-param P $pattern
|
||||
* @psalm-param F $flags
|
||||
* @psalm-return (
|
||||
* P is ''
|
||||
* ? (F is int-mask<GLOB_MARK, GLOB_NOSORT, GLOB_NOESCAPE, GLOB_ONLYDIR, GLOB_ERR>
|
||||
* ? false|list<never>
|
||||
* : (F is int-mask<GLOB_MARK, GLOB_NOSORT, GLOB_NOCHECK, GLOB_NOESCAPE, GLOB_ERR>
|
||||
* ? false|list{0:''}
|
||||
* : false|list<never>
|
||||
* )
|
||||
* )
|
||||
* : (F is int-mask<GLOB_MARK, GLOB_NOSORT, GLOB_NOESCAPE, GLOB_ONLYDIR, GLOB_ERR>
|
||||
* ? false|list<non-empty-string>
|
||||
* : (F is int-mask<GLOB_MARK, GLOB_NOSORT, GLOB_NOCHECK, GLOB_NOESCAPE, GLOB_ERR>
|
||||
* ? false|list{0:non-empty-string, ...<non-empty-string>}
|
||||
* : false|list<non-empty-string>
|
||||
* )
|
||||
* )
|
||||
* )
|
||||
* @psalm-ignore-falsable-return
|
||||
*/
|
||||
function glob (string $pattern, int $flags = 0): array|false {}
|
||||
}
|
||||
|
||||
|
@ -406,6 +406,12 @@ class CoreStubsTest extends TestCase
|
||||
takesList(glob( '' ));
|
||||
PHP,
|
||||
];
|
||||
yield 'glob accepts GLOB_BRACE' => [
|
||||
'code' => <<<'PHP'
|
||||
<?php
|
||||
$globBrace = glob('abc', GLOB_BRACE);
|
||||
PHP,
|
||||
];
|
||||
}
|
||||
|
||||
public function providerInvalidCodeParse(): iterable
|
||||
|
Loading…
Reference in New Issue
Block a user