From cb37145414d19a17a000a4a06ac3a9aff91e9d25 Mon Sep 17 00:00:00 2001 From: Patrick Dawkins Date: Wed, 27 Nov 2024 14:44:28 +0000 Subject: [PATCH] Handle else and elseif blocks --- .../Activity/ActivityCancelCommand.php | 8 ++---- src/Command/Auth/BrowserLoginCommand.php | 5 ++-- src/Command/Backup/BackupGetCommand.php | 5 ++-- src/Command/CommandBase.php | 28 +------------------ src/Command/Db/DbSqlCommand.php | 5 ++-- src/Command/Domain/DomainCommandBase.php | 5 ++-- src/Command/Domain/DomainGetCommand.php | 5 ++-- .../EnvironmentHttpAccessCommand.php | 7 ++--- .../Environment/EnvironmentLogCommand.php | 12 ++++---- .../Environment/EnvironmentUrlCommand.php | 5 ++-- .../Integration/IntegrationCommandBase.php | 7 ++--- src/Command/Mount/MountUploadCommand.php | 7 ++--- src/Command/Repo/RepoCommandBase.php | 8 ++---- .../Resources/ResourcesSizeListCommand.php | 5 ++-- src/Command/Self/SelfInstallCommand.php | 11 ++++---- src/Command/SshKey/SshKeyListCommand.php | 8 ++---- .../Variable/VariableCreateCommand.php | 7 ++--- .../Variable/VariableDeleteCommand.php | 7 ++--- src/Command/Variable/VariableSetCommand.php | 8 ++++-- .../Variable/VariableUpdateCommand.php | 8 ++++-- src/InjectCommandServicesRector.php | 8 +++++- 21 files changed, 70 insertions(+), 99 deletions(-) diff --git a/src/Command/Activity/ActivityCancelCommand.php b/src/Command/Activity/ActivityCancelCommand.php index 5c598f892..14fff437d 100644 --- a/src/Command/Activity/ActivityCancelCommand.php +++ b/src/Command/Activity/ActivityCancelCommand.php @@ -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(); } @@ -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) { diff --git a/src/Command/Auth/BrowserLoginCommand.php b/src/Command/Auth/BrowserLoginCommand.php index 0b17b8bd1..0a764bb4e 100644 --- a/src/Command/Auth/BrowserLoginCommand.php +++ b/src/Command/Auth/BrowserLoginCommand.php @@ -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(); } @@ -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; } diff --git a/src/Command/Backup/BackupGetCommand.php b/src/Command/Backup/BackupGetCommand.php index d6299fabd..2c72dae72 100644 --- a/src/Command/Backup/BackupGetCommand.php +++ b/src/Command/Backup/BackupGetCommand.php @@ -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(); } @@ -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]; } diff --git a/src/Command/CommandBase.php b/src/Command/CommandBase.php index f2d73a972..0165360cb 100644 --- a/src/Command/CommandBase.php +++ b/src/Command/CommandBase.php @@ -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; @@ -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' @@ -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: - * - * /** @var \Platformsh\Cli\Service\Filesystem $fs *\/ - * $fs = $this->getService('fs'); - * - * - * @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 */ diff --git a/src/Command/Db/DbSqlCommand.php b/src/Command/Db/DbSqlCommand.php index 1f3ec4b08..57e1a7305 100644 --- a/src/Command/Db/DbSqlCommand.php +++ b/src/Command/Db/DbSqlCommand.php @@ -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(); } @@ -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; } diff --git a/src/Command/Domain/DomainCommandBase.php b/src/Command/Domain/DomainCommandBase.php index 54e3ed63f..1bf3b5636 100644 --- a/src/Command/Domain/DomainCommandBase.php +++ b/src/Command/Domain/DomainCommandBase.php @@ -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(); } @@ -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 = 'Attachment (--attach)' . "\nA non-production domain must be attached to an existing production domain." . "\nIt will inherit the same routing behavior." diff --git a/src/Command/Domain/DomainGetCommand.php b/src/Command/Domain/DomainGetCommand.php index 495add56b..e64e4e790 100644 --- a/src/Command/Domain/DomainGetCommand.php +++ b/src/Command/Domain/DomainGetCommand.php @@ -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(); } @@ -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]; } diff --git a/src/Command/Environment/EnvironmentHttpAccessCommand.php b/src/Command/Environment/EnvironmentHttpAccessCommand.php index 9b6b7f4ef..2b5c40663 100644 --- a/src/Command/Environment/EnvironmentHttpAccessCommand.php +++ b/src/Command/Environment/EnvironmentHttpAccessCommand.php @@ -1,9 +1,9 @@ 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()); } diff --git a/src/Command/Environment/EnvironmentLogCommand.php b/src/Command/Environment/EnvironmentLogCommand.php index 228e71859..8ea768026 100644 --- a/src/Command/Environment/EnvironmentLogCommand.php +++ b/src/Command/Environment/EnvironmentLogCommand.php @@ -1,8 +1,8 @@ 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)) { diff --git a/src/Command/Environment/EnvironmentUrlCommand.php b/src/Command/Environment/EnvironmentUrlCommand.php index a7350a9d8..d49da856d 100644 --- a/src/Command/Environment/EnvironmentUrlCommand.php +++ b/src/Command/Environment/EnvironmentUrlCommand.php @@ -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(); } @@ -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]); } diff --git a/src/Command/Integration/IntegrationCommandBase.php b/src/Command/Integration/IntegrationCommandBase.php index c3ce74ab3..b0e68efe3 100644 --- a/src/Command/Integration/IntegrationCommandBase.php +++ b/src/Command/Integration/IntegrationCommandBase.php @@ -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; @@ -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(); } @@ -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); diff --git a/src/Command/Mount/MountUploadCommand.php b/src/Command/Mount/MountUploadCommand.php index 7635b4c8e..1644808c4 100644 --- a/src/Command/Mount/MountUploadCommand.php +++ b/src/Command/Mount/MountUploadCommand.php @@ -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; @@ -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(); } @@ -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) { diff --git a/src/Command/Repo/RepoCommandBase.php b/src/Command/Repo/RepoCommandBase.php index 8ea9a334e..69f101833 100644 --- a/src/Command/Repo/RepoCommandBase.php +++ b/src/Command/Repo/RepoCommandBase.php @@ -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(); } @@ -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( @@ -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( diff --git a/src/Command/Resources/ResourcesSizeListCommand.php b/src/Command/Resources/ResourcesSizeListCommand.php index 625f8e878..d502b231d 100644 --- a/src/Command/Resources/ResourcesSizeListCommand.php +++ b/src/Command/Resources/ResourcesSizeListCommand.php @@ -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(); } @@ -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)); diff --git a/src/Command/Self/SelfInstallCommand.php b/src/Command/Self/SelfInstallCommand.php index f79f2fa75..df49c09ff 100644 --- a/src/Command/Self/SelfInstallCommand.php +++ b/src/Command/Self/SelfInstallCommand.php @@ -2,9 +2,9 @@ namespace Platformsh\Cli\Command\Self; use Platformsh\Cli\Service\Config; +use Platformsh\Cli\Service\Filesystem; use Platformsh\Cli\Service\QuestionHelper; use Platformsh\Cli\Service\Shell; -use Symfony\Component\Filesystem\Filesystem; use Platformsh\Cli\Command\CommandBase; use Platformsh\Cli\CredentialHelper\Manager; use Platformsh\Cli\Util\OsUtil; @@ -21,7 +21,7 @@ class SelfInstallCommand extends CommandBase const INSTALLED_FILENAME = 'self_installed'; protected $local = true; - public function __construct(private readonly Config $config, private readonly QuestionHelper $questionHelper, private readonly Shell $shell) + public function __construct(private readonly Config $config, private readonly Filesystem $filesystem, private readonly QuestionHelper $questionHelper, private readonly Shell $shell) { parent::__construct(); } @@ -51,7 +51,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int if ($this->config->get('application.executable') === 'platform') { $requiredFiles['shell-config-bash.rc'] = 'shell-config-bash-direct.tmpl.rc'; } - $fs = new Filesystem(); + $fs = new \Symfony\Component\Filesystem\Filesystem(); try { foreach ($requiredFiles as $destFile => $sourceFile) { if (($contents = file_get_contents(CLI_ROOT . DIRECTORY_SEPARATOR . $sourceFile)) === false) { @@ -149,8 +149,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $this->debug(sprintf('Shell config detection disabled via %s', $shellConfigOverrideVar)); $shellConfigFile = false; } elseif ($shellConfigOverride !== false) { - /** @var \Platformsh\Cli\Service\Filesystem $fsService */ - $fsService = $this->getService('fs'); + $fsService = $this->filesystem; if (!$fsService->canWrite($shellConfigOverride)) { throw new \RuntimeException(sprintf( 'File not writable: %s (defined in %s)', @@ -299,7 +298,7 @@ private function markSelfInstalled($configDir) { $filename = $configDir . DIRECTORY_SEPARATOR . self::INSTALLED_FILENAME; if (!file_exists($filename)) { - $fs = new Filesystem(); + $fs = new \Symfony\Component\Filesystem\Filesystem(); $fs->dumpFile($filename, json_encode(['installed_at' => date('c')])); } } diff --git a/src/Command/SshKey/SshKeyListCommand.php b/src/Command/SshKey/SshKeyListCommand.php index 506a9cbc5..a60ea936b 100644 --- a/src/Command/SshKey/SshKeyListCommand.php +++ b/src/Command/SshKey/SshKeyListCommand.php @@ -20,7 +20,7 @@ class SshKeyListCommand extends SshKeyCommandBase ]; private $defaultColumns = ['id', 'title', 'path']; - public function __construct(private readonly Api $api, private readonly Config $config) + public function __construct(private readonly Api $api, private readonly Config $config, private readonly SshKey $sshKey, private readonly Table $table) { parent::__construct(); } @@ -44,10 +44,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int $this->config->get('service.name') )); } else { - /** @var Table $table */ - $table = $this->getService('table'); - /** @var SshKey $sshKeyService */ - $sshKeyService = $this->getService('ssh_key'); + $table = $this->table; + $sshKeyService = $this->sshKey; $rows = []; foreach ($keys as $key) { $row = ['id' => $key->key_id, 'title' => $key->title, 'fingerprint' => $key->fingerprint]; diff --git a/src/Command/Variable/VariableCreateCommand.php b/src/Command/Variable/VariableCreateCommand.php index ded101e92..70d0483d1 100644 --- a/src/Command/Variable/VariableCreateCommand.php +++ b/src/Command/Variable/VariableCreateCommand.php @@ -2,10 +2,10 @@ namespace Platformsh\Cli\Command\Variable; +use Platformsh\Cli\Service\ActivityMonitor; use Platformsh\Cli\Service\Api; use Platformsh\Cli\Service\Config; use Platformsh\Cli\Service\QuestionHelper; -use Platformsh\Cli\Service\ActivityMonitor; use GuzzleHttp\Exception\BadResponseException; use Platformsh\Client\Model\ProjectLevelVariable; use Platformsh\Client\Model\Variable; @@ -23,7 +23,7 @@ class VariableCreateCommand extends VariableCommandBase /** @var Form */ private $form; - public function __construct(private readonly Api $api, private readonly Config $config, private readonly QuestionHelper $questionHelper) + public function __construct(private readonly ActivityMonitor $activityMonitor, private readonly Api $api, private readonly Config $config, private readonly QuestionHelper $questionHelper) { parent::__construct(); } @@ -230,8 +230,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int if (!$result->countActivities() || $level === self::LEVEL_PROJECT) { $this->redeployWarning(); } elseif ($this->shouldWait($input)) { - /** @var ActivityMonitor $activityMonitor */ - $activityMonitor = $this->getService('activity_monitor'); + $activityMonitor = $this->activityMonitor; $success = $activityMonitor->waitMultiple($result->getActivities(), $this->getSelectedProject()); } diff --git a/src/Command/Variable/VariableDeleteCommand.php b/src/Command/Variable/VariableDeleteCommand.php index efaf549ee..21536936e 100644 --- a/src/Command/Variable/VariableDeleteCommand.php +++ b/src/Command/Variable/VariableDeleteCommand.php @@ -1,9 +1,9 @@ countActivities() || $level === self::LEVEL_PROJECT) { $this->redeployWarning(); } elseif ($this->shouldWait($input)) { - /** @var ActivityMonitor $activityMonitor */ - $activityMonitor = $this->getService('activity_monitor'); + $activityMonitor = $this->activityMonitor; $success = $activityMonitor->waitMultiple($result->getActivities(), $this->getSelectedProject()); } diff --git a/src/Command/Variable/VariableSetCommand.php b/src/Command/Variable/VariableSetCommand.php index 258782675..c9d0ba9ca 100644 --- a/src/Command/Variable/VariableSetCommand.php +++ b/src/Command/Variable/VariableSetCommand.php @@ -19,6 +19,11 @@ class VariableSetCommand extends CommandBase protected $hiddenInList = true; protected $stability = 'deprecated'; + public function __construct(private readonly ActivityMonitor $activityMonitor) + { + parent::__construct(); + } + /** * {@inheritdoc} */ @@ -74,8 +79,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()); } diff --git a/src/Command/Variable/VariableUpdateCommand.php b/src/Command/Variable/VariableUpdateCommand.php index ea1b84d89..b56406007 100644 --- a/src/Command/Variable/VariableUpdateCommand.php +++ b/src/Command/Variable/VariableUpdateCommand.php @@ -16,6 +16,11 @@ class VariableUpdateCommand extends VariableCommandBase /** @var Form */ private $form; + public function __construct(private readonly ActivityMonitor $activityMonitor) + { + parent::__construct(); + } + /** * {@inheritdoc} */ @@ -91,8 +96,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int if (!$result->countActivities() || $level === self::LEVEL_PROJECT) { $this->redeployWarning(); } elseif ($this->shouldWait($input)) { - /** @var ActivityMonitor $activityMonitor */ - $activityMonitor = $this->getService('activity_monitor'); + $activityMonitor = $this->activityMonitor; $success = $activityMonitor->waitMultiple($result->getActivities(), $this->getSelectedProject()); } diff --git a/src/InjectCommandServicesRector.php b/src/InjectCommandServicesRector.php index 20f44b577..190361574 100644 --- a/src/InjectCommandServicesRector.php +++ b/src/InjectCommandServicesRector.php @@ -124,8 +124,14 @@ private function findAssignmentsRecursively(array $stmts): array { $assignments = []; foreach ($stmts as $stmt) { - if ($stmt instanceof Block || $stmt instanceof Node\Stmt\ElseIf_ || $stmt instanceof Node\Stmt\If_) { + if (property_exists($stmt, 'stmts') && is_array($stmt->stmts)) { $assignments = array_merge($assignments, $this->findAssignmentsRecursively($stmt->stmts)); + if ($stmt instanceof Node\Stmt\If_) { + $assignments = array_merge($assignments, $this->findAssignmentsRecursively($stmt->elseifs)); + if ($stmt->else !== null) { + $assignments = array_merge($assignments, $this->findAssignmentsRecursively($stmt->else->stmts)); + } + } } elseif ($stmt instanceof Expression) { $expr = &$stmt->expr; if ($expr instanceof Assign) {