public function enterScope(NodeTraversal $t) { $node = $t->getScopeRoot(); $function = null; if ($node instanceof \PHPParser_Node_Stmt_Function) { $function = $this->typeRegistry->getFunction($node->name); if (null !== $function) { $this->parser->setCurrentClassName(null); $this->parser->setImportedNamespaces($this->importedNamespaces = $function->getImportedNamespaces()); } } else { if ($node instanceof \PHPParser_Node_Stmt_ClassMethod) { $objType = $t->getScope()->getTypeOfThis()->toMaybeObjectType(); if (null !== $objType) { /** @var $objType MethodContainer */ $this->parser->setCurrentClassName($objType->getName()); $this->parser->setImportedNamespaces($this->importedNamespaces = $objType->getImportedNamespaces()); $function = $objType->getMethod($node->name); } } } if (null !== $function) { if (null !== ($returnType = $function->getReturnType())) { $this->verifyReturnType($returnType, $node); } foreach ($function->getParameters() as $param) { /** @var $param Parameter */ if (null !== ($paramType = $param->getPhpType())) { $this->verifyParamType($paramType, $node, $param->getName()); } } } return true; }
private function enterNode(\PHPParser_Node $node) { if (NodeUtil::isMethodContainer($node)) { $this->commentParser->setCurrentClassName(implode("\\", $node->namespacedName->parts)); $this->commentParser->setImportedNamespaces($this->importedNamespaces); $this->classParser->setImportedNamespaces($this->importedNamespaces); $class = $this->classParser->parse($node); $this->classFiles[$class] = $this->phpFile; if ($this->typeRegistry->hasClass($class->getName(), TypeRegistry::LOOKUP_NO_CACHE)) { $this->analyzer->logger->warning(sprintf('The class "%s" has been defined more than once (maybe as a fixture for code generation). Ignoring the second definition.', $class->getName())); return; } $this->typeRegistry->registerClass($class); } else { if ($node instanceof \PHPParser_Node_Stmt_Function) { $this->functionParser->setImportedNamespaces($this->importedNamespaces); $function = $this->functionParser->parse($node); if ($this->typeRegistry->hasFunction($functionName = $function->getName(), false)) { $this->analyzer->logger->warning(sprintf('The function "%s" has been defined more than once (probably conditionally). Ignoring the second definition.', $functionName)); return; } $this->typeRegistry->registerFunction($function); } else { if (NodeUtil::isConstantDefinition($node)) { assert($node instanceof \PHPParser_Node_Expr_FuncCall); if (!$node->args[0]->value instanceof \PHPParser_Node_Scalar_String) { return; } $constant = new GlobalConstant($node->args[0]->value->value); $constant->setAstNode($node); $constant->setPhpType($this->typeRegistry->getNativeType('unknown')); if (null !== ($type = $node->args[1]->value->getAttribute('type'))) { $constant->setPhpType($type); } if ($this->typeRegistry->hasConstant($constant->getName(), false)) { $this->analyzer->logger->warning(sprintf('The constant "%s" was defined more than once. Ignoring all but first definition.', $constant->getName())); return; } $this->typeRegistry->registerConstant($constant); } } } }