From fde2b5916d985462a838b8994b6fb783bd4bdc35 Mon Sep 17 00:00:00 2001 From: Gautier DELEGLISE Date: Sat, 26 Oct 2024 23:49:53 +0200 Subject: [PATCH 01/10] :sparkles: method parameter default value rendering --- src/DocBlock/Tags/Method.php | 9 +++++- tests/unit/DocBlock/Tags/MethodTest.php | 39 +++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/src/DocBlock/Tags/Method.php b/src/DocBlock/Tags/Method.php index 471ebe95..ceefa6a2 100644 --- a/src/DocBlock/Tags/Method.php +++ b/src/DocBlock/Tags/Method.php @@ -261,10 +261,17 @@ public function __toString(): string { $arguments = []; foreach ($this->parameters as $parameter) { + if ($parameter->getDefaultValue() !== null) { + $parameterDefaultValueStr = $parameter->getDefaultValue(); + settype($parameterDefaultValueStr, (string)$parameter->getType()); + $parameterDefaultValueStr = sprintf(' = %s', var_export($parameterDefaultValueStr, true)); + } + $arguments[] = $parameter->getType() . ' ' . ($parameter->isReference() ? '&' : '') . ($parameter->isVariadic() ? '...' : '') . - '$' . $parameter->getName(); + '$' . $parameter->getName() . + $parameterDefaultValueStr ?? ''; } $argumentStr = '(' . implode(', ', $arguments) . ')'; diff --git a/tests/unit/DocBlock/Tags/MethodTest.php b/tests/unit/DocBlock/Tags/MethodTest.php index dfc0032b..ab33d3f9 100644 --- a/tests/unit/DocBlock/Tags/MethodTest.php +++ b/tests/unit/DocBlock/Tags/MethodTest.php @@ -19,8 +19,10 @@ use phpDocumentor\Reflection\Fqsen; use phpDocumentor\Reflection\TypeResolver; use phpDocumentor\Reflection\Types\Array_; +use phpDocumentor\Reflection\Types\Boolean; use phpDocumentor\Reflection\Types\Compound; use phpDocumentor\Reflection\Types\Context; +use phpDocumentor\Reflection\Types\Float_; use phpDocumentor\Reflection\Types\Integer; use phpDocumentor\Reflection\Types\Mixed_; use phpDocumentor\Reflection\Types\Object_; @@ -698,4 +700,41 @@ public function testCreateWithReference(): void $this->assertSame($description, $fixture->getDescription()); $this->assertTrue($fixture->returnsReference()); } + + /** + * @uses \phpDocumentor\Reflection\DocBlock\Tags\MethodParameter::__construct + * @uses \phpDocumentor\Reflection\DocBlock\Tags\MethodParameter::getDefaultValue() + * @uses \phpDocumentor\Reflection\DocBlock\Tags\MethodParameter::__toString + * @uses \phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter + * + * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::render + * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::getName + */ + public function testIfTagCanBeRenderedUsingMethodParameterWithDefaultValue(): void + { + $arguments = [ + ['name' => 'argument1', 'type' => new String_()], + ['name' => 'argument2', 'type' => new Object_()], + ]; + + $fixture = new Method( + 'myMethod', + $arguments, + new Void_(), + false, + null, + false, + [ + new MethodParameter('argument1', new String_(), false, false, '1'), + new MethodParameter('argument2', new Integer(), false, false, '1'), + new MethodParameter('argument3', new Boolean(), false, false, 'true'), + new MethodParameter('argument4', new Float_(), false, false, '1.23'), + ] + ); + + $this->assertSame( + '@method void myMethod(string $argument1 = \'1\', int $argument2 = 1, bool $argument3 = true, float $argument4 = 1.23)', + $fixture->render() + ); + } } From 442a3d1dc8b6beef5b5a2344d5d4be4e5be058d8 Mon Sep 17 00:00:00 2001 From: Gautier DELEGLISE Date: Sun, 27 Oct 2024 12:17:33 +0100 Subject: [PATCH 02/10] :recycle: variable might not be defined --- src/DocBlock/Tags/Method.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/DocBlock/Tags/Method.php b/src/DocBlock/Tags/Method.php index ceefa6a2..174e33cd 100644 --- a/src/DocBlock/Tags/Method.php +++ b/src/DocBlock/Tags/Method.php @@ -261,6 +261,7 @@ public function __toString(): string { $arguments = []; foreach ($this->parameters as $parameter) { + $parameterDefaultValueStr = null; if ($parameter->getDefaultValue() !== null) { $parameterDefaultValueStr = $parameter->getDefaultValue(); settype($parameterDefaultValueStr, (string)$parameter->getType()); From 456d2b0be2b8790719a1c9a4eeb6a1e47e3d5a5b Mon Sep 17 00:00:00 2001 From: Gautier DELEGLISE Date: Sun, 27 Oct 2024 12:20:56 +0100 Subject: [PATCH 03/10] :bug: left side of ?? is not nullable --- src/DocBlock/Tags/Method.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DocBlock/Tags/Method.php b/src/DocBlock/Tags/Method.php index 174e33cd..5fad2f36 100644 --- a/src/DocBlock/Tags/Method.php +++ b/src/DocBlock/Tags/Method.php @@ -272,7 +272,7 @@ public function __toString(): string ($parameter->isReference() ? '&' : '') . ($parameter->isVariadic() ? '...' : '') . '$' . $parameter->getName() . - $parameterDefaultValueStr ?? ''; + ($parameterDefaultValueStr ?? ''); } $argumentStr = '(' . implode(', ', $arguments) . ')'; From 992c829bade5762f73b37c742c317e691d57f278 Mon Sep 17 00:00:00 2001 From: Gautier DELEGLISE Date: Mon, 28 Oct 2024 10:28:22 +0100 Subject: [PATCH 04/10] :recycle: cover more default value cases --- src/DocBlock/Tags/Factory/MethodFactory.php | 2 +- .../Tags/Factory/MethodParameterFactory.php | 81 ++++++++++++++ src/DocBlock/Tags/Method.php | 13 +-- src/DocBlock/Tags/MethodParameter.php | 18 ++- .../DocBlock/Tags/MethodParameterTest.php | 104 ++++++++++++++++++ tests/unit/DocBlock/Tags/MethodTest.php | 38 +------ 6 files changed, 203 insertions(+), 53 deletions(-) create mode 100644 src/DocBlock/Tags/Factory/MethodParameterFactory.php create mode 100644 tests/unit/DocBlock/Tags/MethodParameterTest.php diff --git a/src/DocBlock/Tags/Factory/MethodFactory.php b/src/DocBlock/Tags/Factory/MethodFactory.php index 920be845..51dc0429 100644 --- a/src/DocBlock/Tags/Factory/MethodFactory.php +++ b/src/DocBlock/Tags/Factory/MethodFactory.php @@ -57,7 +57,7 @@ function (MethodTagValueParameterNode $param) use ($context) { ), $param->isReference, $param->isVariadic, - (string) $param->defaultValue + $param->defaultValue ); }, $tagValue->parameters diff --git a/src/DocBlock/Tags/Factory/MethodParameterFactory.php b/src/DocBlock/Tags/Factory/MethodParameterFactory.php new file mode 100644 index 00000000..8fd16f24 --- /dev/null +++ b/src/DocBlock/Tags/Factory/MethodParameterFactory.php @@ -0,0 +1,81 @@ +{$method}($defaultValue); + } + return ''; + } + + protected function formatDouble(float $defaultValue): string + { + return var_export($defaultValue, true); + } + + protected function formatNull($defaultValue): string + { + return 'null'; + } + + protected function formatInteger(int $defaultValue): string + { + return var_export($defaultValue, true); + } + + protected function formatString(string $defaultValue): string + { + return var_export($defaultValue, true); + } + + protected function formatBoolean(bool $defaultValue): string + { + return var_export($defaultValue, true); + } + + protected 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 .= ','; + } + } + } + + $formatedValue .= ']'; + + return $formatedValue; + } + + protected function formatObject(object $defaultValue): string + { + return 'new '. get_class($defaultValue). '()'; + } +} diff --git a/src/DocBlock/Tags/Method.php b/src/DocBlock/Tags/Method.php index 5fad2f36..41e0eed1 100644 --- a/src/DocBlock/Tags/Method.php +++ b/src/DocBlock/Tags/Method.php @@ -261,18 +261,7 @@ public function __toString(): string { $arguments = []; foreach ($this->parameters as $parameter) { - $parameterDefaultValueStr = null; - if ($parameter->getDefaultValue() !== null) { - $parameterDefaultValueStr = $parameter->getDefaultValue(); - settype($parameterDefaultValueStr, (string)$parameter->getType()); - $parameterDefaultValueStr = sprintf(' = %s', var_export($parameterDefaultValueStr, true)); - } - - $arguments[] = $parameter->getType() . ' ' . - ($parameter->isReference() ? '&' : '') . - ($parameter->isVariadic() ? '...' : '') . - '$' . $parameter->getName() . - ($parameterDefaultValueStr ?? ''); + $arguments[] = (string) $parameter; } $argumentStr = '(' . implode(', ', $arguments) . ')'; diff --git a/src/DocBlock/Tags/MethodParameter.php b/src/DocBlock/Tags/MethodParameter.php index 0c85d41d..72d2c4a8 100644 --- a/src/DocBlock/Tags/MethodParameter.php +++ b/src/DocBlock/Tags/MethodParameter.php @@ -12,6 +12,7 @@ namespace phpDocumentor\Reflection\DocBlock\Tags; +use phpDocumentor\Reflection\DocBlock\Tags\Factory\MethodParameterFactory; use phpDocumentor\Reflection\Type; final class MethodParameter @@ -24,14 +25,16 @@ final class MethodParameter private string $name; - private ?string $defaultValue = null; + private mixed $defaultValue; + + private const NO_DEFAULT_VALUE = '__NO_VALUE__'; public function __construct( string $name, Type $type, bool $isReference = false, bool $isVariadic = false, - ?string $defaultValue = null + $defaultValue = self::NO_DEFAULT_VALUE ) { $this->type = $type; $this->isReference = $isReference; @@ -60,8 +63,17 @@ public function isVariadic(): bool return $this->isVariadic; } - public function getDefaultValue(): ?string + public function getDefaultValue(): mixed { return $this->defaultValue; } + + public function __toString(): string + { + return $this->getType() . ' ' . + ($this->isReference() ? '&' : '') . + ($this->isVariadic() ? '...' : '') . + '$' . $this->getName() . + ($this->getDefaultValue() !== self::NO_DEFAULT_VALUE ? (new MethodParameterFactory)->format($this->getDefaultValue()) : ''); + } } diff --git a/tests/unit/DocBlock/Tags/MethodParameterTest.php b/tests/unit/DocBlock/Tags/MethodParameterTest.php new file mode 100644 index 00000000..08d4f0e7 --- /dev/null +++ b/tests/unit/DocBlock/Tags/MethodParameterTest.php @@ -0,0 +1,104 @@ + + */ +class MethodParameterTest extends TestCase +{ + /** + * Call Mockery::close after each test. + */ + public function tearDown(): void + { + m::close(); + } + + public function collectionDefaultValuesProvider(): array + { + return [ + [new String_(), '1', '\'1\''], + [new Integer(), 1, '1'], + [new Boolean(), true, 'true'], + [new Float_(), 1.23, '1.23'], + [new Array_(), [1, '2', true], '[1,\'2\',true]'], + [new Array_(), [[1, 2], '2', true], '[[1,2],\'2\',true]'], + [new Nullable(new Float_()), null, 'null'], + [new Nullable(new Float_()), 1.23, '1.23'], + [new Object_(new Fqsen('\\stdClass')), new \stdClass(), 'new stdClass()'], + ]; + } + + /** + * @uses \phpDocumentor\Reflection\DocBlock\Tags\MethodParameter::__construct + * @uses \phpDocumentor\Reflection\DocBlock\Tags\MethodParameter::getDefaultValue() + * @uses \phpDocumentor\Reflection\DocBlock\Tags\MethodParameter::__toString + * @uses \phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter + * + * @dataProvider collectionDefaultValuesProvider + * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::render + * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::getName + */ + public function testIfTagCanBeRenderedUsingMethodParameterWithDefaultValue(Type $type, $defaultValue, string $defaultValueStr): void + { + $fixture = new MethodParameter('argument', $type, false, false, $defaultValue); + + $this->assertSame( + sprintf('%s $argument = %s', $type, $defaultValueStr), + (string) $fixture + ); + } + + /** + * @uses \phpDocumentor\Reflection\DocBlock\Tags\MethodParameter::__construct + * @uses \phpDocumentor\Reflection\DocBlock\Tags\MethodParameter::getDefaultValue() + * @uses \phpDocumentor\Reflection\DocBlock\Tags\MethodParameter::__toString + * @uses \phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter + * + * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::render + * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::getName + */ + public function testIfTagCanBeRenderedUsingMethodParameterWithNoDefaultValue(): void + { + $fixture = new MethodParameter('argument', new Float_()); + + $this->assertSame( + 'float $argument', + (string) $fixture + ); + } +} diff --git a/tests/unit/DocBlock/Tags/MethodTest.php b/tests/unit/DocBlock/Tags/MethodTest.php index ab33d3f9..77196bb9 100644 --- a/tests/unit/DocBlock/Tags/MethodTest.php +++ b/tests/unit/DocBlock/Tags/MethodTest.php @@ -17,6 +17,7 @@ use phpDocumentor\Reflection\DocBlock\Description; use phpDocumentor\Reflection\DocBlock\DescriptionFactory; use phpDocumentor\Reflection\Fqsen; +use phpDocumentor\Reflection\Type; use phpDocumentor\Reflection\TypeResolver; use phpDocumentor\Reflection\Types\Array_; use phpDocumentor\Reflection\Types\Boolean; @@ -700,41 +701,4 @@ public function testCreateWithReference(): void $this->assertSame($description, $fixture->getDescription()); $this->assertTrue($fixture->returnsReference()); } - - /** - * @uses \phpDocumentor\Reflection\DocBlock\Tags\MethodParameter::__construct - * @uses \phpDocumentor\Reflection\DocBlock\Tags\MethodParameter::getDefaultValue() - * @uses \phpDocumentor\Reflection\DocBlock\Tags\MethodParameter::__toString - * @uses \phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter - * - * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::render - * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::getName - */ - public function testIfTagCanBeRenderedUsingMethodParameterWithDefaultValue(): void - { - $arguments = [ - ['name' => 'argument1', 'type' => new String_()], - ['name' => 'argument2', 'type' => new Object_()], - ]; - - $fixture = new Method( - 'myMethod', - $arguments, - new Void_(), - false, - null, - false, - [ - new MethodParameter('argument1', new String_(), false, false, '1'), - new MethodParameter('argument2', new Integer(), false, false, '1'), - new MethodParameter('argument3', new Boolean(), false, false, 'true'), - new MethodParameter('argument4', new Float_(), false, false, '1.23'), - ] - ); - - $this->assertSame( - '@method void myMethod(string $argument1 = \'1\', int $argument2 = 1, bool $argument3 = true, float $argument4 = 1.23)', - $fixture->render() - ); - } } From 93cfc743bdcd95f8dfcf475ee5b4e37a312a87a4 Mon Sep 17 00:00:00 2001 From: Gautier DELEGLISE Date: Mon, 28 Oct 2024 10:30:40 +0100 Subject: [PATCH 05/10] :green_heart: removed unecessary imports --- tests/unit/DocBlock/Tags/MethodParameterTest.php | 9 --------- tests/unit/DocBlock/Tags/MethodTest.php | 3 --- 2 files changed, 12 deletions(-) diff --git a/tests/unit/DocBlock/Tags/MethodParameterTest.php b/tests/unit/DocBlock/Tags/MethodParameterTest.php index 08d4f0e7..ef64f6e0 100644 --- a/tests/unit/DocBlock/Tags/MethodParameterTest.php +++ b/tests/unit/DocBlock/Tags/MethodParameterTest.php @@ -14,24 +14,15 @@ namespace phpDocumentor\Reflection\DocBlock\Tags; use Mockery as m; -use phpDocumentor\Reflection\DocBlock\Description; -use phpDocumentor\Reflection\DocBlock\DescriptionFactory; use phpDocumentor\Reflection\Fqsen; use phpDocumentor\Reflection\Type; -use phpDocumentor\Reflection\TypeResolver; use phpDocumentor\Reflection\Types\Array_; use phpDocumentor\Reflection\Types\Boolean; -use phpDocumentor\Reflection\Types\Compound; -use phpDocumentor\Reflection\Types\Context; use phpDocumentor\Reflection\Types\Float_; use phpDocumentor\Reflection\Types\Integer; -use phpDocumentor\Reflection\Types\Mixed_; -use phpDocumentor\Reflection\Types\Null_; use phpDocumentor\Reflection\Types\Nullable; use phpDocumentor\Reflection\Types\Object_; use phpDocumentor\Reflection\Types\String_; -use phpDocumentor\Reflection\Types\This; -use phpDocumentor\Reflection\Types\Void_; use PHPUnit\Framework\TestCase; /** diff --git a/tests/unit/DocBlock/Tags/MethodTest.php b/tests/unit/DocBlock/Tags/MethodTest.php index 77196bb9..dfc0032b 100644 --- a/tests/unit/DocBlock/Tags/MethodTest.php +++ b/tests/unit/DocBlock/Tags/MethodTest.php @@ -17,13 +17,10 @@ use phpDocumentor\Reflection\DocBlock\Description; use phpDocumentor\Reflection\DocBlock\DescriptionFactory; use phpDocumentor\Reflection\Fqsen; -use phpDocumentor\Reflection\Type; use phpDocumentor\Reflection\TypeResolver; use phpDocumentor\Reflection\Types\Array_; -use phpDocumentor\Reflection\Types\Boolean; use phpDocumentor\Reflection\Types\Compound; use phpDocumentor\Reflection\Types\Context; -use phpDocumentor\Reflection\Types\Float_; use phpDocumentor\Reflection\Types\Integer; use phpDocumentor\Reflection\Types\Mixed_; use phpDocumentor\Reflection\Types\Object_; From 6a623a4829976aefff76b70ed323fa4f7177139f Mon Sep 17 00:00:00 2001 From: Gautier DELEGLISE Date: Wed, 30 Oct 2024 21:49:01 +0100 Subject: [PATCH 06/10] :children_crossing: code review --- .../Tags/Factory/MethodParameterFactory.php | 26 +++++++++++++------ src/DocBlock/Tags/MethodParameter.php | 8 +++++- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/DocBlock/Tags/Factory/MethodParameterFactory.php b/src/DocBlock/Tags/Factory/MethodParameterFactory.php index 8fd16f24..1cccde95 100644 --- a/src/DocBlock/Tags/Factory/MethodParameterFactory.php +++ b/src/DocBlock/Tags/Factory/MethodParameterFactory.php @@ -17,10 +17,16 @@ use function str_repeat; use function strlen; -class MethodParameterFactory +/** + * @internal This class is not part of the BC promise of this library. + */ +final class MethodParameterFactory { /** * Formats the given default value to a string-able mixin + * + * @param mixed $defaultValue + * @return string */ public function format($defaultValue): string { @@ -30,32 +36,36 @@ public function format($defaultValue): string return ''; } - protected function formatDouble(float $defaultValue): string + private function formatDouble(float $defaultValue): string { return var_export($defaultValue, true); } - protected function formatNull($defaultValue): string + /** + * @param mixed $defaultValue + * @return string + */ + private function formatNull($defaultValue): string { return 'null'; } - protected function formatInteger(int $defaultValue): string + private function formatInteger(int $defaultValue): string { return var_export($defaultValue, true); } - protected function formatString(string $defaultValue): string + private function formatString(string $defaultValue): string { return var_export($defaultValue, true); } - protected function formatBoolean(bool $defaultValue): string + private function formatBoolean(bool $defaultValue): string { return var_export($defaultValue, true); } - protected function formatArray(array $defaultValue): string + private function formatArray(array $defaultValue): string { $formatedValue = '['; @@ -74,7 +84,7 @@ protected function formatArray(array $defaultValue): string return $formatedValue; } - protected function formatObject(object $defaultValue): string + private function formatObject(object $defaultValue): string { return 'new '. get_class($defaultValue). '()'; } diff --git a/src/DocBlock/Tags/MethodParameter.php b/src/DocBlock/Tags/MethodParameter.php index 72d2c4a8..c50c87e3 100644 --- a/src/DocBlock/Tags/MethodParameter.php +++ b/src/DocBlock/Tags/MethodParameter.php @@ -25,10 +25,16 @@ final class MethodParameter private string $name; - private mixed $defaultValue; + /** + * @var mixed + */ + private $defaultValue; private const NO_DEFAULT_VALUE = '__NO_VALUE__'; + /** + * @param mixed $defaultValue + */ public function __construct( string $name, Type $type, From 54f9b11a4c891f996cb974853157fea609c3e247 Mon Sep 17 00:00:00 2001 From: Gautier DELEGLISE Date: Thu, 31 Oct 2024 10:05:00 +0100 Subject: [PATCH 07/10] Update MethodParameterFactory.php --- src/DocBlock/Tags/Factory/MethodParameterFactory.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/DocBlock/Tags/Factory/MethodParameterFactory.php b/src/DocBlock/Tags/Factory/MethodParameterFactory.php index 1cccde95..6de2051e 100644 --- a/src/DocBlock/Tags/Factory/MethodParameterFactory.php +++ b/src/DocBlock/Tags/Factory/MethodParameterFactory.php @@ -65,6 +65,10 @@ private function formatBoolean(bool $defaultValue): string return var_export($defaultValue, true); } + /** + * @param array $defaultValue + * @return string + */ private function formatArray(array $defaultValue): string { $formatedValue = '['; From 2b2242d32382c50c10909a794a5eab7843b89aca Mon Sep 17 00:00:00 2001 From: Gautier DELEGLISE Date: Fri, 1 Nov 2024 17:33:39 +0100 Subject: [PATCH 08/10] :bug: default value from phpstan --- src/DocBlock/Tags/Factory/MethodFactory.php | 2 +- src/DocBlock/Tags/MethodParameter.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/DocBlock/Tags/Factory/MethodFactory.php b/src/DocBlock/Tags/Factory/MethodFactory.php index 51dc0429..5d90759f 100644 --- a/src/DocBlock/Tags/Factory/MethodFactory.php +++ b/src/DocBlock/Tags/Factory/MethodFactory.php @@ -57,7 +57,7 @@ function (MethodTagValueParameterNode $param) use ($context) { ), $param->isReference, $param->isVariadic, - $param->defaultValue + $param->defaultValue === null ? MethodParameter::NO_DEFAULT_VALUE : (string) $param->defaultValue ); }, $tagValue->parameters diff --git a/src/DocBlock/Tags/MethodParameter.php b/src/DocBlock/Tags/MethodParameter.php index c50c87e3..2cb8177f 100644 --- a/src/DocBlock/Tags/MethodParameter.php +++ b/src/DocBlock/Tags/MethodParameter.php @@ -30,7 +30,7 @@ final class MethodParameter */ private $defaultValue; - private const NO_DEFAULT_VALUE = '__NO_VALUE__'; + public const NO_DEFAULT_VALUE = '__NO_VALUE__'; /** * @param mixed $defaultValue From f26d445de6a5b1268250e27b8c142e7850d1ca62 Mon Sep 17 00:00:00 2001 From: Gautier DELEGLISE Date: Sun, 3 Nov 2024 23:28:27 +0100 Subject: [PATCH 09/10] :recycle: revert get default value to string --- src/DocBlock/Tags/Factory/MethodParameterFactory.php | 2 +- src/DocBlock/Tags/MethodParameter.php | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/DocBlock/Tags/Factory/MethodParameterFactory.php b/src/DocBlock/Tags/Factory/MethodParameterFactory.php index 6de2051e..92ff69d2 100644 --- a/src/DocBlock/Tags/Factory/MethodParameterFactory.php +++ b/src/DocBlock/Tags/Factory/MethodParameterFactory.php @@ -66,7 +66,7 @@ private function formatBoolean(bool $defaultValue): string } /** - * @param array $defaultValue + * @param array $defaultValue * @return string */ private function formatArray(array $defaultValue): string diff --git a/src/DocBlock/Tags/MethodParameter.php b/src/DocBlock/Tags/MethodParameter.php index 2cb8177f..4cb2827a 100644 --- a/src/DocBlock/Tags/MethodParameter.php +++ b/src/DocBlock/Tags/MethodParameter.php @@ -69,9 +69,12 @@ public function isVariadic(): bool return $this->isVariadic; } - public function getDefaultValue(): mixed + public function getDefaultValue(): ?string { - return $this->defaultValue; + if (is_array($this->defaultValue)) { + return implode(',', $this->defaultValue); + } + return (string) $this->defaultValue; } public function __toString(): string @@ -80,6 +83,6 @@ public function __toString(): string ($this->isReference() ? '&' : '') . ($this->isVariadic() ? '...' : '') . '$' . $this->getName() . - ($this->getDefaultValue() !== self::NO_DEFAULT_VALUE ? (new MethodParameterFactory)->format($this->getDefaultValue()) : ''); + ($this->defaultValue !== self::NO_DEFAULT_VALUE ? (new MethodParameterFactory)->format($this->defaultValue) : ''); } } From 1ed543b2483bfb4940869434d2466a7b5f3ed7da Mon Sep 17 00:00:00 2001 From: Gautier DELEGLISE Date: Mon, 4 Nov 2024 08:24:17 +0100 Subject: [PATCH 10/10] :rotating_light: assure backward compatibility --- src/DocBlock/Tags/MethodParameter.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/DocBlock/Tags/MethodParameter.php b/src/DocBlock/Tags/MethodParameter.php index 4cb2827a..06fc054d 100644 --- a/src/DocBlock/Tags/MethodParameter.php +++ b/src/DocBlock/Tags/MethodParameter.php @@ -71,6 +71,9 @@ public function isVariadic(): bool public function getDefaultValue(): ?string { + if ($this->defaultValue === static::NO_DEFAULT_VALUE) { + return null; + } if (is_array($this->defaultValue)) { return implode(',', $this->defaultValue); }