Skip to content

Commit

Permalink
fix: TypeExpression - do not break type using walkTypes method (P…
Browse files Browse the repository at this point in the history
  • Loading branch information
kubawerlos authored and danog committed Feb 2, 2024
1 parent 860b721 commit 6c9263a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/DocBlock/TypeExpression.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ public function getTypesGlue(): string
*/
public function walkTypes(\Closure $callback): void
{
foreach ($this->innerTypeExpressions as [
foreach (array_reverse($this->innerTypeExpressions) as [
'start_index' => $startIndex,
'expression' => $inner,
]) {
Expand Down
18 changes: 18 additions & 0 deletions tests/DocBlock/TypeExpressionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,24 @@ public static function provideAllowsNullCases(): iterable
yield ['?\Closure(): void', true];
}

public function testWalkTypes(): void
{
$typeExpression = new TypeExpression('Foo|Bar|Baz', null, []);
$addLeadingSlash = static function (TypeExpression $type): void {
\Closure::bind(static function () use ($type): void {
$value = $type->toString();
if (!str_starts_with($value, '\\')) {
$value = '\\'.$value;
}
$type->value = $value;
}, null, TypeExpression::class)();
};

$typeExpression->walkTypes($addLeadingSlash);

self::assertSame('\Foo|\Bar|\Baz', $typeExpression->toString());
}

/**
* @dataProvider provideSortTypesCases
*/
Expand Down

0 comments on commit 6c9263a

Please sign in to comment.