Skip to content
Permalink
Browse files

Allow numeric to go into string|int|float

  • Loading branch information...
muglug committed Apr 11, 2019
1 parent 97f53a6 commit cadee4d9886457008ade0feff0df1ec79cb1ddba
Showing with 25 additions and 0 deletions.
  1. +9 −0 src/Psalm/Internal/Analyzer/TypeAnalyzer.php
  2. +16 −0 tests/TypeReconciliationTest.php
@@ -133,6 +133,15 @@ public static function isContainedBy(
$type_coerced_from_scalar
);
if ($input_type_part instanceof TNumeric
&& $container_type->hasString()
&& $container_type->hasInt()
&& $container_type->hasFloat()
) {
$scalar_type_match_found = false;
$is_atomic_contained_by = true;
}
if ($is_atomic_contained_by) {
$type_match_found = true;
}
@@ -1293,6 +1293,22 @@ function example(array $x): void {}
example($x);
}',
],
'allowNumericToFoldIntoType' => [
'<?php
/**
* @param mixed $width
* @param mixed $height
*
* @throws RuntimeException
*/
function Foo($width, $height) : void {
if (!is_numeric($width) || !is_numeric($height)) {
throw new RuntimeException("Width & Height were not numeric!");
}
echo sprintf("padding-top:%s%%;", 100 * ($height/$width));
}'
],
];
}

0 comments on commit cadee4d

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