Skip to content

Commit

Permalink
Fix iterable return type
Browse files Browse the repository at this point in the history
Currently, the PHPDoc states that a string should be returned, but that's not correct.

It can be anything that is echo-able.

That means any scalar, Stringable and even null.
  • Loading branch information
ruudk committed Sep 5, 2024
1 parent 83c5415 commit 4cd8955
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/Node/BlockNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function compile(Compiler $compiler): void
$compiler
->addDebugInfo($this)
->write("/**\n")
->write(" * @return iterable<string>\n")
->write(" * @return iterable<null|scalar|\Stringable>\n")
->write(" */\n")
->write(\sprintf("public function block_%s(array \$context, array \$blocks = []): iterable\n", $this->getAttribute('name')), "{\n")
->indent()
Expand Down
8 changes: 4 additions & 4 deletions src/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ public function render(array $context): string
}

/**
* @return iterable<string>
* @return iterable<null|scalar|\Stringable>
*/
public function yield(array $context, array $blocks = []): iterable
{
Expand Down Expand Up @@ -412,7 +412,7 @@ public function yield(array $context, array $blocks = []): iterable
}

/**
* @return iterable<string>
* @return iterable<null|scalar|\Stringable>
*/
public function yieldBlock($name, array $context, array $blocks = [], $useBlocks = true, ?self $templateContext = null): iterable
{
Expand Down Expand Up @@ -472,7 +472,7 @@ public function yieldBlock($name, array $context, array $blocks = [], $useBlocks
* @param array $context The context
* @param array $blocks The current set of blocks
*
* @return iterable<string>
* @return iterable<null|scalar|\Stringable>
*/
public function yieldParentBlock($name, array $context, array $blocks = []): iterable
{
Expand All @@ -491,7 +491,7 @@ public function yieldParentBlock($name, array $context, array $blocks = []): ite
* @param array $context An array of parameters to pass to the template
* @param array $blocks An array of blocks to pass to the template
*
* @return iterable<string>
* @return iterable<null|scalar|\Stringable>
*/
abstract protected function doDisplay(array $context, array $blocks = []): iterable;
}
2 changes: 1 addition & 1 deletion tests/Node/BlockTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static function provideTests(): iterable
$tests[] = [new BlockNode('foo', new TextNode('foo', 1), 1), <<<EOF
// line 1
/**
* @return iterable<string>
* @return iterable<null|scalar|\Stringable>
*/
public function block_foo(array \$context, array \$blocks = []): iterable
{
Expand Down

0 comments on commit 4cd8955

Please sign in to comment.