mirror of
https://github.com/danog/psalm.git
synced 2025-01-21 21:31:13 +01:00
Add support for numeric type
This commit is contained in:
parent
00a6a54cf5
commit
c7dc5dd9f9
@ -1672,7 +1672,7 @@ class StatementsChecker
|
||||
if (!$return_type->isMixed()) {
|
||||
|
||||
foreach ($return_type->types as &$type) {
|
||||
if ($type->isScalar()) {
|
||||
if ($type->isScalarType()) {
|
||||
if (IssueBuffer::accepts(
|
||||
new InvalidArrayAssignment('Cannot assign value on variable $' . $var_id . ' of scalar type ' . $type->value, $this->_file_name, $stmt->getLine())
|
||||
)) {
|
||||
@ -2686,8 +2686,12 @@ class StatementsChecker
|
||||
$type_match_found = true;
|
||||
}
|
||||
|
||||
if ($input_type_part->isScalar()) {
|
||||
if ($param_type_part->isScalar()) {
|
||||
if ($param_type_part->isNumeric() && $input_type_part->isNumericType()) {
|
||||
$type_match_found = true;
|
||||
}
|
||||
|
||||
if ($input_type_part->isScalarType()) {
|
||||
if ($param_type_part->isScalarType()) {
|
||||
$scalar_type_match_found = true;
|
||||
}
|
||||
}
|
||||
|
@ -131,7 +131,7 @@ abstract class Type
|
||||
|
||||
public static function fixScalarTerms($type_string)
|
||||
{
|
||||
if (in_array(strtolower($type_string), ['numeric', 'int', 'float', 'string', 'bool', 'true', 'false', 'null', 'array', 'object', 'mixed'])) {
|
||||
if (in_array(strtolower($type_string), ['numeric', 'int', 'float', 'string', 'bool', 'true', 'false', 'null', 'array', 'object', 'mixed', 'resource'])) {
|
||||
return strtolower($type_string);
|
||||
}
|
||||
elseif ($type_string === 'boolean') {
|
||||
@ -395,6 +395,17 @@ abstract class Type
|
||||
}
|
||||
}
|
||||
|
||||
public function isNumeric()
|
||||
{
|
||||
if ($this instanceof Atomic) {
|
||||
return $this->value === 'numeric';
|
||||
}
|
||||
|
||||
if ($this instanceof Union) {
|
||||
return isset($this->types['numeric']);
|
||||
}
|
||||
}
|
||||
|
||||
public function isEmpty()
|
||||
{
|
||||
return $this->value === 'empty';
|
||||
@ -439,7 +450,7 @@ abstract class Type
|
||||
return $this instanceof Generic;
|
||||
}
|
||||
|
||||
public function isScalar()
|
||||
public function isScalarType()
|
||||
{
|
||||
if ($this instanceof Atomic) {
|
||||
return $this->value === 'int' ||
|
||||
@ -453,6 +464,17 @@ abstract class Type
|
||||
return false;
|
||||
}
|
||||
|
||||
public function isNumericType()
|
||||
{
|
||||
if ($this instanceof Atomic) {
|
||||
return $this->value === 'int' ||
|
||||
$this->value === 'double' ||
|
||||
$this->value === 'float';
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Combines two union types into one
|
||||
* @param Union $type_1
|
||||
|
Loading…
x
Reference in New Issue
Block a user