X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fpsy%2Fpsysh%2Fsrc%2FCodeCleaner%2FListPass.php;fp=vendor%2Fpsy%2Fpsysh%2Fsrc%2FCodeCleaner%2FListPass.php;h=0b44082cdb017c8bdbccf3c42a51435d159687de;hp=0000000000000000000000000000000000000000;hb=419f97be044f1aebd0713921ee604841127e9e84;hpb=052617e40b525f8b817d84c29b1c04951f427069 diff --git a/vendor/psy/psysh/src/CodeCleaner/ListPass.php b/vendor/psy/psysh/src/CodeCleaner/ListPass.php new file mode 100644 index 000000000..0b44082cd --- /dev/null +++ b/vendor/psy/psysh/src/CodeCleaner/ListPass.php @@ -0,0 +1,82 @@ +atLeastPhp71 = version_compare(PHP_VERSION, '7.1', '>='); + } + + /** + * Validate use of list assignment. + * + * @throws ParseErrorException if the user used empty with anything but a variable + * + * @param Node $node + */ + public function enterNode(Node $node) + { + if (!$node instanceof Assign) { + return; + } + + if (!$node->var instanceof Array_ && !$node->var instanceof List_) { + return; + } + + if (!$this->atLeastPhp71 && $node->var instanceof Array_) { + $msg = "syntax error, unexpected '='"; + throw new ParseErrorException($msg, $node->expr->getLine()); + } + + // Polyfill for PHP-Parser 2.x + $items = isset($node->var->items) ? $node->var->items : $node->var->vars; + + if ($items === [] || $items === [null]) { + throw new ParseErrorException('Cannot use empty list', $node->var->getLine()); + } + + foreach ($items as $item) { + if ($item === null) { + throw new ParseErrorException('Cannot use empty list', $item->getLine()); + } + + // List_->$vars in PHP-Parser 2.x is Variable instead of ArrayItem. + if (!$this->atLeastPhp71 && $item instanceof ArrayItem && $item->key !== null) { + $msg = 'Syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting \',\' or \')\''; + throw new ParseErrorException($msg, $item->key->getLine()); + } + + $value = ($item instanceof ArrayItem) ? $item->value : $item; + + if (!$value instanceof Variable) { + $msg = 'Assignments can only happen to writable values'; + throw new ParseErrorException($msg, $item->getLine()); + } + } + } +}