1
0
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:
Brown 2020-05-10 23:58:51 -04:00
parent 8f2f2617d4
commit eefd2e743b
4 changed files with 11 additions and 36 deletions

View File

@ -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()) {

View File

@ -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);
}
/**

View File

@ -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(),
]);
}
}

View File

@ -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) {}