Skip to content

Commit

Permalink
Handle else and elseif blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
pjcdawkins committed Nov 27, 2024
1 parent ab85059 commit cb37145
Show file tree
Hide file tree
Showing 21 changed files with 70 additions and 99 deletions.
8 changes: 3 additions & 5 deletions src/Command/Activity/ActivityCancelCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#[AsCommand(name: 'activity:cancel', description: 'Cancel an activity')]
class ActivityCancelCommand extends ActivityCommandBase
{
public function __construct(private readonly ActivityLoader $activityLoader, private readonly Api $api, private readonly Config $config)
public function __construct(private readonly ActivityLoader $activityLoader, private readonly Api $api, private readonly Config $config, private readonly PropertyFormatter $propertyFormatter, private readonly QuestionHelper $questionHelper)
{
parent::__construct();
}
Expand Down Expand Up @@ -82,10 +82,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return 1;
}
$choices = [];
/** @var QuestionHelper $questionHelper */
$questionHelper = $this->getService('question_helper');
/** @var PropertyFormatter $formatter */
$formatter = $this->getService('property_formatter');
$questionHelper = $this->questionHelper;
$formatter = $this->propertyFormatter;
$byId = [];
$this->api->sortResources($activities, 'created_at');
foreach ($activities as $activity) {
Expand Down
5 changes: 2 additions & 3 deletions src/Command/Auth/BrowserLoginCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#[AsCommand(name: 'auth:browser-login', description: 'Log in to via a browser', aliases: ['login'])]
class BrowserLoginCommand extends CommandBase
{
public function __construct(private readonly Api $api, private readonly Config $config, private readonly Url $url)
public function __construct(private readonly Api $api, private readonly Config $config, private readonly QuestionHelper $questionHelper, private readonly Url $url)
{
parent::__construct();
}
Expand Down Expand Up @@ -86,8 +86,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
));

if ($input->isInteractive()) {
/** @var QuestionHelper $questionHelper */
$questionHelper = $this->getService('question_helper');
$questionHelper = $this->questionHelper;
if (!$questionHelper->confirm('Log in anyway?', false)) {
return 1;
}
Expand Down
5 changes: 2 additions & 3 deletions src/Command/Backup/BackupGetCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
class BackupGetCommand extends CommandBase
{

public function __construct(private readonly PropertyFormatter $propertyFormatter)
public function __construct(private readonly PropertyFormatter $propertyFormatter, private readonly QuestionHelper $questionHelper)
{
parent::__construct();
}
Expand Down Expand Up @@ -58,8 +58,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}
$choices[$id] = sprintf('%s (%s)', $backup->id, $formatter->format($backup->created_at, 'created_at'));
}
/** @var QuestionHelper $questionHelper */
$questionHelper = $this->getService('question_helper');
$questionHelper = $this->questionHelper;
$choice = $questionHelper->choose($choices, 'Enter a number to choose a backup:', $default);
$backup = $byId[$choice];
}
Expand Down
28 changes: 1 addition & 27 deletions src/Command/CommandBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -439,8 +439,6 @@ protected function checkUpdates()

// Ensure classes are auto-loaded if they may be needed after the
// update.
$this->getService('question_helper');
$this->getService('shell');
$currentVersion = $this->config->getVersion();

$cliUpdater = $this->selfUpdater;
Expand Down Expand Up @@ -1418,8 +1416,7 @@ protected function selectRemoteContainer(InputInterface $input, $includeWorkers
if (count($appNames) === 1) {
$choice = reset($appNames);
} elseif ($input->isInteractive()) {
/** @var QuestionHelper $questionHelper */
$questionHelper = $this->getService('question_helper');
$questionHelper = $this->questionHelper;
if ($choicesIncludeWorkers) {
$text = sprintf('Enter a number to choose an app or %s worker:',
count($choices) === 2 ? 'its' : 'a'
Expand Down Expand Up @@ -1944,29 +1941,6 @@ private function labeledMessage($label, $message, $options = 0)
}
}

/**
* Get a service object.
*
* Services are configured in services.yml, and loaded via the Symfony
* Dependency Injection component.
*
* When using this method, always store the result in a temporary variable,
* so that the service's type can be hinted in a variable docblock (allowing
* IDEs and other analysers to check subsequent code). For example:
* <code>
* /** @var \Platformsh\Cli\Service\Filesystem $fs *\/
* $fs = $this->getService('fs');
* </code>
*
* @param string $name The service name. See services.yml for a list.
*
* @return object The associated service object.
*/
protected function getService($name)
{
return $this->container()->get($name);
}

/**
* @return ContainerBuilder
*/
Expand Down
5 changes: 2 additions & 3 deletions src/Command/Db/DbSqlCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
class DbSqlCommand extends CommandBase
{

public function __construct(private readonly Api $api, private readonly Relationships $relationships)
public function __construct(private readonly Api $api, private readonly QuestionHelper $questionHelper, private readonly Relationships $relationships)
{
parent::__construct();
}
Expand Down Expand Up @@ -98,8 +98,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$choices[$schema] .= ' (default)';
}
}
/** @var QuestionHelper $questionHelper */
$questionHelper = $this->getService('question_helper');
$questionHelper = $this->questionHelper;
$schema = $questionHelper->choose($choices, 'Enter a number to choose a schema:', $default, true);
$schema = $schema === '(none)' ? '' : $schema;
}
Expand Down
5 changes: 2 additions & 3 deletions src/Command/Domain/DomainCommandBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ abstract class DomainCommandBase extends CommandBase

protected $attach;

public function __construct(private readonly Api $api, private readonly Config $config)
public function __construct(private readonly Api $api, private readonly Config $config, private readonly QuestionHelper $questionHelper)
{
parent::__construct();
}
Expand Down Expand Up @@ -138,8 +138,7 @@ protected function validateDomainInput(InputInterface $input)
$choices[$productionDomain->name] = $productionDomain->name;
}
}
/** @var QuestionHelper $questionHelper */
$questionHelper = $this->getService('question_helper');
$questionHelper = $this->questionHelper;
$questionText = '<options=bold>Attachment</> (<info>--attach</info>)'
. "\nA non-production domain must be attached to an existing production domain."
. "\nIt will inherit the same routing behavior."
Expand Down
5 changes: 2 additions & 3 deletions src/Command/Domain/DomainGetCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
class DomainGetCommand extends DomainCommandBase
{

public function __construct(private readonly Api $api, private readonly Config $config, private readonly PropertyFormatter $propertyFormatter, private readonly Table $table)
public function __construct(private readonly Api $api, private readonly Config $config, private readonly PropertyFormatter $propertyFormatter, private readonly QuestionHelper $questionHelper, private readonly Table $table)
{
parent::__construct();
}
Expand Down Expand Up @@ -67,8 +67,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$options[$domain->name] = $domain->name;
$byName[$domain->name] = $domain;
}
/** @var QuestionHelper $questionHelper */
$questionHelper = $this->getService('question_helper');
$questionHelper = $this->questionHelper;
$domainName = $questionHelper->choose($options, 'Enter a number to choose a domain:');
$domain = $byName[$domainName];
}
Expand Down
7 changes: 3 additions & 4 deletions src/Command/Environment/EnvironmentHttpAccessCommand.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php
namespace Platformsh\Cli\Command\Environment;

use Platformsh\Cli\Service\ActivityMonitor;
use Platformsh\Cli\Service\Api;
use Platformsh\Cli\Service\PropertyFormatter;
use Platformsh\Cli\Service\ActivityMonitor;
use Platformsh\Cli\Command\CommandBase;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Exception\InvalidArgumentException;
Expand All @@ -15,7 +15,7 @@
class EnvironmentHttpAccessCommand extends CommandBase
{

public function __construct(private readonly Api $api, private readonly PropertyFormatter $propertyFormatter)
public function __construct(private readonly ActivityMonitor $activityMonitor, private readonly Api $api, private readonly PropertyFormatter $propertyFormatter)
{
parent::__construct();
}
Expand Down Expand Up @@ -212,8 +212,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
if (!$result->countActivities()) {
$this->redeployWarning();
} elseif ($this->shouldWait($input)) {
/** @var ActivityMonitor $activityMonitor */
$activityMonitor = $this->getService('activity_monitor');
$activityMonitor = $this->activityMonitor;
$success = $activityMonitor->waitMultiple($result->getActivities(), $this->getSelectedProject());
}

Expand Down
12 changes: 7 additions & 5 deletions src/Command/Environment/EnvironmentLogCommand.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php
namespace Platformsh\Cli\Command\Environment;

use Platformsh\Cli\Service\QuestionHelper;
use Doctrine\Common\Cache\CacheProvider;
use Platformsh\Cli\Service\QuestionHelper;
use Platformsh\Cli\Command\CommandBase;
use Platformsh\Cli\Util\OsUtil;
use Platformsh\Cli\Util\StringUtil;
Expand All @@ -19,6 +19,10 @@
class EnvironmentLogCommand extends CommandBase implements CompletionAwareInterface
{

public function __construct(private readonly CacheProvider $cacheProvider, private readonly QuestionHelper $questionHelper)
{
parent::__construct();
}
protected function configure()
{
$this
Expand Down Expand Up @@ -67,13 +71,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$this->stdErr->writeln('No log type specified.');
return 1;
} else {
/** @var QuestionHelper $questionHelper */
$questionHelper = $this->getService('question_helper');
$questionHelper = $this->questionHelper;

// Read the list of files from the environment.
$cacheKey = sprintf('log-files:%s', $host->getCacheKey());
/** @var CacheProvider $cache */
$cache = $this->getService('cache');
$cache = $this->cacheProvider;
if (!$result = $cache->fetch($cacheKey)) {
$result = $host->runCommand('echo -n _BEGIN_FILE_LIST_; ls -1 ' . $logDir . '/*.log; echo -n _END_FILE_LIST_');
if (is_string($result)) {
Expand Down
5 changes: 2 additions & 3 deletions src/Command/Environment/EnvironmentUrlCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
class EnvironmentUrlCommand extends CommandBase
{

public function __construct(private readonly Api $api, private readonly Config $config, private readonly Url $url)
public function __construct(private readonly Api $api, private readonly Config $config, private readonly QuestionHelper $questionHelper, private readonly Url $url)
{
parent::__construct();
}
Expand Down Expand Up @@ -120,8 +120,7 @@ private function displayOrOpenUrls(array $urls, InputInterface $input, OutputInt
if (count($urls) === 1) {
$url = $urls[0];
} else {
/** @var QuestionHelper $questionHelper */
$questionHelper = $this->getService('question_helper');
$questionHelper = $this->questionHelper;
$url = $questionHelper->choose(array_combine($urls, $urls), 'Enter a number to open a URL', $urls[0]);
}

Expand Down
7 changes: 3 additions & 4 deletions src/Command/Integration/IntegrationCommandBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
use Platformsh\Cli\Service\Api;
use Platformsh\Cli\Local\LocalProject;
use Platformsh\Cli\Service\PropertyFormatter;
use Platformsh\Cli\Service\Table;
use Platformsh\Cli\Service\QuestionHelper;
use Platformsh\Cli\Service\Table;
use GuzzleHttp\Exception\BadResponseException;
use GuzzleHttp\Utils;
use Platformsh\Cli\Command\CommandBase;
Expand All @@ -30,7 +30,7 @@ abstract class IntegrationCommandBase extends CommandBase
/** @var array */
private $bitbucketAccessTokens = [];

public function __construct(private readonly Api $api, private readonly LocalProject $localProject, private readonly PropertyFormatter $propertyFormatter, private readonly Table $table)
public function __construct(private readonly Api $api, private readonly LocalProject $localProject, private readonly PropertyFormatter $propertyFormatter, private readonly QuestionHelper $questionHelper, private readonly Table $table)
{
parent::__construct();
}
Expand All @@ -54,8 +54,7 @@ protected function selectIntegration(Project $project, $id, $interactive) {

return false;
}
/** @var QuestionHelper $questionHelper */
$questionHelper = $this->getService('question_helper');
$questionHelper = $this->questionHelper;
$choices = [];
foreach ($integrations as $integration) {
$choices[$integration->id] = sprintf('%s (%s)', $integration->id, $integration->type);
Expand Down
7 changes: 3 additions & 4 deletions src/Command/Mount/MountUploadCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

namespace Platformsh\Cli\Command\Mount;

use Platformsh\Cli\Local\ApplicationFinder;
use Platformsh\Cli\Service\Config;
use Platformsh\Cli\Service\Filesystem;
use Platformsh\Cli\Service\Mount;
use Platformsh\Cli\Service\QuestionHelper;
use Platformsh\Cli\Service\Rsync;
use Platformsh\Cli\Local\ApplicationFinder;
use Platformsh\Cli\Command\CommandBase;
use Platformsh\Cli\Service\Ssh;
use Platformsh\Cli\Util\OsUtil;
Expand All @@ -21,7 +21,7 @@
class MountUploadCommand extends CommandBase
{

public function __construct(private readonly Config $config, private readonly Filesystem $filesystem, private readonly Mount $mount, private readonly QuestionHelper $questionHelper, private readonly Rsync $rsync)
public function __construct(private readonly ApplicationFinder $applicationFinder, private readonly Config $config, private readonly Filesystem $filesystem, private readonly Mount $mount, private readonly QuestionHelper $questionHelper, private readonly Rsync $rsync)
{
parent::__construct();
}
Expand Down Expand Up @@ -98,8 +98,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}
}

/** @var ApplicationFinder $finder */
$finder = $this->getService('app_finder');
$finder = $this->applicationFinder;
$applications = $finder->findApplications($projectRoot);
$appPath = $projectRoot;
foreach ($applications as $path => $candidateApp) {
Expand Down
8 changes: 3 additions & 5 deletions src/Command/Repo/RepoCommandBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

class RepoCommandBase extends CommandBase
{
public function __construct(private readonly Config $config)
public function __construct(private readonly Config $config, private readonly GitDataApi $gitDataApi)
{
parent::__construct();
}
Expand All @@ -39,8 +39,7 @@ protected function cat(Environment $environment, InputInterface $input, OutputIn
{
$path = $input->getArgument('path');
try {
/** @var GitDataApi $gitData */
$gitData = $this->getService('git_data_api');
$gitData = $this->gitDataApi;
$content = $gitData->readFile($path, $environment, $input->getOption('commit'));
} catch (GitObjectTypeException $e) {
$this->stdErr->writeln(sprintf(
Expand Down Expand Up @@ -75,8 +74,7 @@ protected function cat(Environment $environment, InputInterface $input, OutputIn
protected function ls(Environment $environment, InputInterface $input, OutputInterface $output)
{
try {
/** @var GitDataApi $gitData */
$gitData = $this->getService('git_data_api');
$gitData = $this->gitDataApi;
$tree = $gitData->getTree($environment, $input->getArgument('path'), $input->getOption('commit'));
} catch (GitObjectTypeException $e) {
$this->stdErr->writeln(sprintf(
Expand Down
5 changes: 2 additions & 3 deletions src/Command/Resources/ResourcesSizeListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class ResourcesSizeListCommand extends ResourcesCommandBase
{
protected $tableHeader = ['size' => 'Size name', 'cpu' => 'CPU', 'memory' => 'Memory (MB)'];

public function __construct(private readonly Api $api, private readonly Table $table)
public function __construct(private readonly Api $api, private readonly QuestionHelper $questionHelper, private readonly Table $table)
{
parent::__construct();
}
Expand Down Expand Up @@ -67,8 +67,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return 1;
}
} elseif ($input->isInteractive()) {
/** @var QuestionHelper $questionHelper */
$questionHelper = $this->getService('question_helper');
$questionHelper = $this->questionHelper;
$options = [];
foreach ($servicesByProfile as $profile => $serviceNames) {
$options[$profile] = sprintf('%s (for %s: %s)', $profile, count($serviceNames) === 1 ? 'service' : 'services', implode(', ', $serviceNames));
Expand Down
Loading

0 comments on commit cb37145

Please sign in to comment.