Skip to content
This repository was archived by the owner on Apr 1, 2024. It is now read-only.

Commit 64c02b5

Browse files
committed
instanceof -> is
fully handled by hhast now; manually fixed up a new error - we had nonnull, but know it's an XHPChild closes #197
1 parent 80dd47f commit 64c02b5

File tree

7 files changed

+25
-25
lines changed

7 files changed

+25
-25
lines changed

src/core/ComposableElement.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ final public function __construct(
4646
foreach ($attributes as $key => $value) {
4747
if (self::isSpreadKey($key)) {
4848
invariant(
49-
$value instanceof :x:composable-element,
49+
$value is :x:composable-element,
5050
"Only XHP can be used with an attribute spread operator",
5151
);
5252
$this->spreadElementImpl($value);
@@ -78,14 +78,14 @@ final public function __construct(
7878
* @param $child single child or array of children
7979
*/
8080
final public function appendChild(mixed $child): this {
81-
if ($child instanceof Traversable) {
81+
if ($child is Traversable<_>) {
8282
foreach ($child as $c) {
8383
$this->appendChild($c);
8484
}
85-
} else if ($child instanceof :x:frag) {
85+
} else if ($child is :x:frag) {
8686
$this->children->addAll($child->getChildren());
8787
} else if ($child !== null) {
88-
assert($child instanceof XHPChild);
88+
assert($child is XHPChild);
8989
$this->children->add($child);
9090
}
9191
return $this;
@@ -116,20 +116,20 @@ final public function replaceChildren(XHPChild ...$children): this {
116116
$new_children = Vector {};
117117
foreach ($children as $xhp) {
118118
/* HH_FIXME[4273] bogus "XHPChild always truthy" - FB T41388073 */
119-
if ($xhp instanceof :x:frag) {
119+
if ($xhp is :x:frag) {
120120
foreach ($xhp->children as $child) {
121121
$new_children->add($child);
122122
}
123-
} else if (!($xhp instanceof Traversable)) {
123+
} else if (!($xhp is Traversable<_>)) {
124124
$new_children->add($xhp);
125125
} else {
126126
foreach ($xhp as $element) {
127-
if ($element instanceof :x:frag) {
127+
if ($element is :x:frag) {
128128
foreach ($element->children as $child) {
129129
$new_children->add($child);
130130
}
131131
} else if ($element !== null) {
132-
$new_children->add($element);
132+
$new_children->add($element as XHPChild);
133133
}
134134
}
135135
}
@@ -153,7 +153,7 @@ final public function getChildren(
153153
if ($selector[0] == '%') {
154154
$selector = substr($selector, 1);
155155
foreach ($this->children as $child) {
156-
if ($child instanceof :xhp && $child->categoryOf($selector)) {
156+
if ($child is :xhp && $child->categoryOf($selector)) {
157157
$children->add($child);
158158
}
159159
}
@@ -186,7 +186,7 @@ final public function getFirstChild(?string $selector = null): ?XHPChild {
186186
} else if ($selector[0] == '%') {
187187
$selector = substr($selector, 1);
188188
foreach ($this->children as $child) {
189-
if ($child instanceof :xhp && $child->categoryOf($selector)) {
189+
if ($child is :xhp && $child->categoryOf($selector)) {
190190
return $child;
191191
}
192192
}
@@ -735,7 +735,7 @@ final private function validateChildrenRule(
735735
case XHPChildrenConstraintType::PCDATA:
736736
if (
737737
$this->children->containsKey($index) &&
738-
!($this->children->get($index) instanceof :xhp)
738+
!($this->children->get($index) is :xhp)
739739
) {
740740
return tuple(true, $index + 1);
741741
}
@@ -754,13 +754,13 @@ final private function validateChildrenRule(
754754
case XHPChildrenConstraintType::CATEGORY:
755755
if (
756756
!$this->children->containsKey($index) ||
757-
!($this->children->get($index) instanceof :xhp)
757+
!($this->children->get($index) is :xhp)
758758
) {
759759
return tuple(false, $index);
760760
}
761761
$category = :xhp::class2element($expr->getConstraintString());
762762
$child = $this->children->get($index);
763-
assert($child instanceof :xhp);
763+
assert($child is :xhp);
764764
$categories = $child->__xhpCategoryDeclaration();
765765
if (($categories[$category] ?? 0) === 0) {
766766
return tuple(false, $index);
@@ -795,7 +795,7 @@ public function __getChildrenDeclaration(): string {
795795
final public function __getChildrenDescription(): string {
796796
$desc = array();
797797
foreach ($this->children as $child) {
798-
if ($child instanceof :xhp) {
798+
if ($child is :xhp) {
799799
$tmp = ':'.:xhp::class2element(get_class($child));
800800
$categories = $child->__xhpCategoryDeclaration();
801801
if (C\count($categories) > 0) {

src/core/Element.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ final public function toString(): string {
4545
}
4646

4747
$composed->__transferContext($this->getAllContexts());
48-
if ($this instanceof XHPHasTransferAttributes) {
48+
if ($this is XHPHasTransferAttributes) {
4949
$this->transferAttributesToRenderedRoot($composed);
5050
}
5151

@@ -56,11 +56,11 @@ final public function toString(): string {
5656
): Awaitable<:x:primitive> {
5757
$that = $this;
5858
// Flush root elements returned from render() to an :x:primitive
59-
while ($that instanceof :x:element) {
59+
while ($that is :x:element) {
6060
$that = await $that->__renderAndProcess();
6161
}
6262

63-
if ($that instanceof :x:primitive) {
63+
if ($that is :x:primitive) {
6464
return $that;
6565
}
6666

src/core/Primitive.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ final public function toString(): string {
3030
$children = $this->getChildren();
3131
$awaitables = Map {};
3232
foreach ($children as $idx => $child) {
33-
if ($child instanceof :x:composable-element) {
33+
if ($child is :x:composable-element) {
3434
$child->__transferContext($this->getAllContexts());
3535
$awaitables[$idx] = $child->__flushSubtree();
3636
}

src/core/XHP.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,13 @@ final public function jsonSerialize(): string {
8989
}
9090

9191
final protected static function renderChild(XHPChild $child): string {
92-
if ($child instanceof :xhp) {
92+
if ($child is :xhp) {
9393
return $child->toString();
9494
}
95-
if ($child instanceof XHPUnsafeRenderable) {
95+
if ($child is XHPUnsafeRenderable) {
9696
return $child->toHTMLString();
9797
}
98-
if ($child instanceof Traversable) {
98+
if ($child is Traversable<_>) {
9999
throw new XHPRenderArrayException('Can not render traversables!');
100100
}
101101

src/core/XHPAttributeCoercion.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public static function CoerceToString(
6565
mixed $val,
6666
): string {
6767
self::LogCoercion($context, 'string', $attr, $val);
68-
if (($val is int) || ($val is float) || $val instanceof Stringish) {
68+
if (($val is int) || ($val is float) || $val is Stringish) {
6969
return (string)$val;
7070
}
7171

src/html/Element.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ protected final function renderBaseAttrs(): string {
118118
if ($val === true) {
119119
$buf .= ' '.htmlspecialchars($key);
120120
} else {
121-
if ($val instanceof XHPUnsafeAttributeValue) {
121+
if ($val is XHPUnsafeAttributeValue) {
122122
$val_str = $val->toHTMLString();
123123
} else {
124124
$val_str = htmlspecialchars((string) $val, ENT_COMPAT);

src/html/XHPHelpers.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@ protected function getAttributeNamesThatAppendValuesOnTransfer(
145145
final public function transferAttributesToRenderedRoot(
146146
:x:composable-element $root,
147147
): void {
148-
if (:xhp::isAttributeValidationEnabled() && $root instanceof :x:element) {
149-
if (!($root instanceof HasXHPHelpers)) {
148+
if (:xhp::isAttributeValidationEnabled() && $root is :x:element) {
149+
if (!($root is HasXHPHelpers)) {
150150
throw new XHPClassException(
151151
$this,
152152
'render() must return an object using the XHPHelpers trait.',

0 commit comments

Comments
 (0)