コード例 #1
0
 /**
  * Validate a class constant fetch expression.
  *
  * @throws FatalErrorException if a class constant is not defined.
  *
  * @param ClassConstFetch $stmt
  */
 protected function validateClassConstFetchExpression(ClassConstFetch $stmt)
 {
     // if class name is an expression, give it a pass for now
     if (!$stmt->class instanceof Expr) {
         $className = $this->getFullyQualifiedName($stmt->class);
         // if the class doesn't exist, don't throw an exception… it might be
         // defined in the same line it's used or something stupid like that.
         if (class_exists($className)) {
             $constName = sprintf('%s::%s', $className, $stmt->name);
             if (!defined($constName)) {
                 $msg = sprintf('Class constant \'%s\' not found', $constName);
                 throw new FatalErrorException($msg, 0, 1, null, $stmt->getLine());
             }
         }
     }
 }
コード例 #2
0
ファイル: SoftMocks.php プロジェクト: badoo/soft-mocks
 public function rewriteExpr_ClassConstFetch(\PhpParser\Node\Expr\ClassConstFetch $Node)
 {
     if ($this->disable_const_rewrite_level > 0 || strtolower($Node->name) == 'class') {
         return null;
     }
     $NewNode = new \PhpParser\Node\Expr\StaticCall(new \PhpParser\Node\Name("\\" . SoftMocks::class), "getClassConst", [self::nodeNameToArg($Node->class), self::nodeNameToArg($Node->name)]);
     $NewNode->setLine($Node->getLine());
     return $NewNode;
 }