public function getDefaultEnvironmentId(array $environments)
    {
        // If there is only one environment, use that.
        if (count($environments) <= 1) {
            $environment = reset($environments);

            return $environment ? $environment->id : null;
        }

        // Check if there is only one "main" environment.
        $main = array_filter($environments, function (Environment $environment) {
            return $environment->is_main;
        });
        if (count($main) === 1) {
            $environment = reset($main);

            return $environment ? $environment->id : null;
        }

        // Check if there is a "master" environment.
        if (isset($environments['master'])) {
            return 'master';
        }

        return null;
    }