mirror of
https://github.com/barryvdh/ReflectionDocBlock.git
synced 2026-08-18 10:07:12 +00:00
Fix codestyle issues
This commit is contained in:
@@ -57,7 +57,9 @@ final class MethodFactory implements PHPStanFactory
|
||||
),
|
||||
$param->isReference,
|
||||
$param->isVariadic,
|
||||
$param->defaultValue === null ? MethodParameter::NO_DEFAULT_VALUE : (string) $param->defaultValue
|
||||
$param->defaultValue === null ?
|
||||
MethodParameter::NO_DEFAULT_VALUE :
|
||||
(string) $param->defaultValue
|
||||
);
|
||||
},
|
||||
$tagValue->parameters
|
||||
|
||||
@@ -13,9 +13,12 @@ declare(strict_types=1);
|
||||
|
||||
namespace phpDocumentor\Reflection\DocBlock\Tags\Factory;
|
||||
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Formatter;
|
||||
use function str_repeat;
|
||||
use function strlen;
|
||||
use function array_key_last;
|
||||
use function get_class;
|
||||
use function gettype;
|
||||
use function method_exists;
|
||||
use function ucfirst;
|
||||
use function var_export;
|
||||
|
||||
/**
|
||||
* @internal This class is not part of the BC promise of this library.
|
||||
@@ -26,13 +29,14 @@ final class MethodParameterFactory
|
||||
* Formats the given default value to a string-able mixin
|
||||
*
|
||||
* @param mixed $defaultValue
|
||||
* @return string
|
||||
*/
|
||||
public function format($defaultValue): string
|
||||
{
|
||||
if (method_exists($this, $method = 'format'.ucfirst(gettype($defaultValue)))) {
|
||||
$method = 'format' . ucfirst(gettype($defaultValue));
|
||||
if (method_exists($this, $method)) {
|
||||
return ' = ' . $this->{$method}($defaultValue);
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
@@ -43,7 +47,6 @@ final class MethodParameterFactory
|
||||
|
||||
/**
|
||||
* @param mixed $defaultValue
|
||||
* @return string
|
||||
*/
|
||||
private function formatNull($defaultValue): string
|
||||
{
|
||||
@@ -66,30 +69,32 @@ final class MethodParameterFactory
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<array|null|int|float|bool|string|object> $defaultValue
|
||||
* @return string
|
||||
* @param array<(array<mixed>|int|float|bool|string|object|null)> $defaultValue
|
||||
*/
|
||||
private function formatArray(array $defaultValue): string
|
||||
{
|
||||
$formatedValue = '[';
|
||||
|
||||
foreach ($defaultValue as $key => $value) {
|
||||
if (method_exists($this, $method = 'format'.ucfirst(gettype($value)))) {
|
||||
$formatedValue .= $this->{$method}($value);
|
||||
|
||||
if ($key !== array_key_last($defaultValue)) {
|
||||
$formatedValue .= ',';
|
||||
}
|
||||
$method = 'format' . ucfirst(gettype($value));
|
||||
if (!method_exists($this, $method)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$formatedValue .= $this->{$method}($value);
|
||||
|
||||
if ($key === array_key_last($defaultValue)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$formatedValue .= ',';
|
||||
}
|
||||
|
||||
$formatedValue .= ']';
|
||||
|
||||
return $formatedValue;
|
||||
return $formatedValue . ']';
|
||||
}
|
||||
|
||||
private function formatObject(object $defaultValue): string
|
||||
{
|
||||
return 'new '. get_class($defaultValue). '()';
|
||||
return 'new ' . get_class($defaultValue) . '()';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,9 @@ namespace phpDocumentor\Reflection\DocBlock\Tags;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Factory\MethodParameterFactory;
|
||||
use phpDocumentor\Reflection\Type;
|
||||
|
||||
use function implode;
|
||||
use function is_array;
|
||||
|
||||
final class MethodParameter
|
||||
{
|
||||
private Type $type;
|
||||
@@ -25,9 +28,7 @@ final class MethodParameter
|
||||
|
||||
private string $name;
|
||||
|
||||
/**
|
||||
* @var mixed
|
||||
*/
|
||||
/** @var mixed */
|
||||
private $defaultValue;
|
||||
|
||||
public const NO_DEFAULT_VALUE = '__NO_VALUE__';
|
||||
@@ -71,13 +72,11 @@ final class MethodParameter
|
||||
|
||||
public function getDefaultValue(): ?string
|
||||
{
|
||||
if ($this->defaultValue === static::NO_DEFAULT_VALUE) {
|
||||
if ($this->defaultValue === self::NO_DEFAULT_VALUE) {
|
||||
return null;
|
||||
}
|
||||
if (is_array($this->defaultValue)) {
|
||||
return implode(',', $this->defaultValue);
|
||||
}
|
||||
return (string) $this->defaultValue;
|
||||
|
||||
return (new MethodParameterFactory())->format($this->defaultValue);
|
||||
}
|
||||
|
||||
public function __toString(): string
|
||||
@@ -86,6 +85,10 @@ final class MethodParameter
|
||||
($this->isReference() ? '&' : '') .
|
||||
($this->isVariadic() ? '...' : '') .
|
||||
'$' . $this->getName() .
|
||||
($this->defaultValue !== self::NO_DEFAULT_VALUE ? (new MethodParameterFactory)->format($this->defaultValue) : '');
|
||||
(
|
||||
$this->defaultValue !== self::NO_DEFAULT_VALUE ?
|
||||
(new MethodParameterFactory())->format($this->defaultValue) :
|
||||
''
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user