1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-22 05:41:20 +01:00

use int|string in phpdoc format for array-key (#4645)

This commit is contained in:
orklah 2020-11-21 23:38:40 +01:00 committed by Daniil Gentili
parent f9edf5d7e1
commit 58ddeaafdf
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
3 changed files with 32 additions and 2 deletions

View File

@ -30,4 +30,16 @@ class TArrayKey extends Scalar
{
return false;
}
/**
* @param array<string> $aliased_classes
*/
public function toNamespacedString(
?string $namespace,
array $aliased_classes,
?string $this_class,
bool $use_phpdoc_format
): string {
return $use_phpdoc_format ? '(int|string)' : 'array-key';
}
}

View File

@ -67,8 +67,7 @@ class TTemplateKeyOf extends TArrayKey
}
/**
* @param array<string> $aliased_classes
*
* @param array<string> $aliased_classes
*/
public function toNamespacedString(
?string $namespace,

View File

@ -965,6 +965,25 @@ class MissingReturnTypeTest extends FileManipulationTest
false,
true,
],
'arrayKeyReturn' => [
'<?php
function scope(array $array) {
return (array_keys($array))[0] ?? null;
}',
'<?php
/**
* @return (int|string)|null
*
* @psalm-return array-key|null
*/
function scope(array $array) {
return (array_keys($array))[0] ?? null;
}',
'7.1',
['MissingReturnType'],
false,
true,
],
];
}
}