/**
  * @param string $fileName
  * @param \PhpParser\Node\Expr\Variable $node
  */
 function run($fileName, $node, ClassLike $inside = null, Scope $scope = null)
 {
     if (gettype($node->name) == 'string' && $scope && !$scope->isGlobal()) {
         $name = $name = $node->name;
         if ($name != "GLOBALS" && $name != "_GET" && $name != "_POST" && $name != "_COOKIE" && $name != "_REQUEST" && $name != "this" && $name != "_SERVER" && $name != "_SESSION" && $name != "_FILES" && $name != "http_response_header") {
             $this->incTests();
             if ($scope->getVarType($name) == Scope::UNDEFINED) {
                 $this->emitError($fileName, $node, self::TYPE_UNKNOWN_VARIABLE, "Undefined variable: {$name}");
             }
         }
     }
 }
예제 #2
0
 /**
  * @param           $fileName
  * @param           $node
  * @param string    $inside
  * @param Scope     $scope
  * @param           $method
  */
 protected function checkMethod($fileName, $node, $inside, Scope $scope, MethodInterface $method)
 {
     if ($method->isStatic()) {
         $this->emitError($fileName, $node, self::TYPE_INCORRECT_DYNAMIC_CALL, "Call to static method of {$inside}::" . $method->getName() . " non-statically");
         return;
     }
     $params = $method->getParameters();
     $minimumArgs = $method->getMinimumRequiredParameters();
     if (count($node->args) < $minimumArgs) {
         $this->emitError($fileName, $node, self::TYPE_SIGNATURE_COUNT, "Function call parameter count mismatch to method " . $method->getName() . " (passed " . count($node->args) . " requires {$minimumArgs})");
     }
     if (count($node->args) > count($params) && !$method->isVariadic()) {
         $this->emitError($fileName, $node, self::TYPE_SIGNATURE_COUNT_EXCESS, "Too many parameters to non-variadic method " . $method->getName() . " (passed " . count($node->args) . " only takes " . count($params) . ")");
     }
     foreach ($node->args as $index => $arg) {
         if ($scope && $arg->value instanceof \PhpParser\Node\Expr\Variable && $index < count($params) && $params[$index]->getType() != "") {
             $variableName = $arg->value->name;
             $type = $scope->getVarType($variableName);
             $expectedType = $params[$index]->getType();
             if (!in_array($type, [Scope::SCALAR_TYPE, Scope::MIXED_TYPE, Scope::UNDEFINED]) && $type != "" && !$this->symbolTable->isParentClassOrInterface($expectedType, $type)) {
                 $this->emitError($fileName, $node, self::TYPE_SIGNATURE_TYPE, "Variable passed to method " . $inside . "->" . $node->name . "() parameter \${$variableName} must be a {$expectedType}, passing {$type}");
             }
         }
     }
 }