1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Small fixes

This commit is contained in:
Daniil Gentili 2021-11-11 12:05:03 +01:00
parent 9dd8533806
commit 575fd1c55a
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
3 changed files with 7 additions and 4 deletions

View File

@ -5980,7 +5980,7 @@ return [
'ImagickPixel::clear' => ['bool'],
'ImagickPixel::clone' => ['void'],
'ImagickPixel::destroy' => ['bool'],
'ImagickPixel::getColor' => ['array{r: int|float, g: int|float, b: int|float, a: int|float}', 'normalized='=>'int'],
'ImagickPixel::getColor' => ['array{r: int|float, g: int|float, b: int|float, a: int|float}', 'normalized='=>'0|1|2'],
'ImagickPixel::getColorAsString' => ['string'],
'ImagickPixel::getColorCount' => ['int'],
'ImagickPixel::getColorQuantum' => ['mixed'],

View File

@ -3161,7 +3161,7 @@ return [
'ImagickPixel::clear' => ['bool'],
'ImagickPixel::clone' => ['void'],
'ImagickPixel::destroy' => ['bool'],
'ImagickPixel::getColor' => ['array{r: int|float, g: int|float, b: int|float, a: int|float}', 'normalized='=>'int'],
'ImagickPixel::getColor' => ['array{r: int|float, g: int|float, b: int|float, a: int|float}', 'normalized='=>'0|1|2'],
'ImagickPixel::getColorAsString' => ['string'],
'ImagickPixel::getColorCount' => ['int'],
'ImagickPixel::getColorQuantum' => ['mixed'],

View File

@ -8,6 +8,8 @@ use Psalm\Type\Atomic\TKeyedArray;
use Psalm\Type\Atomic\TLiteralInt;
use Psalm\Type\Union;
use function in_array;
class ImagickPixelColorReturnTypeProvider implements \Psalm\Plugin\EventHandler\MethodReturnTypeProviderInterface
{
public static function getClassLikeNames() : array
@ -32,10 +34,10 @@ class ImagickPixelColorReturnTypeProvider implements \Psalm\Plugin\EventHandler\
if (!$call_args) {
$formats = [0 => true];
} else {
$normalized = $source->node_data->getType($call_args[0]->value);
$normalized = $source->node_data->getType($call_args[0]->value) ?? Type::getMixed();
$formats = [];
foreach ($normalized->getAtomicTypes() as $t) {
if ($t instanceof TLiteralInt) {
if ($t instanceof TLiteralInt && in_array($t->value, [0, 1, 2], true)) {
$formats[$t->value] = true;
} else {
$formats[0] = true;
@ -76,6 +78,7 @@ class ImagickPixelColorReturnTypeProvider implements \Psalm\Plugin\EventHandler\
]);
}
/** @var non-empty-list<Psalm\Type\Union> $types */
return Type::combineUnionTypeArray($types, $event->getSource()->getCodebase());
}
}