Mercurial > hg > isophonics-drupal-site
diff vendor/nikic/php-parser/lib/PhpParser/Error.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 | c2387f117808 |
line wrap: on
line diff
--- a/vendor/nikic/php-parser/lib/PhpParser/Error.php Fri Feb 23 15:52:07 2018 +0000 +++ b/vendor/nikic/php-parser/lib/PhpParser/Error.php Mon Apr 23 09:33:26 2018 +0100 @@ -1,4 +1,4 @@ -<?php +<?php declare(strict_types=1); namespace PhpParser; @@ -14,12 +14,12 @@ * @param array|int $attributes Attributes of node/token where error occurred * (or start line of error -- deprecated) */ - public function __construct($message, $attributes = array()) { + public function __construct(string $message, $attributes = []) { $this->rawMessage = (string) $message; if (is_array($attributes)) { $this->attributes = $attributes; } else { - $this->attributes = array('startLine' => $attributes); + $this->attributes = ['startLine' => $attributes]; } $this->updateMessage(); } @@ -29,7 +29,7 @@ * * @return string Error message */ - public function getRawMessage() { + public function getRawMessage() : string { return $this->rawMessage; } @@ -38,8 +38,8 @@ * * @return int Error start line */ - public function getStartLine() { - return isset($this->attributes['startLine']) ? $this->attributes['startLine'] : -1; + public function getStartLine() : int { + return $this->attributes['startLine'] ?? -1; } /** @@ -47,22 +47,21 @@ * * @return int Error end line */ - public function getEndLine() { - return isset($this->attributes['endLine']) ? $this->attributes['endLine'] : -1; + public function getEndLine() : int { + return $this->attributes['endLine'] ?? -1; } - /** * Gets the attributes of the node/token the error occurred at. * * @return array */ - public function getAttributes() { + public function getAttributes() : array { return $this->attributes; } /** - * Sets the attributes of the node/token the error occured at. + * Sets the attributes of the node/token the error occurred at. * * @param array $attributes */ @@ -76,7 +75,7 @@ * * @param string $message Error message */ - public function setRawMessage($message) { + public function setRawMessage(string $message) { $this->rawMessage = (string) $message; $this->updateMessage(); } @@ -86,7 +85,7 @@ * * @param int $line Error start line */ - public function setStartLine($line) { + public function setStartLine(int $line) { $this->attributes['startLine'] = (int) $line; $this->updateMessage(); } @@ -98,8 +97,8 @@ * * @return bool */ - public function hasColumnInfo() { - return isset($this->attributes['startFilePos']) && isset($this->attributes['endFilePos']); + public function hasColumnInfo() : bool { + return isset($this->attributes['startFilePos'], $this->attributes['endFilePos']); } /** @@ -108,7 +107,7 @@ * @param string $code Source code of the file * @return int */ - public function getStartColumn($code) { + public function getStartColumn(string $code) : int { if (!$this->hasColumnInfo()) { throw new \RuntimeException('Error does not have column information'); } @@ -122,7 +121,7 @@ * @param string $code Source code of the file * @return int */ - public function getEndColumn($code) { + public function getEndColumn(string $code) : int { if (!$this->hasColumnInfo()) { throw new \RuntimeException('Error does not have column information'); } @@ -130,7 +129,14 @@ return $this->toColumn($code, $this->attributes['endFilePos']); } - public function getMessageWithColumnInfo($code) { + /** + * Formats message including line and column information. + * + * @param string $code Source code associated with the error, for calculation of the columns + * + * @return string Formatted message + */ + public function getMessageWithColumnInfo(string $code) : string { return sprintf( '%s from %d:%d to %d:%d', $this->getRawMessage(), $this->getStartLine(), $this->getStartColumn($code), @@ -138,7 +144,15 @@ ); } - private function toColumn($code, $pos) { + /** + * Converts a file offset into a column. + * + * @param string $code Source code that $pos indexes into + * @param int $pos 0-based position in $code + * + * @return int 1-based column (relative to start of line) + */ + private function toColumn(string $code, int $pos) : int { if ($pos > strlen($code)) { throw new \RuntimeException('Invalid position information'); }