Skip to content
Permalink
Browse files

Fix #2352 - treat hexdec return type a bit better

  • Loading branch information
muglug committed Dec 27, 2019
1 parent 4a28525 commit 9a04d93cf9cda85efc8780ca29fc3b180cb702d5
@@ -56,6 +56,7 @@ public function __construct()
$this->registerClass(ReturnTypeProvider\GetObjectVarsReturnTypeProvider::class);
$this->registerClass(ReturnTypeProvider\GetClassMethodsReturnTypeProvider::class);
$this->registerClass(ReturnTypeProvider\FirstArgStringReturnTypeProvider::class);
$this->registerClass(ReturnTypeProvider\HexdecReturnTypeProvider::class);
}

/**
@@ -0,0 +1,44 @@
<?php
namespace Psalm\Internal\Provider\ReturnTypeProvider;

use function array_map;
use function count;
use function explode;
use function in_array;
use PhpParser;
use Psalm\CodeLocation;
use Psalm\Context;
use Psalm\Internal\Analyzer\Statements\Expression\CallAnalyzer;
use Psalm\Internal\Analyzer\Statements\ExpressionAnalyzer;
use Psalm\Internal\Codebase\CallMap;
use Psalm\Internal\Type\ArrayType;
use Psalm\StatementsSource;
use Psalm\Type;
use function strpos;
use function strtolower;

class HexdecReturnTypeProvider implements \Psalm\Plugin\Hook\FunctionReturnTypeProviderInterface
{
public static function getFunctionIds() : array
{
return ['hexdec'];
}

/**
* @param array<PhpParser\Node\Arg> $call_args
* @param CodeLocation $code_location
*/
public static function getFunctionReturnType(
StatementsSource $statements_source,
string $function_id,
array $call_args,
Context $context,
CodeLocation $code_location
) : Type\Union {
if (!$statements_source instanceof \Psalm\Internal\Analyzer\StatementsAnalyzer) {
return Type::getMixed();
}

return Type::getInt(true);
}
}

0 comments on commit 9a04d93

Please sign in to comment.
You can’t perform that action at this time.