private function findProjectRoot(string $dir) : ?string
    {
        do {
            $path = $dir . '/composer.json';

            if (file_exists($path)) {
                return $dir;
            }

            $prev = $dir;
            $dir = dirname($dir);
        } while ($dir !== $prev);

        return null;
    }