Skip to content

Commit

Permalink
Merge pull request #111 from phug-php/feature/multi-tester-3
Browse files Browse the repository at this point in the history
Use multi-tester 2.5

split: 44978d6c0f5d5245cd8b9988002d117ea9ebdd04
  • Loading branch information
kylekatarnls authored Sep 21, 2023
1 parent fc8e3a0 commit 6568257
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 6 additions & 0 deletions Formatter/Format/XmlFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,19 +167,23 @@ protected function formatAttributeElement(AttributeElement $element)
$value = $element->getValue();
$name = $element->getName();
$nonEmptyAttribute = ($name === 'class' || $name === 'id');

if ($nonEmptyAttribute && (
!$value ||
($value instanceof TextElement && ((string) $value->getValue()) === '') ||
(is_string($value) && in_array(trim($value), ['', '""', "''"], true))
)) {
return '';
}

if ($value instanceof ExpressionElement) {
if ($nonEmptyAttribute && in_array(trim($value->getValue()), ['', '""', "''"], true)) {
return '';
}

if (strtolower($value->getValue()) === 'true') {
$formattedValue = null;

if ($name instanceof ExpressionElement) {
$bufferVariable = $this->pattern('buffer_variable');
$name = $this->pattern(
Expand All @@ -193,6 +197,7 @@ protected function formatAttributeElement(AttributeElement $element)
$value = new ExpressionElement($bufferVariable);
$formattedValue = $this->format($value);
}

$formattedName = $this->format($name);
$formattedValue = $formattedValue || $formattedValue === '0'
? $formattedValue
Expand All @@ -204,6 +209,7 @@ protected function formatAttributeElement(AttributeElement $element)
$formattedValue
);
}

if (in_array(strtolower($value->getValue()), ['false', 'null', 'undefined'], true)) {
return '';
}
Expand Down
8 changes: 1 addition & 7 deletions Formatter/Partial/MagicAccessorTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,7 @@ trait MagicAccessorTrait
{
private function getMethod($prefix, $name)
{
switch ($name) {
case 'nodes':
$name = 'children';
break;
}

return $prefix.ucfirst($name);
return $prefix.ucfirst($name === 'nodes' ? 'children' : $name);
}

public function __get($name)
Expand Down

0 comments on commit 6568257

Please sign in to comment.