X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fpsy%2Fpsysh%2Fsrc%2FFormatter%2FSignatureFormatter.php;fp=vendor%2Fpsy%2Fpsysh%2Fsrc%2FFormatter%2FSignatureFormatter.php;h=ec8725d9ff6fa3d70aad203286fd7aa1b94def93;hp=0ef3e8b32d357bdf4d041cb90f5c35f6ea1ff9e5;hb=0bf8d09d2542548982e81a441b1f16e75873a04f;hpb=74df008bdbb3a11eeea356744f39b802369bda3c
diff --git a/vendor/psy/psysh/src/Formatter/SignatureFormatter.php b/vendor/psy/psysh/src/Formatter/SignatureFormatter.php
index 0ef3e8b32..ec8725d9f 100644
--- a/vendor/psy/psysh/src/Formatter/SignatureFormatter.php
+++ b/vendor/psy/psysh/src/Formatter/SignatureFormatter.php
@@ -11,7 +11,8 @@
namespace Psy\Formatter;
-use Psy\Reflection\ReflectionConstant;
+use Psy\Reflection\ReflectionClassConstant;
+use Psy\Reflection\ReflectionConstant_;
use Psy\Reflection\ReflectionLanguageConstruct;
use Psy\Util\Json;
use Symfony\Component\Console\Formatter\OutputFormatter;
@@ -41,8 +42,9 @@ class SignatureFormatter implements Formatter
case $reflector instanceof \ReflectionClass:
return self::formatClass($reflector);
- case $reflector instanceof ReflectionConstant:
- return self::formatConstant($reflector);
+ case $reflector instanceof ReflectionClassConstant:
+ case $reflector instanceof \ReflectionClassConstant:
+ return self::formatClassConstant($reflector);
case $reflector instanceof \ReflectionMethod:
return self::formatMethod($reflector);
@@ -50,8 +52,11 @@ class SignatureFormatter implements Formatter
case $reflector instanceof \ReflectionProperty:
return self::formatProperty($reflector);
+ case $reflector instanceof ReflectionConstant_:
+ return self::formatConstant($reflector);
+
default:
- throw new \InvalidArgumentException('Unexpected Reflector class: ' . get_class($reflector));
+ throw new \InvalidArgumentException('Unexpected Reflector class: ' . \get_class($reflector));
}
}
@@ -70,8 +75,6 @@ class SignatureFormatter implements Formatter
/**
* Print the method, property or class modifiers.
*
- * Technically this should be a trait. Can't wait for 5.4 :)
- *
* @param \Reflector $reflector
*
* @return string Formatted modifiers
@@ -81,13 +84,13 @@ class SignatureFormatter implements Formatter
if ($reflector instanceof \ReflectionClass && $reflector->isTrait()) {
// For some reason, PHP 5.x returns `abstract public` modifiers for
// traits. Let's just ignore that business entirely.
- if (version_compare(PHP_VERSION, '7.0.0', '<')) {
+ if (\version_compare(PHP_VERSION, '7.0.0', '<')) {
return [];
}
}
- return implode(' ', array_map(function ($modifier) {
- return sprintf('%s', $modifier);
+ return \implode(' ', \array_map(function ($modifier) {
+ return \sprintf('%s', $modifier);
}, \Reflection::getModifierNames($reflector->getModifiers())));
}
@@ -112,39 +115,39 @@ class SignatureFormatter implements Formatter
$chunks[] = $reflector->isInterface() ? 'interface' : 'class';
}
- $chunks[] = sprintf('%s', self::formatName($reflector));
+ $chunks[] = \sprintf('%s', self::formatName($reflector));
if ($parent = $reflector->getParentClass()) {
$chunks[] = 'extends';
- $chunks[] = sprintf('%s', $parent->getName());
+ $chunks[] = \sprintf('%s', $parent->getName());
}
$interfaces = $reflector->getInterfaceNames();
if (!empty($interfaces)) {
- sort($interfaces);
+ \sort($interfaces);
$chunks[] = 'implements';
- $chunks[] = implode(', ', array_map(function ($name) {
- return sprintf('%s', $name);
+ $chunks[] = \implode(', ', \array_map(function ($name) {
+ return \sprintf('%s', $name);
}, $interfaces));
}
- return implode(' ', $chunks);
+ return \implode(' ', $chunks);
}
/**
* Format a constant signature.
*
- * @param ReflectionConstant $reflector
+ * @param ReflectionClassConstant|\ReflectionClassConstant $reflector
*
* @return string Formatted signature
*/
- private static function formatConstant(ReflectionConstant $reflector)
+ private static function formatClassConstant($reflector)
{
$value = $reflector->getValue();
$style = self::getTypeStyle($value);
- return sprintf(
+ return \sprintf(
'const %s = <%s>%s%s>',
self::formatName($reflector),
$style,
@@ -153,6 +156,27 @@ class SignatureFormatter implements Formatter
);
}
+ /**
+ * Format a constant signature.
+ *
+ * @param ReflectionConstant_ $reflector
+ *
+ * @return string Formatted signature
+ */
+ private static function formatConstant($reflector)
+ {
+ $value = $reflector->getValue();
+ $style = self::getTypeStyle($value);
+
+ return \sprintf(
+ 'define(%s, <%s>%s%s>)',
+ OutputFormatter::escape(Json::encode($reflector->getName())),
+ $style,
+ OutputFormatter::escape(Json::encode($value)),
+ $style
+ );
+ }
+
/**
* Helper for getting output style for a given value's type.
*
@@ -162,11 +186,11 @@ class SignatureFormatter implements Formatter
*/
private static function getTypeStyle($value)
{
- if (is_int($value) || is_float($value)) {
+ if (\is_int($value) || \is_float($value)) {
return 'number';
- } elseif (is_string($value)) {
+ } elseif (\is_string($value)) {
return 'string';
- } elseif (is_bool($value) || is_null($value)) {
+ } elseif (\is_bool($value) || \is_null($value)) {
return 'bool';
} else {
return 'strong'; // @codeCoverageIgnore
@@ -182,7 +206,7 @@ class SignatureFormatter implements Formatter
*/
private static function formatProperty(\ReflectionProperty $reflector)
{
- return sprintf(
+ return \sprintf(
'%s $%s',
self::formatModifiers($reflector),
$reflector->getName()
@@ -198,11 +222,11 @@ class SignatureFormatter implements Formatter
*/
private static function formatFunction(\ReflectionFunctionAbstract $reflector)
{
- return sprintf(
+ return \sprintf(
'function %s%s(%s)',
$reflector->returnsReference() ? '&' : '',
self::formatName($reflector),
- implode(', ', self::formatFunctionParams($reflector))
+ \implode(', ', self::formatFunctionParams($reflector))
);
}
@@ -215,7 +239,7 @@ class SignatureFormatter implements Formatter
*/
private static function formatMethod(\ReflectionMethod $reflector)
{
- return sprintf(
+ return \sprintf(
'%s %s',
self::formatModifiers($reflector),
self::formatFunction($reflector)
@@ -238,7 +262,7 @@ class SignatureFormatter implements Formatter
if ($param->isArray()) {
$hint = 'array ';
} elseif ($class = $param->getClass()) {
- $hint = sprintf('%s ', $class->getName());
+ $hint = \sprintf('%s ', $class->getName());
}
} catch (\Exception $e) {
// sometimes we just don't know...
@@ -248,11 +272,11 @@ class SignatureFormatter implements Formatter
// Hax: we'll try to extract it :P
// @codeCoverageIgnoreStart
- $chunks = explode('$' . $param->getName(), (string) $param);
- $chunks = explode(' ', trim($chunks[0]));
- $guess = end($chunks);
+ $chunks = \explode('$' . $param->getName(), (string) $param);
+ $chunks = \explode(' ', \trim($chunks[0]));
+ $guess = \end($chunks);
- $hint = sprintf('%s ', $guess);
+ $hint = \sprintf('%s ', $guess);
// @codeCoverageIgnoreEnd
}
@@ -263,14 +287,14 @@ class SignatureFormatter implements Formatter
} else {
$value = $param->getDefaultValue();
$typeStyle = self::getTypeStyle($value);
- $value = is_array($value) ? 'array()' : is_null($value) ? 'null' : var_export($value, true);
+ $value = \is_array($value) ? 'array()' : \is_null($value) ? 'null' : \var_export($value, true);
}
- $default = sprintf(' = <%s>%s%s>', $typeStyle, OutputFormatter::escape($value), $typeStyle);
+ $default = \sprintf(' = <%s>%s%s>', $typeStyle, OutputFormatter::escape($value), $typeStyle);
} else {
$default = '';
}
- $params[] = sprintf(
+ $params[] = \sprintf(
'%s%s$%s%s',
$param->isPassedByReference() ? '&' : '',
$hint,