public function persist(MethodContainer $container, $packageVersionId) { switch (true) { case $container instanceof Clazz: $type = 'class'; $superClass = $container->getSuperClass(); if ($superClasses = $container->getSuperClasses()) { $superClasses = implode(',', $superClasses); } else { $superClasses = null; } if ($implementedInterfaces = $container->getImplementedInterfaces()) { $implementedInterfaces = implode(',', $implementedInterfaces); } else { $implementedInterfaces = null; } $modifier = $container->getModifier(); $extendedInterfaces = null; break; case $container instanceof InterfaceC: $type = 'interface'; $superClass = null; $superClasses = null; $implementedInterfaces = null; $modifier = 0; if ($extendedInterfaces = $container->getExtendedInterfaces()) { $extendedInterfaces = implode(',', $extendedInterfaces); } else { $extendedInterfaces = null; } break; case $container instanceof TraitC: $type = 'trait'; $superClass = null; $superClasses = null; $implementedInterfaces = null; $modifier = 0; $extendedInterfaces = null; break; default: throw new \InvalidArgumentException('Unknown MethodContainer ' . get_class($container)); } $this->insertStmt->bindValue(1, $container->getName()); $this->insertStmt->bindValue(2, $container->isNormalized() ? 1 : 0, \PDO::PARAM_INT); $this->insertStmt->bindValue(3, $packageVersionId, \PDO::PARAM_INT); $this->insertStmt->bindValue(4, $type); $this->insertStmt->bindValue(5, $superClass, null === $superClass ? \PDO::PARAM_NULL : \PDO::PARAM_STR); $this->insertStmt->bindValue(6, $superClasses, null === $superClasses ? \PDO::PARAM_NULL : \PDO::PARAM_STR); $this->insertStmt->bindValue(7, $implementedInterfaces, null === $implementedInterfaces ? \PDO::PARAM_NULL : \PDO::PARAM_STR); $this->insertStmt->bindValue(8, $modifier, \PDO::PARAM_INT); $this->insertStmt->bindValue(9, $extendedInterfaces, null === $extendedInterfaces ? \PDO::PARAM_NULL : \PDO::PARAM_STR); $this->insertStmt->execute(); $containerId = $this->con->lastInsertId(); foreach ($container->getMethods() as $method) { $this->methodPersister->persist($method, $packageVersionId, $containerId); } switch (true) { case $container instanceof Clazz: foreach ($container->getProperties() as $property) { $this->propertyPersister->persist($property, $packageVersionId, $containerId); } foreach ($container->getConstants() as $constant) { $this->constantPersister->persist($constant, $packageVersionId, $containerId); } break; case $container instanceof InterfaceC: foreach ($container->getConstants() as $constant) { $this->constantPersister->persist($constant, $packageVersionId, $containerId); } break; case $container instanceof TraitC: break; default: throw new \InvalidArgumentException('Unknown MethodContainer ' . get_class($container)); } }
private function normalizeType(MethodContainer $class) { // If the class is coming from the cache, it is already normalized. if ($class->isNormalized()) { return true; } // If this class was visited as part of a parent/interface, return here. if (isset($this->visitedTypes[$class])) { return $this->visitedTypes[$class]; } $normalized = true; if ($class instanceof Clazz) { if ($superClass = $class->getSuperClass()) { // Check if the type registry contains this class if ($superClassType = $this->typeRegistry->getClass($superClass)) { if (!$this->normalizeType($superClassType)) { $normalized = false; } $this->mergeTypes($class, $superClassType); } else { $normalized = false; } } foreach ($class->getImplementedInterfaces() as $interfaceName) { if (null === ($interfaceType = $this->typeRegistry->getClass($interfaceName))) { $normalized = false; continue; } if (!$this->normalizeType($interfaceType)) { $normalized = false; } $this->mergeTypes($class, $interfaceType); } } else { if ($class instanceof InterfaceC) { foreach ($class->getExtendedInterfaces() as $interfaceName) { if (null === ($interfaceType = $this->typeRegistry->getClass($interfaceName))) { $normalized = false; continue; } if (!$this->normalizeType($interfaceType)) { $normalized = false; } $this->mergeTypes($class, $interfaceType); } } else { if ($class instanceof TraitC) { // TODO: Implement support for Traits } else { throw new \LogicException('Previous ifs were exhaustive.'); } } } $class->setNormalized($normalized); $this->visitedTypes[$class] = $normalized; return $normalized; }