Mercurial > hg > isophonics-drupal-site
comparison vendor/nikic/php-parser/lib/PhpParser/NodeDumper.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 | 4c8ae668cc8c |
children |
comparison
equal
deleted
inserted
replaced
12:7a779792577d | 13:5fb285c0d0e3 |
---|---|
1 <?php | 1 <?php declare(strict_types=1); |
2 | 2 |
3 namespace PhpParser; | 3 namespace PhpParser; |
4 | 4 |
5 use PhpParser\Node\Expr\Include_; | 5 use PhpParser\Node\Expr\Include_; |
6 use PhpParser\Node\Stmt\Class_; | 6 use PhpParser\Node\Stmt\Class_; |
37 * the dumpPositions option is enabled and the dumping of node offsets | 37 * the dumpPositions option is enabled and the dumping of node offsets |
38 * is desired. | 38 * is desired. |
39 * | 39 * |
40 * @return string Dumped value | 40 * @return string Dumped value |
41 */ | 41 */ |
42 public function dump($node, $code = null) { | 42 public function dump($node, string $code = null) : string { |
43 $this->code = $code; | 43 $this->code = $code; |
44 return $this->dumpRecursive($node); | 44 return $this->dumpRecursive($node); |
45 } | 45 } |
46 | 46 |
47 protected function dumpRecursive($node) { | 47 protected function dumpRecursive($node) { |
63 } elseif (true === $value) { | 63 } elseif (true === $value) { |
64 $r .= 'true'; | 64 $r .= 'true'; |
65 } elseif (is_scalar($value)) { | 65 } elseif (is_scalar($value)) { |
66 if ('flags' === $key || 'newModifier' === $key) { | 66 if ('flags' === $key || 'newModifier' === $key) { |
67 $r .= $this->dumpFlags($value); | 67 $r .= $this->dumpFlags($value); |
68 } else if ('type' === $key && $node instanceof Include_) { | 68 } elseif ('type' === $key && $node instanceof Include_) { |
69 $r .= $this->dumpIncludeType($value); | 69 $r .= $this->dumpIncludeType($value); |
70 } else if ('type' === $key | 70 } elseif ('type' === $key |
71 && ($node instanceof Use_ || $node instanceof UseUse || $node instanceof GroupUse)) { | 71 && ($node instanceof Use_ || $node instanceof UseUse || $node instanceof GroupUse)) { |
72 $r .= $this->dumpUseType($value); | 72 $r .= $this->dumpUseType($value); |
73 } else { | 73 } else { |
74 $r .= $value; | 74 $r .= $value; |
75 } | 75 } |
76 } else { | 76 } else { |
77 $r .= str_replace("\n", "\n ", $this->dumpRecursive($value)); | 77 $r .= str_replace("\n", "\n ", $this->dumpRecursive($value)); |
78 } | 78 } |
79 } | 79 } |
80 | 80 |
81 if ($this->dumpComments && $comments = $node->getAttribute('comments')) { | 81 if ($this->dumpComments && $comments = $node->getComments()) { |
82 $r .= "\n comments: " . str_replace("\n", "\n ", $this->dumpRecursive($comments)); | 82 $r .= "\n comments: " . str_replace("\n", "\n ", $this->dumpRecursive($comments)); |
83 } | 83 } |
84 } elseif (is_array($node)) { | 84 } elseif (is_array($node)) { |
85 $r = 'array('; | 85 $r = 'array('; |
86 | 86 |
139 protected function dumpIncludeType($type) { | 139 protected function dumpIncludeType($type) { |
140 $map = [ | 140 $map = [ |
141 Include_::TYPE_INCLUDE => 'TYPE_INCLUDE', | 141 Include_::TYPE_INCLUDE => 'TYPE_INCLUDE', |
142 Include_::TYPE_INCLUDE_ONCE => 'TYPE_INCLUDE_ONCE', | 142 Include_::TYPE_INCLUDE_ONCE => 'TYPE_INCLUDE_ONCE', |
143 Include_::TYPE_REQUIRE => 'TYPE_REQUIRE', | 143 Include_::TYPE_REQUIRE => 'TYPE_REQUIRE', |
144 Include_::TYPE_REQUIRE_ONCE => 'TYPE_REQURE_ONCE', | 144 Include_::TYPE_REQUIRE_ONCE => 'TYPE_REQUIRE_ONCE', |
145 ]; | 145 ]; |
146 | 146 |
147 if (!isset($map[$type])) { | 147 if (!isset($map[$type])) { |
148 return $type; | 148 return $type; |
149 } | 149 } |
162 return $type; | 162 return $type; |
163 } | 163 } |
164 return $map[$type] . ' (' . $type . ')'; | 164 return $map[$type] . ' (' . $type . ')'; |
165 } | 165 } |
166 | 166 |
167 /** | |
168 * Dump node position, if possible. | |
169 * | |
170 * @param Node $node Node for which to dump position | |
171 * | |
172 * @return string|null Dump of position, or null if position information not available | |
173 */ | |
167 protected function dumpPosition(Node $node) { | 174 protected function dumpPosition(Node $node) { |
168 if (!$node->hasAttribute('startLine') || !$node->hasAttribute('endLine')) { | 175 if (!$node->hasAttribute('startLine') || !$node->hasAttribute('endLine')) { |
169 return null; | 176 return null; |
170 } | 177 } |
171 | 178 |
172 $start = $node->getAttribute('startLine'); | 179 $start = $node->getStartLine(); |
173 $end = $node->getAttribute('endLine'); | 180 $end = $node->getEndLine(); |
174 if ($node->hasAttribute('startFilePos') && $node->hasAttribute('endFilePos') | 181 if ($node->hasAttribute('startFilePos') && $node->hasAttribute('endFilePos') |
175 && null !== $this->code | 182 && null !== $this->code |
176 ) { | 183 ) { |
177 $start .= ':' . $this->toColumn($this->code, $node->getAttribute('startFilePos')); | 184 $start .= ':' . $this->toColumn($this->code, $node->getStartFilePos()); |
178 $end .= ':' . $this->toColumn($this->code, $node->getAttribute('endFilePos')); | 185 $end .= ':' . $this->toColumn($this->code, $node->getEndFilePos()); |
179 } | 186 } |
180 return "[$start - $end]"; | 187 return "[$start - $end]"; |
181 } | 188 } |
182 | 189 |
183 // Copied from Error class | 190 // Copied from Error class |