Platformsh\Cli\Command\Environment\EnvironmentCheckoutCommand::offerBranchChoice PHP Метод

offerBranchChoice() защищенный Метод

Prompt the user to select a branch to checkout.
protected offerBranchChoice ( Platformsh\Client\Model\Project $project, string $projectRoot ) : string | false
$project Platformsh\Client\Model\Project
$projectRoot string
Результат string | false The branch name, or false on failure.
    protected function offerBranchChoice(Project $project, $projectRoot)
    {
        $environments = $this->api()->getEnvironments($project);
        $currentEnvironment = $this->getCurrentEnvironment($project);
        if ($currentEnvironment) {
            $this->stdErr->writeln("The current environment is <info>{$currentEnvironment->title}</info>.");
        }
        $environmentList = [];
        foreach ($environments as $id => $environment) {
            if ($currentEnvironment && $id == $currentEnvironment->id) {
                continue;
            }
            $environmentList[$id] = $environment->title;
        }
        $projectConfig = $this->localProject->getProjectConfig($projectRoot);
        if (!empty($projectConfig['mapping'])) {
            foreach ($projectConfig['mapping'] as $branch => $id) {
                if (isset($environmentList[$id]) && isset($environmentList[$branch])) {
                    unset($environmentList[$id]);
                    $environmentList[$branch] = sprintf('%s (%s)', $environments[$id]->title, $branch);
                }
            }
        }
        if (!count($environmentList)) {
            $this->stdErr->writeln("Use <info>" . self::$config->get('application.executable') . " branch</info> to create an environment.");
            return false;
        }
        /** @var \Platformsh\Cli\Helper\QuestionHelper $helper */
        $helper = $this->getHelper('question');
        // If there's more than one choice, present the user with a list.
        if (count($environmentList) > 1) {
            $chooseEnvironmentText = "Enter a number to check out another environment:";
            return $helper->choose($environmentList, $chooseEnvironmentText);
        } elseif ($helper->confirm(sprintf('Check out environment <info>%s</info>?', reset($environmentList)))) {
            return key($environmentList);
        }
        return false;
    }