Returns imports section for model.

@param string $baseNamespace base namespace to avoid importing classes from same namespace
@param array $usedClasses Array of used in model classes

@return string
347312
private function formatUsedClasses($baseNamespace, $usedClasses)
    {
        $result = [];
        foreach ($usedClasses as $usedClass) {
            // Do not import classes from same namespace
            $namespacePattern = str_replace('\\', '\\\\', "/{$baseNamespace}\\[a-zA-Z0-9_]*/");
            if (! preg_match($namespacePattern, $usedClass)) {
                $result[] = "use {$usedClass};";
            }
        }

        sort($result);

        return implode("\n", $result);
    }
884387
private function fetchNamespaces (NamespaceRegistry $entryNamespaces) : array
    {
        $namespaces = [];

        foreach ($entryNamespaces as $namespace => $path)
        {
            $namespaces[$namespace] = $this->makePathRelative($path);
        }

        return $namespaces;
    }
615671
public static function getClassesInNamespace($strNamespace)
    {
        $arrOptions = [];

        foreach (array_keys(ClassLoader::getClasses()) as $strName)
        {
            if (StringUtil::startsWith($strName, $strNamespace))
            {
                $arrOptions[$strName] = $strName;
            }
        }

        asort($arrOptions);

        return $arrOptions;
    }
676017
protected function getRequiredUseClasses(array $fields, array $additions = [])
    {
        $commands = [];

        foreach ($additions as $addition) {
            $commands[] = $this->getUseClassCommand($addition);
        }

        $collections = $this->getRelationCollections($fields, 'form');

        foreach ($collections as $collection) {
            $command = $this->getUseClassCommand($collection->getFullForeignModel());

            if (!in_array($command, $commands)) {
                $commands[] = $this->getUseClassCommand($collection->getFullForeignModel());
            }
        }

        // Attempt to include classes that don't start with \\ with using command.
        foreach ($fields as $field) {
            if (!empty($field->onStore) && !in_array($field->onStore, $commands)) {
                $commands[] = $this->extractNamespace($field->onStore);
            }

            if (!empty($field->onUpdate) && !in_array($field->onUpdate, $commands)) {
                $commands[] = $this->extractNamespace($field->onUpdate);
            }
            // Extract the name spaces fromt he custom rules
            $customRules = $this->extractCustomValidationRules($field->getValidationRule());
            $namespaces = $this->extractCustomValidationNamespaces($customRules);
            foreach ($namespaces as $namespace) {
                $commands[] = $this->getUseClassCommand($namespace);
            }
        }

        usort($commands, function ($a, $b) {
            return strlen($a) - strlen($b);
        });

        return implode(PHP_EOL, array_unique($commands));
    }
626723
public function addNamespacesToRegistry($namespaces)
    {
        collect((array) $namespaces)->each(function ($namespace) {
            // Get path from namespace.
            $path = $this->getPathFromNamespace($namespace);

            if (file_exists($path)) {
                // Register each annotations file found in the namespace.
                foreach (Finder::create()->files()->name('*.php')->in($path) as $file) {
                    $this->addFilesToRegistry($file->getRealPath());
                }
            }
        });

        return $this;
    }
1305022
public function getDescriptor(string $classNamespace): ?Descriptor
    {
        if (!$this->isEmpty()) {
            /** @var Descriptor $descriptor */
            foreach ($this as $rootNamespace => $descriptor) {
                $rootNamespace = $descriptor->getRootNamespace();

                $doubleSlashed = str_replace('\\', '\\\\', $rootNamespace);
                $pattern = sprintf('|^%s\\.*|', $doubleSlashed);

                if (preg_match($pattern, $classNamespace)) {
                    return $descriptor;
                }
            }
        }

        return null;
    }
714888
public function getClassFromUse($coverClassName, $usedClasses)
    {
        if (false === is_array($usedClasses)) {
            return $coverClassName;
        }

        foreach ($usedClasses as $use) {
            $this->getClassNameFromClassFQN($use);
            if ($coverClassName === $this->getClassNameFromClassFQN($use)) {
                return $use;
            }
        }

        return $coverClassName;
    }
923325
private function getMetadataForNamespace($namespace)
    {
        $metadata = [];
        foreach ($this->getAllMetadata() as $m) {
            if (strpos($m->name, $namespace) !== 0) {
                continue;
            }

            $metadata[] = $m;
        }

        return new ClassMetadataCollection($metadata);
    }
505409
private function getNamespaceUseDeclarations(Tokens $tokens, array $useIndexes)
    {
        $uses = array();

        foreach ($useIndexes as $index) {
            $declarationEndIndex = $tokens->getNextTokenOfKind($index, array(';'));
            $declarationContent = $tokens->generatePartialCode($index + 1, $declarationEndIndex - 1);

            // ignore multiple use statements like: `use BarB, BarC as C, BarD;`
            // that should be split into few separate statements
            if (false !== strpos($declarationContent, ',')) {
                continue;
            }

            $declarationParts = preg_split('/\s+as\s+/i', $declarationContent);

            if (1 === count($declarationParts)) {
                $fullName = $declarationContent;
                $declarationParts = explode('\\', $fullName);
                $shortName = end($declarationParts);
                $aliased = false;
            } else {
                $fullName = $declarationParts[0];
                $shortName = $declarationParts[1];
                $declarationParts = explode('\\', $fullName);
                $aliased = $shortName !== end($declarationParts);
            }

            $shortName = trim($shortName);

            $uses[$shortName] = array(
                'aliased' => $aliased,
                'end' => $declarationEndIndex,
                'fullName' => trim($fullName),
                'shortName' => $shortName,
                'start' => $index,
            );
        }

        return $uses;
    }
580626
private function extractUsedClasses(&$placeholder)
    {
        $classNamespaceRegExp = '/([\\\\a-zA-Z0-9_]*\\\\[\\\\a-zA-Z0-9_]*)/';
        $matches = [];
        $usedInModelClasses = [];
        if (preg_match_all($classNamespaceRegExp, $placeholder, $matches)) {
            foreach ($matches[1] as $match) {
                $usedClassName = $match;
                $usedInModelClasses[] = trim($usedClassName, '\\');
                $namespaceParts = explode('\\', $usedClassName);
                $resultClassName = array_pop($namespaceParts);
                $placeholder = str_replace($usedClassName, $resultClassName, $placeholder);
            }
        }

        return array_unique($usedInModelClasses);
    }
585774
private function getByNamespace($namespace)
    {
        $this->checkForNonEmptyNamespace($namespace);

        if (!isset($this->configurations[$namespace])) {
            $this->configurations[$namespace]
                = $this->retrieveConfigurationFromTypoScriptSetup($namespace);
        }

        return $this->configurations[$namespace];
    }
561227
protected function loadNamespaceOverrides(array $lines, $locale, $group, $namespace)
	{
		$file = "{$this->path}/packages/{$locale}/{$namespace}/{$group}.php";

		if ($this->files->exists($file))
		{
			return array_replace_recursive($lines, $this->files->getRequire($file));
		}

		return $lines;
	}
603956
private function matchUseImports(Tokens $tokens, string $className): ?string
    {
        $namespaceUseAnalyses = $this->namespaceUsesAnalyzer->getDeclarationsFromTokens($tokens);

        foreach ($namespaceUseAnalyses as $namespaceUseAnalysis) {
            if ($className === $namespaceUseAnalysis->getShortName()) {
                return $namespaceUseAnalysis->getFullName();
            }
        }

        return null;
    }
267420
public function toNamespacedString($namespace, array $aliased_classes, $this_class, $use_phpdoc_format)
    {
        $printed_int = false;
        $printed_float = false;
        $printed_string = false;

        $s = '';

        foreach ($this->types as $type) {
            if ($type instanceof TLiteralFloat) {
                if ($printed_float) {
                    continue;
                }

                $printed_float = true;
            } elseif ($type instanceof TLiteralString) {
                if ($printed_string) {
                    continue;
                }

                $printed_string = true;
            } elseif ($type instanceof TLiteralInt) {
                if ($printed_int) {
                    continue;
                }

                $printed_int = true;
            }

            $s .= $type->toNamespacedString($namespace, $aliased_classes, $this_class, $use_phpdoc_format) . '|';
        }

        return substr($s, 0, -1) ?: '';
    }
210466
public static function getNamespaces()
    {
        $called = get_called_class();

        if (!isset(static::$namespaces[$called])) {
            static::$namespaces[$called] = new PriorityQueue();
        }

        return static::$namespaces[$called];
    }
164573
public function setTypeName(string $typeName, array $use = [], string $nameSpace = ''): TypeModel
    {
        $types = ['string', 'int', 'float', 'array', 'bool', 'callable'];
        $this->typeName = $typeName;
        if (!in_array($typeName, $types) && strpos($typeName, '|') === false) {
            foreach ($use as $item) {
                $items = explode('\\', $item);
                $className = array_pop($items);
                if ($className == $typeName) {
                    $this->setClassName('\\'.$item);
                    break;
                }
            }
            if (!$this->getClassName()) {
                if (strpos($typeName, '\\') !== false) {
                    $this->setClassName($typeName);
                } else {
                    $this->setClassName($nameSpace.'\\'.$typeName);
                }
            }
        }

        return $this;
    }
1353438
public function get_namespace_parts( $classname, $first_only = false ) {
		// Trim any left-slashes from our string
		$classname = ltrim( $classname, '\\' );

		if ( $first_only === true ) {
			return substr( $classname, 0, strpos( $classname, '\\' ) );
		}

		return explode( '\\', $classname );
	}