diff vendor/psy/psysh/src/CodeCleaner/ValidClassNamePass.php @ 17:129ea1e6d783

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:21:36 +0000
parents c2387f117808
children
line wrap: on
line diff
--- a/vendor/psy/psysh/src/CodeCleaner/ValidClassNamePass.php	Tue Jul 10 15:07:59 2018 +0100
+++ b/vendor/psy/psysh/src/CodeCleaner/ValidClassNamePass.php	Thu Feb 28 13:21:36 2019 +0000
@@ -43,7 +43,7 @@
 
     public function __construct()
     {
-        $this->atLeastPhp55 = version_compare(PHP_VERSION, '5.5', '>=');
+        $this->atLeastPhp55 = \version_compare(PHP_VERSION, '5.5', '>=');
     }
 
     /**
@@ -164,7 +164,7 @@
     protected function validateClassConstFetchExpression(ClassConstFetch $stmt)
     {
         // there is no need to check exists for ::class const for php 5.5 or newer
-        if (strtolower($stmt->name) === 'class' && $this->atLeastPhp55) {
+        if (\strtolower($stmt->name) === 'class' && $this->atLeastPhp55) {
             return;
         }
 
@@ -210,12 +210,12 @@
         }
 
         if ($errorType !== null) {
-            throw $this->createError(sprintf('%s named %s already exists', ucfirst($errorType), $name), $stmt);
+            throw $this->createError(\sprintf('%s named %s already exists', \ucfirst($errorType), $name), $stmt);
         }
 
         // Store creation for the rest of this code snippet so we can find local
         // issue too
-        $this->currentScope[strtolower($name)] = $scopeType;
+        $this->currentScope[\strtolower($name)] = $scopeType;
     }
 
     /**
@@ -229,7 +229,7 @@
     protected function ensureClassExists($name, $stmt)
     {
         if (!$this->classExists($name)) {
-            throw $this->createError(sprintf('Class \'%s\' not found', $name), $stmt);
+            throw $this->createError(\sprintf('Class \'%s\' not found', $name), $stmt);
         }
     }
 
@@ -244,7 +244,22 @@
     protected function ensureClassOrInterfaceExists($name, $stmt)
     {
         if (!$this->classExists($name) && !$this->interfaceExists($name)) {
-            throw $this->createError(sprintf('Class \'%s\' not found', $name), $stmt);
+            throw $this->createError(\sprintf('Class \'%s\' not found', $name), $stmt);
+        }
+    }
+
+    /**
+     * Ensure that a referenced class _or trait_ exists.
+     *
+     * @throws FatalErrorException
+     *
+     * @param string $name
+     * @param Stmt   $stmt
+     */
+    protected function ensureClassOrTraitExists($name, $stmt)
+    {
+        if (!$this->classExists($name) && !$this->traitExists($name)) {
+            throw $this->createError(\sprintf('Class \'%s\' not found', $name), $stmt);
         }
     }
 
@@ -259,10 +274,10 @@
      */
     protected function ensureMethodExists($class, $name, $stmt)
     {
-        $this->ensureClassExists($class, $stmt);
+        $this->ensureClassOrTraitExists($class, $stmt);
 
         // let's pretend all calls to self, parent and static are valid
-        if (in_array(strtolower($class), ['self', 'parent', 'static'])) {
+        if (\in_array(\strtolower($class), ['self', 'parent', 'static'])) {
             return;
         }
 
@@ -276,8 +291,8 @@
             return;
         }
 
-        if (!method_exists($class, $name) && !method_exists($class, '__callStatic')) {
-            throw $this->createError(sprintf('Call to undefined method %s::%s()', $class, $name), $stmt);
+        if (!\method_exists($class, $name) && !\method_exists($class, '__callStatic')) {
+            throw $this->createError(\sprintf('Call to undefined method %s::%s()', $class, $name), $stmt);
         }
     }
 
@@ -295,7 +310,7 @@
             /** @var string $name */
             $name = $this->getFullyQualifiedName($interface);
             if (!$this->interfaceExists($name)) {
-                throw $this->createError(sprintf('Interface \'%s\' not found', $name), $stmt);
+                throw $this->createError(\sprintf('Interface \'%s\' not found', $name), $stmt);
             }
         }
     }
@@ -335,11 +350,11 @@
         // Give `self`, `static` and `parent` a pass. This will actually let
         // some errors through, since we're not checking whether the keyword is
         // being used in a class scope.
-        if (in_array(strtolower($name), ['self', 'static', 'parent'])) {
+        if (\in_array(\strtolower($name), ['self', 'static', 'parent'])) {
             return true;
         }
 
-        return class_exists($name) || $this->findInScope($name) === self::CLASS_TYPE;
+        return \class_exists($name) || $this->findInScope($name) === self::CLASS_TYPE;
     }
 
     /**
@@ -351,7 +366,7 @@
      */
     protected function interfaceExists($name)
     {
-        return interface_exists($name) || $this->findInScope($name) === self::INTERFACE_TYPE;
+        return \interface_exists($name) || $this->findInScope($name) === self::INTERFACE_TYPE;
     }
 
     /**
@@ -363,7 +378,7 @@
      */
     protected function traitExists($name)
     {
-        return trait_exists($name) || $this->findInScope($name) === self::TRAIT_TYPE;
+        return \trait_exists($name) || $this->findInScope($name) === self::TRAIT_TYPE;
     }
 
     /**
@@ -375,7 +390,7 @@
      */
     protected function findInScope($name)
     {
-        $name = strtolower($name);
+        $name = \strtolower($name);
         if (isset($this->currentScope[$name])) {
             return $this->currentScope[$name];
         }