public static function getApplications($directory, Config $config = null)
    {
        // Finder can be extremely slow with a deep directory structure. The
        // search depth is limited to safeguard against this.
        $finder = new Finder();
        $config = $config ?: new Config();
        $finder->in($directory)
               ->ignoreDotFiles(false)
               ->name($config->get('service.app_config_file'))
               ->ignoreUnreadableDirs()
               ->exclude([
                   '.idea',
                   $config->get('local.local_dir'),
                   'builds',
                   'node_modules',
                   'vendor',
               ])
               ->depth('< 5');

        /** @var \Platformsh\Cli\Local\LocalApplication[] $applications */
        $applications = [];

        /** @var \Symfony\Component\Finder\SplFileInfo $file */
        foreach ($finder as $file) {
            $appRoot = dirname($file->getRealPath());
            $applications[$appRoot] = new LocalApplication($appRoot, $config, $directory);
        }

        // If there are no application config files found, treat the
        // directory as a single application.
        if (empty($applications)) {
            $applications[$directory] = new LocalApplication($directory, $config, $directory);
        }

        if (count($applications) === 1) {
            foreach ($applications as $application) {
                $application->setSingle(true);
                break;
            }
        }

        return $applications;
    }