Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / nikic / php-parser / lib / PhpParser / Error.php
index 4a23294feefed93325b04039763dde23fc877a40..cedb41244fafebe3dbf21c413574c57460147731 100644 (file)
@@ -1,4 +1,4 @@
-<?php
+<?php declare(strict_types=1);
 
 namespace PhpParser;
 
@@ -14,12 +14,12 @@ class Error extends \RuntimeException
      * @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 @@ class Error extends \RuntimeException
      *
      * @return string Error message
      */
-    public function getRawMessage() {
+    public function getRawMessage() : string {
         return $this->rawMessage;
     }
 
@@ -38,8 +38,8 @@ class Error extends \RuntimeException
      *
      * @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 @@ class Error extends \RuntimeException
      *
      * @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 @@ class Error extends \RuntimeException
      *
      * @param string $message Error message
      */
-    public function setRawMessage($message) {
+    public function setRawMessage(string $message) {
         $this->rawMessage = (string) $message;
         $this->updateMessage();
     }
@@ -86,7 +85,7 @@ class Error extends \RuntimeException
      *
      * @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 @@ class Error extends \RuntimeException
      *
      * @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 @@ class Error extends \RuntimeException
      * @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 @@ class Error extends \RuntimeException
      * @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 @@ class Error extends \RuntimeException
         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 @@ class Error extends \RuntimeException
         );
     }
 
-    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');
         }