Aggiornato Composer

This commit is contained in:
Paolo A
2024-05-17 12:24:19 +00:00
parent 4ac62108b5
commit ec201d75b2
2238 changed files with 38684 additions and 59785 deletions

View File

@@ -3,7 +3,7 @@
/*
* This file is part of Psy Shell.
*
* (c) 2012-2022 Justin Hileman
* (c) 2012-2023 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@@ -11,8 +11,7 @@
namespace Psy\Formatter;
use Psy\Reflection\ReflectionClassConstant;
use Psy\Reflection\ReflectionConstant_;
use Psy\Reflection\ReflectionConstant;
use Psy\Reflection\ReflectionLanguageConstruct;
use Psy\Util\Json;
use Symfony\Component\Console\Formatter\OutputFormatter;
@@ -38,11 +37,10 @@ class SignatureFormatter implements ReflectorFormatter
case $reflector instanceof ReflectionLanguageConstruct:
return self::formatFunction($reflector);
// this case also covers \ReflectionObject:
case $reflector instanceof \ReflectionClass:
// this case also covers \ReflectionObject
return self::formatClass($reflector);
case $reflector instanceof ReflectionClassConstant:
case $reflector instanceof \ReflectionClassConstant:
return self::formatClassConstant($reflector);
@@ -52,7 +50,7 @@ class SignatureFormatter implements ReflectorFormatter
case $reflector instanceof \ReflectionProperty:
return self::formatProperty($reflector);
case $reflector instanceof ReflectionConstant_:
case $reflector instanceof ReflectionConstant:
return self::formatConstant($reflector);
default:
@@ -63,7 +61,7 @@ class SignatureFormatter implements ReflectorFormatter
/**
* Print the signature name.
*
* @param \Reflector $reflector
* @param \ReflectionClass|\ReflectionClassConstant|\ReflectionFunctionAbstract $reflector
*
* @return string Formatted name
*/
@@ -75,7 +73,7 @@ class SignatureFormatter implements ReflectorFormatter
/**
* Print the method, property or class modifiers.
*
* @param \Reflector $reflector
* @param \ReflectionMethod|\ReflectionProperty|\ReflectionClass $reflector
*
* @return string Formatted modifiers
*/
@@ -130,7 +128,7 @@ class SignatureFormatter implements ReflectorFormatter
/**
* Format a constant signature.
*
* @param ReflectionClassConstant|\ReflectionClassConstant $reflector
* @param \ReflectionClassConstant $reflector
*
* @return string Formatted signature
*/
@@ -151,11 +149,11 @@ class SignatureFormatter implements ReflectorFormatter
/**
* Format a constant signature.
*
* @param ReflectionConstant_ $reflector
* @param ReflectionConstant $reflector
*
* @return string Formatted signature
*/
private static function formatConstant(ReflectionConstant_ $reflector): string
private static function formatConstant(ReflectionConstant $reflector): string
{
$value = $reflector->getValue();
$style = self::getTypeStyle($value);
@@ -173,8 +171,6 @@ class SignatureFormatter implements ReflectorFormatter
* Helper for getting output style for a given value's type.
*
* @param mixed $value
*
* @return string
*/
private static function getTypeStyle($value): string
{
@@ -236,7 +232,7 @@ class SignatureFormatter implements ReflectorFormatter
return '';
}
return \sprintf(': %s', self::formatReflectionType($reflector->getReturnType()));
return \sprintf(': %s', self::formatReflectionType($reflector->getReturnType(), true));
}
/**
@@ -269,7 +265,9 @@ class SignatureFormatter implements ReflectorFormatter
$hint = '';
try {
if (\method_exists($param, 'getType')) {
$hint = self::formatReflectionType($param->getType());
// Only include the inquisitive nullable type iff param default value is not null.
$defaultIsNull = $param->isOptional() && $param->isDefaultValueAvailable() && $param->getDefaultValue() === null;
$hint = self::formatReflectionType($param->getType(), !$defaultIsNull);
} else {
if ($param->isArray()) {
$hint = '<keyword>array</keyword>';
@@ -324,28 +322,37 @@ class SignatureFormatter implements ReflectorFormatter
* Print function param or return type(s).
*
* @param \ReflectionType $type
*
* @return string
*/
private static function formatReflectionType(\ReflectionType $type = null): string
private static function formatReflectionType(?\ReflectionType $type, bool $indicateNullable): string
{
if ($type === null) {
return '';
}
$types = $type instanceof \ReflectionUnionType ? $type->getTypes() : [$type];
$formattedTypes = [];
foreach ($types as $type) {
$typeStyle = $type->isBuiltin() ? 'keyword' : 'class';
// PHP 7.0 didn't have `getName` on reflection types, so wheee!
$typeName = \method_exists($type, 'getName') ? $type->getName() : (string) $type;
// @todo Do we want to include the ? for nullable types? Maybe only sometimes?
$formattedTypes[] = \sprintf('<%s>%s</%s>', $typeStyle, OutputFormatter::escape($typeName), $typeStyle);
if ($type instanceof \ReflectionUnionType) {
$delimeter = '|';
} elseif ($type instanceof \ReflectionIntersectionType) {
$delimeter = '&';
} else {
return self::formatReflectionNamedType($type, $indicateNullable);
}
return \implode('|', $formattedTypes);
$formattedTypes = [];
foreach ($type->getTypes() as $namedType) {
$formattedTypes[] = self::formatReflectionNamedType($namedType, $indicateNullable);
}
return \implode($delimeter, $formattedTypes);
}
/**
* Print a single named type.
*/
private static function formatReflectionNamedType(\ReflectionNamedType $type, bool $indicateNullable): string
{
$typeStyle = $type->isBuiltin() ? 'keyword' : 'class';
$nullable = $indicateNullable && $type->allowsNull() ? '?' : '';
return \sprintf('<%s>%s%s</%s>', $typeStyle, $nullable, OutputFormatter::escape($type->getName()), $typeStyle);
}
}