mirror of
https://github.com/danog/psalm.git
synced 2025-01-21 21:31:13 +01:00
Use generic function definition for sscanf
cc @villfa
This commit is contained in:
parent
8f2f2617d4
commit
eefd2e743b
@ -1754,6 +1754,10 @@ class CallAnalyzer
|
||||
|
||||
if (isset($function_storage->param_out_types[$argument_offset])) {
|
||||
$by_ref_out_type = $function_storage->param_out_types[$argument_offset];
|
||||
} elseif ($argument_offset >= count($function_params)
|
||||
&& isset($function_storage->param_out_types[count($function_params) - 1])
|
||||
) {
|
||||
$by_ref_out_type = $function_storage->param_out_types[count($function_params) - 1];
|
||||
}
|
||||
|
||||
if ($by_ref_type && $by_ref_type->isNullable()) {
|
||||
|
@ -57,7 +57,6 @@ class FunctionReturnTypeProvider
|
||||
$this->registerClass(ReturnTypeProvider\GetClassMethodsReturnTypeProvider::class);
|
||||
$this->registerClass(ReturnTypeProvider\FirstArgStringReturnTypeProvider::class);
|
||||
$this->registerClass(ReturnTypeProvider\HexdecReturnTypeProvider::class);
|
||||
$this->registerClass(ReturnTypeProvider\SScanFReturnTypeProvider::class);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,35 +0,0 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Psalm\Internal\Provider\ReturnTypeProvider;
|
||||
|
||||
use function count;
|
||||
use Psalm\CodeLocation;
|
||||
use Psalm\Context;
|
||||
use Psalm\StatementsSource;
|
||||
use Psalm\Type;
|
||||
|
||||
class SScanFReturnTypeProvider implements \Psalm\Plugin\Hook\FunctionReturnTypeProviderInterface
|
||||
{
|
||||
public static function getFunctionIds(): array
|
||||
{
|
||||
return ['sscanf'];
|
||||
}
|
||||
|
||||
public static function getFunctionReturnType(
|
||||
StatementsSource $statements_source,
|
||||
string $function_id,
|
||||
array $call_args,
|
||||
Context $context,
|
||||
CodeLocation $code_location
|
||||
) : Type\Union {
|
||||
if (count($call_args) === 2) {
|
||||
return new Type\Union([
|
||||
new Type\Atomic\TList(Type::parseString('float|int|string')),
|
||||
]);
|
||||
}
|
||||
|
||||
return new Type\Union([
|
||||
new Type\Atomic\TInt(),
|
||||
]);
|
||||
}
|
||||
}
|
@ -406,3 +406,10 @@ function range($start, $end, $step = 1) {}
|
||||
* )
|
||||
*/
|
||||
function date(string $format, int $timestamp = 0) {}
|
||||
|
||||
/**
|
||||
* @param mixed $vars
|
||||
* @param-out string|int|float $vars
|
||||
* @return (func_num_args() is 2 ? list<float|int|string> : int)
|
||||
*/
|
||||
function sscanf(string $str, string $format, &...$vars) {}
|
||||
|
Loading…
x
Reference in New Issue
Block a user