diff --git a/src/CodeInspector/StatementsChecker.php b/src/CodeInspector/StatementsChecker.php index b5c32b8a8..5447bd812 100644 --- a/src/CodeInspector/StatementsChecker.php +++ b/src/CodeInspector/StatementsChecker.php @@ -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; } } diff --git a/src/CodeInspector/Type.php b/src/CodeInspector/Type.php index e3fa86e09..a944c4606 100644 --- a/src/CodeInspector/Type.php +++ b/src/CodeInspector/Type.php @@ -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