private function getNewUseStatements(): string
    {
        $this->sortUseStatements();

        $file = $this->getFile()->getBaseFile();

        return implode(
            $file->eolChar,
            array_map(
                function (UseStatement $useStatement) use ($file): string {
                    $unqualifiedName = NamespaceHelper::getUnqualifiedNameFromFullyQualifiedName(
                        $useStatement->getFullyQualifiedTypeName()
                    );

                    $useTypeName = UseStatementHelper::getTypeName($file, $useStatement);
                    $useTypeFormatted = $useTypeName ? sprintf('%s ', $useTypeName) : '';

                    return ($unqualifiedName === $useStatement->getNameAsReferencedInFile())
                        ? sprintf(
                            'use %s%s;',
                            $useTypeFormatted,
                            $useStatement->getFullyQualifiedTypeName()
                        )
                        : sprintf(
                            'use %s%s as %s;',
                            $useTypeFormatted,
                            $useStatement->getFullyQualifiedTypeName(),
                            $useStatement->getNameAsReferencedInFile()
                        );
                },
                $this->useStatements
            )
        );
    }