Mercurial > hg > isophonics-drupal-site
comparison vendor/nikic/php-parser/lib/PhpParser/Comment.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 class Comment implements \JsonSerializable | 5 class Comment implements \JsonSerializable |
6 { | 6 { |
7 protected $text; | 7 protected $text; |
8 protected $line; | 8 protected $line; |
9 protected $filePos; | 9 protected $filePos; |
10 protected $tokenPos; | |
10 | 11 |
11 /** | 12 /** |
12 * Constructs a comment node. | 13 * Constructs a comment node. |
13 * | 14 * |
14 * @param string $text Comment text (including comment delimiters like /*) | 15 * @param string $text Comment text (including comment delimiters like /*) |
15 * @param int $startLine Line number the comment started on | 16 * @param int $startLine Line number the comment started on |
16 * @param int $startFilePos File offset the comment started on | 17 * @param int $startFilePos File offset the comment started on |
18 * @param int $startTokenPos Token offset the comment started on | |
17 */ | 19 */ |
18 public function __construct($text, $startLine = -1, $startFilePos = -1) { | 20 public function __construct( |
21 string $text, int $startLine = -1, int $startFilePos = -1, int $startTokenPos = -1 | |
22 ) { | |
19 $this->text = $text; | 23 $this->text = $text; |
20 $this->line = $startLine; | 24 $this->line = $startLine; |
21 $this->filePos = $startFilePos; | 25 $this->filePos = $startFilePos; |
26 $this->tokenPos = $startTokenPos; | |
22 } | 27 } |
23 | 28 |
24 /** | 29 /** |
25 * Gets the comment text. | 30 * Gets the comment text. |
26 * | 31 * |
27 * @return string The comment text (including comment delimiters like /*) | 32 * @return string The comment text (including comment delimiters like /*) |
28 */ | 33 */ |
29 public function getText() { | 34 public function getText() : string { |
30 return $this->text; | 35 return $this->text; |
31 } | 36 } |
32 | 37 |
33 /** | 38 /** |
34 * Gets the line number the comment started on. | 39 * Gets the line number the comment started on. |
35 * | 40 * |
36 * @return int Line number | 41 * @return int Line number |
37 */ | 42 */ |
38 public function getLine() { | 43 public function getLine() : int { |
39 return $this->line; | 44 return $this->line; |
40 } | 45 } |
41 | 46 |
42 /** | 47 /** |
43 * Gets the file offset the comment started on. | 48 * Gets the file offset the comment started on. |
44 * | 49 * |
45 * @return int File offset | 50 * @return int File offset |
46 */ | 51 */ |
47 public function getFilePos() { | 52 public function getFilePos() : int { |
48 return $this->filePos; | 53 return $this->filePos; |
54 } | |
55 | |
56 /** | |
57 * Gets the token offset the comment started on. | |
58 * | |
59 * @return int Token offset | |
60 */ | |
61 public function getTokenPos() : int { | |
62 return $this->tokenPos; | |
49 } | 63 } |
50 | 64 |
51 /** | 65 /** |
52 * Gets the comment text. | 66 * Gets the comment text. |
53 * | 67 * |
54 * @return string The comment text (including comment delimiters like /*) | 68 * @return string The comment text (including comment delimiters like /*) |
55 */ | 69 */ |
56 public function __toString() { | 70 public function __toString() : string { |
57 return $this->text; | 71 return $this->text; |
58 } | 72 } |
59 | 73 |
60 /** | 74 /** |
61 * Gets the reformatted comment text. | 75 * Gets the reformatted comment text. |
112 | 126 |
113 // No idea how to format this comment, so simply return as is | 127 // No idea how to format this comment, so simply return as is |
114 return $text; | 128 return $text; |
115 } | 129 } |
116 | 130 |
117 private function getShortestWhitespacePrefixLen($str) { | 131 /** |
132 * Get length of shortest whitespace prefix (at the start of a line). | |
133 * | |
134 * If there is a line with no prefix whitespace, 0 is a valid return value. | |
135 * | |
136 * @param string $str String to check | |
137 * @return int Length in characters. Tabs count as single characters. | |
138 */ | |
139 private function getShortestWhitespacePrefixLen(string $str) : int { | |
118 $lines = explode("\n", $str); | 140 $lines = explode("\n", $str); |
119 $shortestPrefixLen = INF; | 141 $shortestPrefixLen = \INF; |
120 foreach ($lines as $line) { | 142 foreach ($lines as $line) { |
121 preg_match('(^\s*)', $line, $matches); | 143 preg_match('(^\s*)', $line, $matches); |
122 $prefixLen = strlen($matches[0]); | 144 $prefixLen = strlen($matches[0]); |
123 if ($prefixLen < $shortestPrefixLen) { | 145 if ($prefixLen < $shortestPrefixLen) { |
124 $shortestPrefixLen = $prefixLen; | 146 $shortestPrefixLen = $prefixLen; |
125 } | 147 } |
126 } | 148 } |
127 return $shortestPrefixLen; | 149 return $shortestPrefixLen; |
128 } | 150 } |
129 | 151 |
130 public function jsonSerialize() { | 152 /** |
153 * @return array | |
154 * @psalm-return array{nodeType:string, text:mixed, line:mixed, filePos:mixed} | |
155 */ | |
156 public function jsonSerialize() : array { | |
131 // Technically not a node, but we make it look like one anyway | 157 // Technically not a node, but we make it look like one anyway |
132 $type = $this instanceof Comment\Doc ? 'Comment_Doc' : 'Comment'; | 158 $type = $this instanceof Comment\Doc ? 'Comment_Doc' : 'Comment'; |
133 return [ | 159 return [ |
134 'nodeType' => $type, | 160 'nodeType' => $type, |
135 'text' => $this->text, | 161 'text' => $this->text, |
136 'line' => $this->line, | 162 'line' => $this->line, |
137 'filePos' => $this->filePos, | 163 'filePos' => $this->filePos, |
164 'tokenPos' => $this->tokenPos, | |
138 ]; | 165 ]; |
139 } | 166 } |
140 } | 167 } |