Skip to content
This repository was archived by the owner on Jan 31, 2020. It is now read-only.

Commit e15b18c

Browse files
committed
Optimize check count placeholder container items count.
1 parent 06642a0 commit e15b18c

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

src/Helper/Placeholder/Container/AbstractContainer.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,21 +113,19 @@ public function __toString()
113113
*/
114114
public function toString($indent = null)
115115
{
116-
$indent = ($indent !== null)
117-
? $this->getWhitespace($indent)
118-
: $this->getIndent();
119-
120116
// If we don't have items - do not show prefix and postfix
121117
if (!$this->count()) {
122118
return '';
123119
}
124120

125-
$itemsToString = implode($this->getSeparator(), $this->getArrayCopy());
126-
// todo check empty $itemsToString after trim() to return ''
121+
$indent = ($indent !== null)
122+
? $this->getWhitespace($indent)
123+
: $this->getIndent();
127124

125+
$items = $this->getArrayCopy();
128126
$return = $indent
129127
. $this->getPrefix()
130-
. $itemsToString
128+
. implode($this->getSeparator(), $items)
131129
. $this->getPostfix();
132130
$return = preg_replace("/(\r\n?|\n)/", '$1' . $indent, $return);
133131

test/Helper/Placeholder/ContainerTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,4 +441,13 @@ public function testNoUsePrefixPostfixIfNoItems()
441441
$this->assertEquals('', $string);
442442
}
443443

444+
public function testUsePrefixPostfixIfEmptyItems()
445+
{
446+
$this->container->setPrefix("<h1>")
447+
->setPostfix("</h1>");
448+
$this->container->set('');
449+
$string = $this->container->toString();
450+
$this->assertEquals('<h1></h1>', $string);
451+
}
452+
444453
}

0 commit comments

Comments
 (0)