diff --git a/lib/Less/Functions.php b/lib/Less/Functions.php index e958e77c..86595f7e 100644 --- a/lib/Less/Functions.php +++ b/lib/Less/Functions.php @@ -697,9 +697,7 @@ private function _minmax( $isMin, $args ) { for ( $i = 0; $i < $arg_count; $i++ ) { $current = $args[$i]; if ( !( $current instanceof Less_Tree_Dimension ) ) { - // @phan-suppress-next-line PhanUndeclaredProperty Checked Less_Tree->value - if ( property_exists( $args[$i], 'value' ) && is_array( $args[$i]->value ) ) { - // @phan-suppress-next-line PhanUndeclaredProperty Checked Less_Tree->value + if ( $args[$i] instanceof Less_Tree_HasValueProperty && is_array( $args[$i]->value ) ) { $args[] = $args[$i]->value; } continue; @@ -842,8 +840,7 @@ public function isem( $n ) { * @param Less_Tree|string $unit */ public function isunit( $n, $unit ) { - if ( is_object( $unit ) && property_exists( $unit, 'value' ) ) { - // @phan-suppress-next-line PhanUndeclaredProperty Checked Less_Tree->value + if ( $unit instanceof Less_Tree_HasValueProperty ) { $unit = $unit->value; } @@ -870,7 +867,7 @@ public function extract( $values, $index ) { $index = (int)$index->value - 1; // (1-based index) // handle non-array values as an array of length 1 // return 'undefined' if index is invalid - if ( property_exists( $values, 'value' ) && is_array( $values->value ) ) { + if ( $values instanceof Less_Tree_HasValueProperty && is_array( $values->value ) ) { if ( isset( $values->value[$index] ) ) { return $values->value[$index]; } @@ -884,7 +881,8 @@ public function extract( $values, $index ) { } public function length( $values ) { - $n = ( property_exists( $values, 'value' ) && is_array( $values->value ) ) ? count( $values->value ) : 1; + $n = ( $values instanceof Less_Tree_HasValueProperty && is_array( $values->value ) ) ? + count( $values->value ) : 1; return new Less_Tree_Dimension( $n ); } @@ -1005,7 +1003,7 @@ public function svggradient( $direction ) { '<' . $gradientType . 'Gradient id="gradient" gradientUnits="userSpaceOnUse" ' . $gradientDirectionSvg . '>'; for ( $i = 0; $i < count( $stops ); $i++ ) { - if ( is_object( $stops[$i] ) && property_exists( $stops[$i], 'value' ) ) { + if ( $stops[$i] instanceof Less_Tree_HasValueProperty ) { $color = $stops[$i]->value[0]; $position = $stops[$i]->value[1]; } else { diff --git a/lib/Less/Parser.php b/lib/Less/Parser.php index e4690f37..f5a34c48 100644 --- a/lib/Less/Parser.php +++ b/lib/Less/Parser.php @@ -1508,7 +1508,7 @@ private function parseMixinArgs( $isCall ) { if ( $isCall ) { // Variable - if ( property_exists( $arg, 'value' ) && count( $arg->value ) == 1 ) { + if ( $value instanceof Less_Tree_HasValueProperty && count( $arg->value ) == 1 ) { $val = $arg->value[0]; } } else { diff --git a/lib/Less/Tree.php b/lib/Less/Tree.php index bbb2bd99..f5ec816d 100644 --- a/lib/Less/Tree.php +++ b/lib/Less/Tree.php @@ -2,12 +2,6 @@ /** * Tree - * - * TODO: Callers often use `property_exists(, 'value')` to distinguish - * tree nodes that are considerd value-holding. Refactor this to move - * the 'value' property that most subclasses implement to there, and use - * something else (special value, method, or intermediate class?) to - * signal whether a subclass is considered value-holding. */ class Less_Tree { diff --git a/lib/Less/Tree/Alpha.php b/lib/Less/Tree/Alpha.php index b00bf392..50a7a9a7 100644 --- a/lib/Less/Tree/Alpha.php +++ b/lib/Less/Tree/Alpha.php @@ -2,7 +2,7 @@ /** * @private */ -class Less_Tree_Alpha extends Less_Tree { +class Less_Tree_Alpha extends Less_Tree implements Less_Tree_HasValueProperty { public $value; public function __construct( $val ) { diff --git a/lib/Less/Tree/Anonymous.php b/lib/Less/Tree/Anonymous.php index 20e31b06..84e93a88 100644 --- a/lib/Less/Tree/Anonymous.php +++ b/lib/Less/Tree/Anonymous.php @@ -2,7 +2,7 @@ /** * @private */ -class Less_Tree_Anonymous extends Less_Tree { +class Less_Tree_Anonymous extends Less_Tree implements Less_Tree_HasValueProperty { public $value; public $quote; public $index; diff --git a/lib/Less/Tree/Assignment.php b/lib/Less/Tree/Assignment.php index 814bd5a3..c17133cf 100644 --- a/lib/Less/Tree/Assignment.php +++ b/lib/Less/Tree/Assignment.php @@ -2,7 +2,7 @@ /** * @private */ -class Less_Tree_Assignment extends Less_Tree { +class Less_Tree_Assignment extends Less_Tree implements Less_Tree_HasValueProperty { public $key; public $value; diff --git a/lib/Less/Tree/Attribute.php b/lib/Less/Tree/Attribute.php index f0f5d530..41c89acb 100644 --- a/lib/Less/Tree/Attribute.php +++ b/lib/Less/Tree/Attribute.php @@ -2,7 +2,7 @@ /** * @private */ -class Less_Tree_Attribute extends Less_Tree { +class Less_Tree_Attribute extends Less_Tree implements Less_Tree_HasValueProperty { public $key; public $op; diff --git a/lib/Less/Tree/Call.php b/lib/Less/Tree/Call.php index 3ce74edd..af0e95f0 100644 --- a/lib/Less/Tree/Call.php +++ b/lib/Less/Tree/Call.php @@ -3,7 +3,7 @@ * @private * @see less.tree.Call in less.js 3.0.0 https://github.com/less/less.js/blob/v3.0.0/dist/less.js#L6336 */ -class Less_Tree_Call extends Less_Tree { +class Less_Tree_Call extends Less_Tree implements Less_Tree_HasValueProperty { public $value; public $name; diff --git a/lib/Less/Tree/Comment.php b/lib/Less/Tree/Comment.php index 8f4d8ee6..98a54366 100644 --- a/lib/Less/Tree/Comment.php +++ b/lib/Less/Tree/Comment.php @@ -2,7 +2,7 @@ /** * @private */ -class Less_Tree_Comment extends Less_Tree { +class Less_Tree_Comment extends Less_Tree implements Less_Tree_HasValueProperty { public $value; public $silent; diff --git a/lib/Less/Tree/Dimension.php b/lib/Less/Tree/Dimension.php index 7f3d063c..4c1e200d 100644 --- a/lib/Less/Tree/Dimension.php +++ b/lib/Less/Tree/Dimension.php @@ -2,7 +2,7 @@ /** * @private */ -class Less_Tree_Dimension extends Less_Tree { +class Less_Tree_Dimension extends Less_Tree implements Less_Tree_HasValueProperty { public $value; public $unit; diff --git a/lib/Less/Tree/Directive.php b/lib/Less/Tree/Directive.php index f5c88cf3..289f3942 100644 --- a/lib/Less/Tree/Directive.php +++ b/lib/Less/Tree/Directive.php @@ -2,7 +2,7 @@ /** * @private */ -class Less_Tree_Directive extends Less_Tree { +class Less_Tree_Directive extends Less_Tree implements Less_Tree_HasValueProperty { public $name; public $value; diff --git a/lib/Less/Tree/Element.php b/lib/Less/Tree/Element.php index 2c69bcc6..784cc6c8 100644 --- a/lib/Less/Tree/Element.php +++ b/lib/Less/Tree/Element.php @@ -2,7 +2,7 @@ /** * @private */ -class Less_Tree_Element extends Less_Tree { +class Less_Tree_Element extends Less_Tree implements Less_Tree_HasValueProperty { /** @var string */ public $combinator; diff --git a/lib/Less/Tree/Expression.php b/lib/Less/Tree/Expression.php index 6e928d77..cdabf390 100644 --- a/lib/Less/Tree/Expression.php +++ b/lib/Less/Tree/Expression.php @@ -2,7 +2,7 @@ /** * @private */ -class Less_Tree_Expression extends Less_Tree { +class Less_Tree_Expression extends Less_Tree implements Less_Tree_HasValueProperty { /** @var array */ public $value = []; public $parens = false; diff --git a/lib/Less/Tree/HasValueProperty.php b/lib/Less/Tree/HasValueProperty.php new file mode 100644 index 00000000..5dbf9c51 --- /dev/null +++ b/lib/Less/Tree/HasValueProperty.php @@ -0,0 +1,8 @@ +value, 'value' ) || !is_string( $v->value->value ) ) { + if ( !( $v->value instanceof Less_Tree_HasValueProperty ) || !is_string( $v->value->value ) ) { $this->cacheable = false; return; } diff --git a/lib/Less/Tree/UnicodeDescriptor.php b/lib/Less/Tree/UnicodeDescriptor.php index 03a4fb0b..cc1b39e1 100644 --- a/lib/Less/Tree/UnicodeDescriptor.php +++ b/lib/Less/Tree/UnicodeDescriptor.php @@ -2,7 +2,7 @@ /** * @private */ -class Less_Tree_UnicodeDescriptor extends Less_Tree { +class Less_Tree_UnicodeDescriptor extends Less_Tree implements Less_Tree_HasValueProperty { public $value; diff --git a/lib/Less/Tree/Url.php b/lib/Less/Tree/Url.php index 9732f26f..140153b1 100644 --- a/lib/Less/Tree/Url.php +++ b/lib/Less/Tree/Url.php @@ -2,7 +2,7 @@ /** * @private */ -class Less_Tree_Url extends Less_Tree { +class Less_Tree_Url extends Less_Tree implements Less_Tree_HasValueProperty { public $attrs; public $value; diff --git a/lib/Less/Tree/Value.php b/lib/Less/Tree/Value.php index 437cf3d7..88c89849 100644 --- a/lib/Less/Tree/Value.php +++ b/lib/Less/Tree/Value.php @@ -2,7 +2,7 @@ /** * @private */ -class Less_Tree_Value extends Less_Tree { +class Less_Tree_Value extends Less_Tree implements Less_Tree_HasValueProperty { public $value;