comparison vendor/psy/psysh/src/CodeCleaner/LegacyEmptyPass.php @ 13:5fb285c0d0e3

Update Drupal core to 8.4.7 via Composer. Security update; I *think* we've been lucky to get away with this so far, as we don't support self-registration which seems to be used by the so-called "drupalgeddon 2" attack that 8.4.5 was vulnerable to.
author Chris Cannam
date Mon, 23 Apr 2018 09:33:26 +0100
parents
children c2387f117808
comparison
equal deleted inserted replaced
12:7a779792577d 13:5fb285c0d0e3
1 <?php
2
3 /*
4 * This file is part of Psy Shell.
5 *
6 * (c) 2012-2018 Justin Hileman
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 namespace Psy\CodeCleaner;
13
14 use PhpParser\Node;
15 use PhpParser\Node\Expr\Empty_;
16 use PhpParser\Node\Expr\Variable;
17 use Psy\Exception\ParseErrorException;
18
19 /**
20 * Validate that the user did not call the language construct `empty()` on a
21 * statement in PHP < 5.5.
22 */
23 class LegacyEmptyPass extends CodeCleanerPass
24 {
25 private $atLeastPhp55;
26
27 public function __construct()
28 {
29 $this->atLeastPhp55 = version_compare(PHP_VERSION, '5.5', '>=');
30 }
31
32 /**
33 * Validate use of empty in PHP < 5.5.
34 *
35 * @throws ParseErrorException if the user used empty with anything but a variable
36 *
37 * @param Node $node
38 */
39 public function enterNode(Node $node)
40 {
41 if ($this->atLeastPhp55) {
42 return;
43 }
44
45 if (!$node instanceof Empty_) {
46 return;
47 }
48
49 if (!$node->expr instanceof Variable) {
50 $msg = sprintf('syntax error, unexpected %s', $this->getUnexpectedThing($node->expr));
51
52 throw new ParseErrorException($msg, $node->expr->getLine());
53 }
54 }
55
56 private function getUnexpectedThing(Node $node)
57 {
58 switch ($node->getType()) {
59 case 'Scalar_String':
60 case 'Scalar_LNumber':
61 case 'Scalar_DNumber':
62 return json_encode($node->value);
63
64 case 'Expr_ConstFetch':
65 return (string) $node->name;
66
67 default:
68 return $node->getType();
69 }
70 }
71 }