mirror of
https://github.com/danog/psalm.git
synced 2025-01-21 21:31:13 +01:00
Revert changes to Type.php
This commit is contained in:
parent
5ff6f27178
commit
c54850aa5b
@ -45,6 +45,10 @@ abstract class Type
|
||||
// remove all unacceptable characters
|
||||
$type_string = preg_replace('/[^A-Za-z0-9\-_\\\\&|\? \<\>\{\}:,\]\[\(\)\$]/', '', trim($type_string));
|
||||
|
||||
if (strpos($type_string, '[') !== false) {
|
||||
$type_string = self::convertSquareBrackets($type_string);
|
||||
}
|
||||
|
||||
$type_string = preg_replace('/\?(?=[a-zA-Z])/', 'null|', $type_string);
|
||||
|
||||
$type_tokens = self::tokenize($type_string);
|
||||
@ -333,10 +337,14 @@ abstract class Type
|
||||
Aliases $aliases,
|
||||
array $template_types = null
|
||||
) {
|
||||
if (strpos($return_type, '[') !== false) {
|
||||
$return_type = self::convertSquareBrackets($return_type);
|
||||
}
|
||||
|
||||
$return_type_tokens = self::tokenize($return_type);
|
||||
|
||||
foreach ($return_type_tokens as $i => &$return_type_token) {
|
||||
if (in_array($return_type_token, ['<', '>', '|', '?', ',', '{', '}', ':', '[', ']'], true)) {
|
||||
if (in_array($return_type_token, ['<', '>', '|', '?', ',', '{', '}', ':'], true)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -397,6 +405,35 @@ abstract class Type
|
||||
return ($namespace ? $namespace . '\\' : '') . $class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function convertSquareBrackets($type)
|
||||
{
|
||||
$class_chars = '[a-zA-Z0-9\<\>\\\\_]+';
|
||||
|
||||
return preg_replace_callback(
|
||||
'/(' . $class_chars . '|' . '\((' . $class_chars . '(\|' . $class_chars . ')*' . ')\))((\[\])+)/',
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
function (array $matches) {
|
||||
$inner_type = str_replace(['(', ')'], '', (string)$matches[1]);
|
||||
|
||||
$dimensionality = strlen((string)$matches[4]) / 2;
|
||||
|
||||
for ($i = 0; $i < $dimensionality; ++$i) {
|
||||
$inner_type = 'array<mixed,' . $inner_type . '>';
|
||||
}
|
||||
|
||||
return $inner_type;
|
||||
},
|
||||
$type
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Type\Union
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user