Aggiornato Composer
This commit is contained in:
23
vendor/psy/psysh/src/Formatter/CodeFormatter.php
vendored
23
vendor/psy/psysh/src/Formatter/CodeFormatter.php
vendored
@@ -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.
|
||||
@@ -32,7 +32,7 @@ class CodeFormatter implements ReflectorFormatter
|
||||
const HIGHLIGHT_CONST = 'const';
|
||||
const HIGHLIGHT_NUMBER = 'number';
|
||||
const HIGHLIGHT_STRING = 'string';
|
||||
const HIGHLIGHT_COMMENT = 'comment';
|
||||
const HIGHLIGHT_COMMENT = 'code_comment';
|
||||
const HIGHLIGHT_INLINE_HTML = 'inline_html';
|
||||
|
||||
private static $tokenMap = [
|
||||
@@ -76,12 +76,11 @@ class CodeFormatter implements ReflectorFormatter
|
||||
/**
|
||||
* Format the code represented by $reflector for shell output.
|
||||
*
|
||||
* @param \Reflector $reflector
|
||||
* @param string|null $colorMode (deprecated and ignored)
|
||||
* @param \Reflector $reflector
|
||||
*
|
||||
* @return string formatted code
|
||||
*/
|
||||
public static function format(\Reflector $reflector, string $colorMode = null): string
|
||||
public static function format(\Reflector $reflector): string
|
||||
{
|
||||
if (self::isReflectable($reflector)) {
|
||||
if ($code = @\file_get_contents($reflector->getFileName())) {
|
||||
@@ -104,7 +103,7 @@ class CodeFormatter implements ReflectorFormatter
|
||||
*
|
||||
* @return string formatted code
|
||||
*/
|
||||
public static function formatCode(string $code, int $startLine = 1, int $endLine = null, int $markLine = null): string
|
||||
public static function formatCode(string $code, int $startLine = 1, ?int $endLine = null, ?int $markLine = null): string
|
||||
{
|
||||
$spans = self::tokenizeSpans($code);
|
||||
$lines = self::splitLines($spans, $startLine, $endLine);
|
||||
@@ -122,8 +121,6 @@ class CodeFormatter implements ReflectorFormatter
|
||||
* This is typehinted as \Reflector but we've narrowed the input via self::isReflectable already.
|
||||
*
|
||||
* @param \ReflectionClass|\ReflectionFunctionAbstract $reflector
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
private static function getStartLine(\Reflector $reflector): int
|
||||
{
|
||||
@@ -209,7 +206,7 @@ class CodeFormatter implements ReflectorFormatter
|
||||
*
|
||||
* @return \Generator lines, each an array of [$spanType, $spanText] pairs
|
||||
*/
|
||||
private static function splitLines(\Generator $spans, int $startLine = 1, int $endLine = null): \Generator
|
||||
private static function splitLines(\Generator $spans, int $startLine = 1, ?int $endLine = null): \Generator
|
||||
{
|
||||
$lineNum = 1;
|
||||
$buffer = [];
|
||||
@@ -276,7 +273,7 @@ class CodeFormatter implements ReflectorFormatter
|
||||
*
|
||||
* @return \Generator Numbered, formatted lines
|
||||
*/
|
||||
private static function numberLines(\Generator $lines, int $markLine = null): \Generator
|
||||
private static function numberLines(\Generator $lines, ?int $markLine = null): \Generator
|
||||
{
|
||||
$lines = \iterator_to_array($lines);
|
||||
|
||||
@@ -302,16 +299,16 @@ class CodeFormatter implements ReflectorFormatter
|
||||
$mark = ($markLine === $lineNum) ? self::LINE_MARKER : self::NO_LINE_MARKER;
|
||||
}
|
||||
|
||||
yield \sprintf("%s<aside>%${pad}s</aside>: %s", $mark, $lineNum, $line);
|
||||
yield \sprintf("%s<aside>%{$pad}s</aside>: %s", $mark, $lineNum, $line);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether a Reflector instance is reflectable by this formatter.
|
||||
*
|
||||
* @param \Reflector $reflector
|
||||
* @phpstan-assert-if-true \ReflectionClass|\ReflectionFunctionAbstract $reflector
|
||||
*
|
||||
* @return bool
|
||||
* @param \Reflector $reflector
|
||||
*/
|
||||
private static function isReflectable(\Reflector $reflector): bool
|
||||
{
|
||||
|
||||
@@ -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.
|
||||
@@ -68,8 +68,6 @@ class DocblockFormatter implements ReflectorFormatter
|
||||
*
|
||||
* @param array $vector
|
||||
* @param array $lines
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private static function formatVector(array $vector, array $lines): string
|
||||
{
|
||||
@@ -133,8 +131,6 @@ class DocblockFormatter implements ReflectorFormatter
|
||||
*
|
||||
* @param string $type Vector type
|
||||
* @param int $max Pad width
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private static function getVectorParamTemplate(string $type, int $max): string
|
||||
{
|
||||
@@ -150,8 +146,6 @@ class DocblockFormatter implements ReflectorFormatter
|
||||
*
|
||||
* @param string $text String to indent
|
||||
* @param string $indent (default: ' ')
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private static function indent(string $text, string $indent = ' '): string
|
||||
{
|
||||
@@ -162,8 +156,6 @@ class DocblockFormatter implements ReflectorFormatter
|
||||
* Convert underscored or whitespace separated words into sentence case.
|
||||
*
|
||||
* @param string $text
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private static function inflect(string $text): string
|
||||
{
|
||||
|
||||
21
vendor/psy/psysh/src/Formatter/Formatter.php
vendored
21
vendor/psy/psysh/src/Formatter/Formatter.php
vendored
@@ -1,21 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Psy Shell.
|
||||
*
|
||||
* (c) 2012-2022 Justin Hileman
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Psy\Formatter;
|
||||
|
||||
/**
|
||||
* Formatter interface.
|
||||
*
|
||||
* @deprecated this interface only exists for backwards compatibility. Use ReflectorFormatter.
|
||||
*/
|
||||
interface Formatter extends ReflectorFormatter
|
||||
{
|
||||
}
|
||||
@@ -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.
|
||||
@@ -18,8 +18,6 @@ interface ReflectorFormatter
|
||||
{
|
||||
/**
|
||||
* @param \Reflector $reflector
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function format(\Reflector $reflector): string;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
@@ -29,7 +29,7 @@ class TraceFormatter
|
||||
*
|
||||
* @return string[] Formatted stacktrace lines
|
||||
*/
|
||||
public static function formatTrace(\Throwable $throwable, FilterOptions $filter = null, int $count = null, bool $includePsy = true): array
|
||||
public static function formatTrace(\Throwable $throwable, ?FilterOptions $filter = null, ?int $count = null, bool $includePsy = true): array
|
||||
{
|
||||
if ($cwd = \getcwd()) {
|
||||
$cwd = \rtrim($cwd, \DIRECTORY_SEPARATOR).\DIRECTORY_SEPARATOR;
|
||||
|
||||
Reference in New Issue
Block a user