public function persist(GlobalConstant $constant, $packageVersionId)
 {
     $this->insertStmt->bindValue(1, $constant->getName());
     $this->insertStmt->bindValue(2, $this->phpType->convertToDatabaseValue($constant->getPhpType(), $this->platform));
     $this->insertStmt->bindValue(3, $packageVersionId, \PDO::PARAM_INT);
     $this->insertStmt->execute();
 }
 public function registerConstant(GlobalConstant $constant)
 {
     $this->constants[$constant->getName()] = $constant;
 }
 private function inferTypesForConstant(GlobalConstant $constant)
 {
     if (($type = $constant->getPhpType()) && !$type->isUnknownType()) {
         return;
     }
     if (null !== ($node = $constant->getAstNode())) {
         $type = $this->parser->getTypeFromVarAnnotation($node);
     }
     if (null === $type) {
         $type = $this->registry->getNativeType('unknown');
     }
     $constant->setPhpType($type);
     if ($node) {
         $node->setAttribute('type', $type);
     }
 }
 public function addConstant(GlobalConstant $constant)
 {
     $constant->setPackageVersion($this);
     $this->constants->set($constant->getName(), $constant);
 }
 public function testLoadConstant()
 {
     $this->versionA->addConstant($fooA = new GlobalConstant('FOO'));
     $fooA->setPhpType($this->typeRegistry->getNativeType('string'));
     $this->versionB->addConstant($fooB = new GlobalConstant('FOO'));
     $fooB->setPhpType($this->typeRegistry->getNativeType('string'));
     $this->em->persist($this->package);
     $this->em->flush();
     $loadedConst = $this->provider->loadConstant('FOO');
     $this->assertSame($fooA, $loadedConst, 'loadConstant() takes the first constant if no package versions are set.');
     $loadedConst = $this->provider->loadConstant('foo');
     $this->assertNull($loadedConst, 'loadConstant() treats the name **not** as case-insensitive.');
     $this->provider->setPackageVersions(array($this->versionB));
     $loadedConst = $this->provider->loadConstant('FOO');
     $this->assertSame($fooB, $loadedConst, 'loadConstant() takes the constant from one of the set packages.');
     $this->provider->setPackageVersions(array($this->versionC));
     $this->assertNull($this->provider->loadConstant('FOO'), 'loadConstant() returns null if constant is not found in set packages.');
     $this->assertNull($this->provider->loadConstant('BAR'), 'loadConstant() returns null if constant does not exist.');
 }
 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);
             }
         }
     }
 }