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);
    }