Tests if a received class name is in fact a Doctrine Entity

Based on @link https://stackoverflow.com/a/27121978/1155833

@param string $classFQCN

@return boolean
@throws EntityNotFoundException
962349
function isEntity(string $classFQCN) : bool
    {
        if ( ! class_exists($classFQCN)) {

            throw new ClassNotFoundException(sprintf('Given class FQCN "%s" does not exist.', $classFQCN));
        }

        if ( ! is_object($classFQCN)) {

            throw new EntityNotFoundException(sprintf('Given class "%s" is not a Doctrine Entity.', $classFQCN));
        }

        return ! $this->getObjectManager()
                      ->getMetadataFactory()
                      ->isTransient(ClassUtils::getClass($classFQCN));
    }
59296
public function getEntity($className, $id)
    {
        if (isset($this->entities[$className]) && isset($this->entities[$className][$id])) {
            return $this->entities[$className][$id];
        }

        if (isset($this->stashedEntities[$className]) && isset($this->stashedEntities[$className][$id])) {
            return $this->stashedEntities[$className][$id];
        }

        return null;
    }
744159
private function _checkEntityName(Certificate $cert): bool
    {
        $name = $this->_entityName->firstDN();
        if ($cert->tbsCertificate()
            ->subject()
            ->equals($name)) {
            return true;
        }
        $exts = $cert->tbsCertificate()->extensions();
        if ($exts->hasSubjectAlternativeName()) {
            $ext = $exts->subjectAlternativeName();
            if ($this->_checkEntityAlternativeNames($ext->names())) {
                return true;
            }
        }
        return false;
    }
1143821
public function isNewEntity(EntityInterface $entity)
    {
        $reflection = $this->getEntityClassReflection();
        $metadata = $this->getEntityMetadata();
        $identifier = $metadata->getName($metadata->getIdentifier(), Metadata::CAMILIZED);
        
        return null !== $identifier
            ? ($reflection->getProperty($identifier)->getValue($entity) === null) : true;
    }
718136
protected function isEntityManager(ClassNode $classNode): bool
    {
        $className = $this->getClassName($classNode);

        if (preg_match(self::PATTERN_ENTITY_MANAGER, $className)) {
            return true;
        }

        return false;
    }
163178
protected function _getEntityName($entity = '') {
        /** @var $class \Gcs\Framework\Core\Orm\Entity\Entity */

        $entity = ucfirst(preg_replace_callback("/(?:^|_)([a-z])/", function ($matches) {
            return strtoupper($matches[1]);
        }, $entity));

        $className = '\Orm\Entity\\' . ucfirst($entity);

        if (class_exists($className)) {
            return $entity;
        }
        else {
            throw new MissingEntityException('The Entity ' . $entity . ' does not exist');
        }
    }
58019
private function throwIfNotEntity(string $className): void
    {
        if (!$this->isEntity($className)) {
            throw new \UnexpectedValueException('Given class name `' . $className . '` is not a Doctrine entity. Either register a custom GraphQL type for `' . $className . '` when instantiating `' . self::class . '`, or change the usage of that class to something else.');
        }
    }
969088
@Override
    @FFDCIgnore(ClassNotFoundException.class)
    public Class<?> classForName(String className)
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
        {
            Tr.debug(tc, "Loading class " + className + " using classloader " + delegate);
        }
        try
        {
            return delegate.loadClass(className);
        } catch (ClassNotFoundException e)
        {
            return loadFromWeldBundleCL(className);
        }
    }
840021
public function add(IEntity $entity) : bool
    {
        $class = $this->entityType;

        if(!($entity instanceof $class)) {
            throw TypeMismatchException::argument(__METHOD__, 'entity', $class, $entity);
        }

        if ($entity->getId() === null) {
            $this->nullIdEntities[] = $entity;
            return true;
        }

        $id = $entity->getId();

        if ($this->has($id)) {
            return false;
        }

        $this->entities[$id] = $entity;

        return true;
    }
659652
public function build(string $fqcn)
    {
        try {
            return $this->doBuild($fqcn);
        } catch (\Throwable $exception) {
            throw new MockNotCreatedException(
                sprintf(
                    'Cannot create mock object for FQCN "%s": %s',
                    $fqcn,
                    $exception->getMessage()
                )
            );
        }
    }
375070
public function validateReflectionMethod($classFQN, $method)
    {
        if (null === $classFQN || null === $method) {
            return false;
        }

        try {
            $reflectionMethod = new \ReflectionMethod($classFQN, $method);
        } catch (\ReflectionException $re) {
            return new CoverFishMessageError(CoverFishMessageError::PHPUNIT_REFLECTION_METHOD_NOT_FOUND, $method);
        }

        return $reflectionMethod;
    }
1008719
public function createFactoryForEntity(string $entityFqn)
    {
        $this->assertEntityManagerSet();
        $factoryFqn = $this->namespaceHelper->getFactoryFqnFromEntityFqn($entityFqn);

        return new $factoryFqn($this, $this->entityManager);
    }
184609
public static function checkAndCreateTableByEntityName(ContainerInterface $container, $className, $force = false)
    {
        /** @var Registry $doctrine */
        /** @var Connection $connection */
        /** @var ClassMetadata $classMetadata */
        $doctrine      = $container->get('doctrine');
        $manager       = $doctrine->getManager();
        $schemaTool    = new SchemaTool($doctrine->getManager());
        $connection    = $doctrine->getConnection();
        $schemaManager = $connection->getSchemaManager();
        $classMetadata = $manager->getClassMetadata($className);

        if ($force || !$schemaManager->tablesExist($classMetadata->getTableName())) {

            if ($schemaManager instanceof SqliteSchemaManager) {

                $columns     = array();
                $identifiers = $classMetadata->getIdentifierColumnNames();
                foreach ($classMetadata->getFieldNames() as $fieldName) {
                    $fieldMapping = $classMetadata->getFieldMapping($fieldName);
                    $columnSql    = $fieldMapping["fieldName"];
                    switch ($fieldMapping["type"]) {
                        case 'integer':
                            $columnSql .= " INTEGER ";
                            break;

                        case 'real':
                        case 'double':
                        case 'float':
                            $columnSql .= " REAL ";
                            break;

                        case 'datetime':
                        case 'date':
                        case 'boolean':
                            $columnSql .= " INTEGER ";
                            break;

                        case 'blob':
                        case 'file':
                            $columnSql .= " BLOB ";
                            break;

                        default:
                            $columnSql .= " TEXT ";
                    }

                    // PRIMARY KEY
                    in_array($fieldName, $identifiers) && $columnSql .= "PRIMARY KEY ";
                    $columnSql .= $fieldMapping["nullable"] ? "NULL " : "NOT NULL ";
                    $columns[] = $columnSql;
                }
                $sql       = 'CREATE TABLE IF NOT EXISTS ' . $classMetadata->getTableName() . '( ' . implode(",\n", $columns) . ')';
                $statement = $connection->query($sql);
            } else {
                $schemaTool->updateSchema(array($classMetadata), true);
            }
        }
    }
723926
private function getNewEmbeddableFqnFromClassName(string $className): string
    {
        return $this->namespaceHelper->tidy(
            $this->projectRootNamespace . '\\'
            . implode('\\', \array_slice($this->archetypeObjectSubDirectories, 1))
            . '\\' . $className
        );
    }
511961
public function getClassNameFromTable(Table $table, $fqcn = false)
    {
        $namespace = $table->getNamespace();
        $class = $table->getPhpName();

        return $this->declareClassNamespace($class, $namespace, true);
    }
695864
private function getEntityByClass($className)
    {
        if (!isset($this->entities[ $className ])) {
            $entity                       = new Entity($this, $className);
            $this->entities[ $className ] = $entity;

            $this->metadataDriver->readEntityMetadata($entity);
        }

        return $this->entities[ $className ];
    }
779253
public function getHydratorClassName($fqcn)
    {
        $config = new Configuration($fqcn);
        $config->setAutoGenerateProxies($this->generateProxies);
        $config->setGeneratedClassesTargetDir($this->cacheDir);

        return $config->createFactory()->getHydratorClass();
    }