From b00e0add1ee6acee232d56f75cf2d6bf0f76e2f5 Mon Sep 17 00:00:00 2001 From: aloiret Date: Wed, 1 May 2019 18:54:13 +0200 Subject: [PATCH] Remove usages of lval as an expression. (#196) Summary: required for .hhconfig disable_lval_as_an_expression. Signed-off-by: Arthur Loiret --- src/core/ComposableElement.php | 3 ++- src/html/XHPBaseHTMLHelpers.php | 3 ++- src/html/XHPHelpers.php | 16 ++++++++-------- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/core/ComposableElement.php b/src/core/ComposableElement.php index 47483b94..c47007c1 100644 --- a/src/core/ComposableElement.php +++ b/src/core/ComposableElement.php @@ -797,7 +797,8 @@ final public function __getChildrenDescription(): string { foreach ($this->children as $child) { if ($child instanceof :xhp) { $tmp = ':'.:xhp::class2element(get_class($child)); - if ($categories = $child->__xhpCategoryDeclaration()) { + $categories = $child->__xhpCategoryDeclaration(); + if (C\count($categories) > 0) { $tmp .= '[%'.implode(',%', array_keys($categories)).']'; } $desc[] = $tmp; diff --git a/src/html/XHPBaseHTMLHelpers.php b/src/html/XHPBaseHTMLHelpers.php index 91f69eee..9f3f4928 100644 --- a/src/html/XHPBaseHTMLHelpers.php +++ b/src/html/XHPBaseHTMLHelpers.php @@ -45,7 +45,8 @@ public function requireUniqueID(): string { $id = /* UNSAFE_EXPR */ $this->:id; if ($id === null || $id === '') { try { - $this->setAttribute('id', $id = bin2hex(random_bytes(5))); + $id = bin2hex(random_bytes(5)); + $this->setAttribute('id', $id); } catch (XHPInvalidAttributeException $error) { throw new XHPException( 'You are trying to add an HTML id to a(n) '. diff --git a/src/html/XHPHelpers.php b/src/html/XHPHelpers.php index 6976fa24..8c92a6f1 100644 --- a/src/html/XHPHelpers.php +++ b/src/html/XHPHelpers.php @@ -182,15 +182,15 @@ final public function transferAttributesToRenderedRoot( foreach ($this->getAttributeNamesThatAppendValuesOnTransfer() as $attr) { if (array_key_exists($attr, $attributes)) { $rootAttributes = $root->getAttributes(); - if ( - array_key_exists($attr, $rootAttributes) && - ($rootValue = (string)$rootAttributes[$attr]) !== '' - ) { - $thisValue = (string)$attributes[$attr]; - if ($thisValue !== '') { - $root->setAttribute($attr, $rootValue.' '.$thisValue); + if (array_key_exists($attr, $rootAttributes)) { + $rootValue = (string)$rootAttributes[$attr]; + if ($rootValue !== '') { + $thisValue = (string)$attributes[$attr]; + if ($thisValue !== '') { + $root->setAttribute($attr, $rootValue.' '.$thisValue); + } + $this->removeAttribute($attr); } - $this->removeAttribute($attr); } } }