diff vendor/psy/psysh/src/Input/ShellInput.php @ 4:a9cd425dd02b

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:11:55 +0000
parents c75dbcec494b
children
line wrap: on
line diff
--- a/vendor/psy/psysh/src/Input/ShellInput.php	Thu Feb 28 11:14:44 2019 +0000
+++ b/vendor/psy/psysh/src/Input/ShellInput.php	Thu Feb 28 13:11:55 2019 +0000
@@ -51,10 +51,10 @@
 
         if ($definition->getArgumentCount() > 0) {
             $args    = $definition->getArguments();
-            $lastArg = array_pop($args);
+            $lastArg = \array_pop($args);
             foreach ($args as $arg) {
                 if ($arg instanceof CodeArgument) {
-                    $msg = sprintf('Unexpected CodeArgument before the final position: %s', $arg->getName());
+                    $msg = \sprintf('Unexpected CodeArgument before the final position: %s', $arg->getName());
                     throw new \InvalidArgumentException($msg);
                 }
             }
@@ -84,33 +84,33 @@
     private function tokenize($input)
     {
         $tokens = [];
-        $length = strlen($input);
+        $length = \strlen($input);
         $cursor = 0;
         while ($cursor < $length) {
-            if (preg_match('/\s+/A', $input, $match, null, $cursor)) {
-            } elseif (preg_match('/([^="\'\s]+?)(=?)(' . StringInput::REGEX_QUOTED_STRING . '+)/A', $input, $match, null, $cursor)) {
+            if (\preg_match('/\s+/A', $input, $match, null, $cursor)) {
+            } elseif (\preg_match('/([^="\'\s]+?)(=?)(' . StringInput::REGEX_QUOTED_STRING . '+)/A', $input, $match, null, $cursor)) {
                 $tokens[] = [
-                    $match[1] . $match[2] . stripcslashes(str_replace(['"\'', '\'"', '\'\'', '""'], '', substr($match[3], 1, strlen($match[3]) - 2))),
-                    stripcslashes(substr($input, $cursor)),
+                    $match[1] . $match[2] . \stripcslashes(\str_replace(['"\'', '\'"', '\'\'', '""'], '', \substr($match[3], 1, \strlen($match[3]) - 2))),
+                    \stripcslashes(\substr($input, $cursor)),
                 ];
-            } elseif (preg_match('/' . StringInput::REGEX_QUOTED_STRING . '/A', $input, $match, null, $cursor)) {
+            } elseif (\preg_match('/' . StringInput::REGEX_QUOTED_STRING . '/A', $input, $match, null, $cursor)) {
                 $tokens[] = [
-                    stripcslashes(substr($match[0], 1, strlen($match[0]) - 2)),
-                    stripcslashes(substr($input, $cursor)),
+                    \stripcslashes(\substr($match[0], 1, \strlen($match[0]) - 2)),
+                    \stripcslashes(\substr($input, $cursor)),
                 ];
-            } elseif (preg_match('/' . StringInput::REGEX_STRING . '/A', $input, $match, null, $cursor)) {
+            } elseif (\preg_match('/' . StringInput::REGEX_STRING . '/A', $input, $match, null, $cursor)) {
                 $tokens[] = [
-                    stripcslashes($match[1]),
-                    stripcslashes(substr($input, $cursor)),
+                    \stripcslashes($match[1]),
+                    \stripcslashes(\substr($input, $cursor)),
                 ];
             } else {
                 // should never happen
                 // @codeCoverageIgnoreStart
-                throw new \InvalidArgumentException(sprintf('Unable to parse input near "... %s ..."', substr($input, $cursor, 10)));
+                throw new \InvalidArgumentException(\sprintf('Unable to parse input near "... %s ..."', \substr($input, $cursor, 10)));
                 // @codeCoverageIgnoreEnd
             }
 
-            $cursor += strlen($match[0]);
+            $cursor += \strlen($match[0]);
         }
 
         return $tokens;
@@ -123,7 +123,7 @@
     {
         $parseOptions = true;
         $this->parsed = $this->tokenPairs;
-        while (null !== $tokenPair = array_shift($this->parsed)) {
+        while (null !== $tokenPair = \array_shift($this->parsed)) {
             // token is what you'd expect. rest is the remainder of the input
             // string, including token, and will be used if this is a code arg.
             list($token, $rest) = $tokenPair;
@@ -132,7 +132,7 @@
                 $this->parseShellArgument($token, $rest);
             } elseif ($parseOptions && '--' === $token) {
                 $parseOptions = false;
-            } elseif ($parseOptions && 0 === strpos($token, '--')) {
+            } elseif ($parseOptions && 0 === \strpos($token, '--')) {
                 $this->parseLongOption($token);
             } elseif ($parseOptions && '-' === $token[0] && '-' !== $token) {
                 $this->parseShortOption($token);
@@ -152,7 +152,7 @@
      */
     private function parseShellArgument($token, $rest)
     {
-        $c = count($this->arguments);
+        $c = \count($this->arguments);
 
         // if input is expecting another argument, add it
         if ($this->definition->hasArgument($c)) {
@@ -184,11 +184,11 @@
 
         // unexpected argument
         $all = $this->definition->getArguments();
-        if (count($all)) {
-            throw new \RuntimeException(sprintf('Too many arguments, expected arguments "%s".', implode('" "', array_keys($all))));
+        if (\count($all)) {
+            throw new \RuntimeException(\sprintf('Too many arguments, expected arguments "%s".', \implode('" "', \array_keys($all))));
         }
 
-        throw new \RuntimeException(sprintf('No arguments expected, got "%s".', $token));
+        throw new \RuntimeException(\sprintf('No arguments expected, got "%s".', $token));
         // @codeCoverageIgnoreEnd
     }
 
@@ -202,12 +202,12 @@
      */
     private function parseShortOption($token)
     {
-        $name = substr($token, 1);
+        $name = \substr($token, 1);
 
-        if (strlen($name) > 1) {
+        if (\strlen($name) > 1) {
             if ($this->definition->hasShortcut($name[0]) && $this->definition->getOptionForShortcut($name[0])->acceptValue()) {
                 // an option with a value (with no space)
-                $this->addShortOption($name[0], substr($name, 1));
+                $this->addShortOption($name[0], \substr($name, 1));
             } else {
                 $this->parseShortOptionSet($name);
             }
@@ -225,15 +225,15 @@
      */
     private function parseShortOptionSet($name)
     {
-        $len = strlen($name);
+        $len = \strlen($name);
         for ($i = 0; $i < $len; $i++) {
             if (!$this->definition->hasShortcut($name[$i])) {
-                throw new \RuntimeException(sprintf('The "-%s" option does not exist.', $name[$i]));
+                throw new \RuntimeException(\sprintf('The "-%s" option does not exist.', $name[$i]));
             }
 
             $option = $this->definition->getOptionForShortcut($name[$i]);
             if ($option->acceptValue()) {
-                $this->addLongOption($option->getName(), $i === $len - 1 ? null : substr($name, $i + 1));
+                $this->addLongOption($option->getName(), $i === $len - 1 ? null : \substr($name, $i + 1));
 
                 break;
             } else {
@@ -249,18 +249,18 @@
      */
     private function parseLongOption($token)
     {
-        $name = substr($token, 2);
+        $name = \substr($token, 2);
 
-        if (false !== $pos = strpos($name, '=')) {
-            if (0 === strlen($value = substr($name, $pos + 1))) {
+        if (false !== $pos = \strpos($name, '=')) {
+            if (0 === \strlen($value = \substr($name, $pos + 1))) {
                 // if no value after "=" then substr() returns "" since php7 only, false before
                 // see http://php.net/manual/fr/migration70.incompatible.php#119151
                 if (PHP_VERSION_ID < 70000 && false === $value) {
                     $value = '';
                 }
-                array_unshift($this->parsed, [$value, null]);
+                \array_unshift($this->parsed, [$value, null]);
             }
-            $this->addLongOption(substr($name, 0, $pos), $value);
+            $this->addLongOption(\substr($name, 0, $pos), $value);
         } else {
             $this->addLongOption($name, null);
         }
@@ -277,7 +277,7 @@
     private function addShortOption($shortcut, $value)
     {
         if (!$this->definition->hasShortcut($shortcut)) {
-            throw new \RuntimeException(sprintf('The "-%s" option does not exist.', $shortcut));
+            throw new \RuntimeException(\sprintf('The "-%s" option does not exist.', $shortcut));
         }
 
         $this->addLongOption($this->definition->getOptionForShortcut($shortcut)->getName(), $value);
@@ -294,30 +294,30 @@
     private function addLongOption($name, $value)
     {
         if (!$this->definition->hasOption($name)) {
-            throw new \RuntimeException(sprintf('The "--%s" option does not exist.', $name));
+            throw new \RuntimeException(\sprintf('The "--%s" option does not exist.', $name));
         }
 
         $option = $this->definition->getOption($name);
 
         if (null !== $value && !$option->acceptValue()) {
-            throw new \RuntimeException(sprintf('The "--%s" option does not accept a value.', $name));
+            throw new \RuntimeException(\sprintf('The "--%s" option does not accept a value.', $name));
         }
 
-        if (in_array($value, ['', null], true) && $option->acceptValue() && count($this->parsed)) {
+        if (\in_array($value, ['', null], true) && $option->acceptValue() && \count($this->parsed)) {
             // if option accepts an optional or mandatory argument
             // let's see if there is one provided
-            $next = array_shift($this->parsed);
+            $next = \array_shift($this->parsed);
             $nextToken = $next[0];
-            if ((isset($nextToken[0]) && '-' !== $nextToken[0]) || in_array($nextToken, ['', null], true)) {
+            if ((isset($nextToken[0]) && '-' !== $nextToken[0]) || \in_array($nextToken, ['', null], true)) {
                 $value = $nextToken;
             } else {
-                array_unshift($this->parsed, $next);
+                \array_unshift($this->parsed, $next);
             }
         }
 
         if (null === $value) {
             if ($option->isValueRequired()) {
-                throw new \RuntimeException(sprintf('The "--%s" option requires a value.', $name));
+                throw new \RuntimeException(\sprintf('The "--%s" option requires a value.', $name));
             }
 
             if (!$option->isArray() && !$option->isValueOptional()) {