Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / nikic / php-parser / lib / PhpParser / Comment.php
index 4034cfa6b198299bd738b25fa600cfc7e94eb899..5da8420958806baf58fc65f465e162ee93b7d269 100644 (file)
@@ -1,4 +1,4 @@
-<?php
+<?php declare(strict_types=1);
 
 namespace PhpParser;
 
@@ -7,18 +7,23 @@ class Comment implements \JsonSerializable
     protected $text;
     protected $line;
     protected $filePos;
+    protected $tokenPos;
 
     /**
      * Constructs a comment node.
      *
-     * @param string $text         Comment text (including comment delimiters like /*)
-     * @param int    $startLine    Line number the comment started on
-     * @param int    $startFilePos File offset the comment started on
+     * @param string $text          Comment text (including comment delimiters like /*)
+     * @param int    $startLine     Line number the comment started on
+     * @param int    $startFilePos  File offset the comment started on
+     * @param int    $startTokenPos Token offset the comment started on
      */
-    public function __construct($text, $startLine = -1, $startFilePos = -1) {
+    public function __construct(
+        string $text, int $startLine = -1, int $startFilePos = -1, int $startTokenPos = -1
+    ) {
         $this->text = $text;
         $this->line = $startLine;
         $this->filePos = $startFilePos;
+        $this->tokenPos = $startTokenPos;
     }
 
     /**
@@ -26,7 +31,7 @@ class Comment implements \JsonSerializable
      *
      * @return string The comment text (including comment delimiters like /*)
      */
-    public function getText() {
+    public function getText() : string {
         return $this->text;
     }
 
@@ -35,7 +40,7 @@ class Comment implements \JsonSerializable
      *
      * @return int Line number
      */
-    public function getLine() {
+    public function getLine() : int {
         return $this->line;
     }
 
@@ -44,16 +49,25 @@ class Comment implements \JsonSerializable
      *
      * @return int File offset
      */
-    public function getFilePos() {
+    public function getFilePos() : int {
         return $this->filePos;
     }
 
+    /**
+     * Gets the token offset the comment started on.
+     *
+     * @return int Token offset
+     */
+    public function getTokenPos() : int {
+        return $this->tokenPos;
+    }
+
     /**
      * Gets the comment text.
      *
      * @return string The comment text (including comment delimiters like /*)
      */
-    public function __toString() {
+    public function __toString() : string {
         return $this->text;
     }
 
@@ -114,9 +128,17 @@ class Comment implements \JsonSerializable
         return $text;
     }
 
-    private function getShortestWhitespacePrefixLen($str) {
+    /**
+     * Get length of shortest whitespace prefix (at the start of a line).
+     *
+     * If there is a line with no prefix whitespace, 0 is a valid return value.
+     *
+     * @param string $str String to check
+     * @return int Length in characters. Tabs count as single characters.
+     */
+    private function getShortestWhitespacePrefixLen(string $str) : int {
         $lines = explode("\n", $str);
-        $shortestPrefixLen = INF;
+        $shortestPrefixLen = \INF;
         foreach ($lines as $line) {
             preg_match('(^\s*)', $line, $matches);
             $prefixLen = strlen($matches[0]);
@@ -127,7 +149,11 @@ class Comment implements \JsonSerializable
         return $shortestPrefixLen;
     }
 
-    public function jsonSerialize() {
+    /**
+     * @return       array
+     * @psalm-return array{nodeType:string, text:mixed, line:mixed, filePos:mixed}
+     */
+    public function jsonSerialize() : array {
         // Technically not a node, but we make it look like one anyway
         $type = $this instanceof Comment\Doc ? 'Comment_Doc' : 'Comment';
         return [
@@ -135,6 +161,7 @@ class Comment implements \JsonSerializable
             'text' => $this->text,
             'line' => $this->line,
             'filePos' => $this->filePos,
+            'tokenPos' => $this->tokenPos,
         ];
     }
-}
\ No newline at end of file
+}