Skip to content

Commit

Permalink
CLI-1067: [remote:ssh] Typed property must not be accessed before ini…
Browse files Browse the repository at this point in the history
…tialization (#1512)
  • Loading branch information
danepowell authored May 25, 2023
1 parent 46a18f8 commit 43058df
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
4 changes: 4 additions & 0 deletions src/Command/Remote/SshCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Acquia\Cli\Command\Remote;

use Acquia\Cli\Exception\AcquiaCliException;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand All @@ -27,6 +28,9 @@ protected function execute(InputInterface $input, OutputInterface $output): ?int
$alias = $this->normalizeAlias($alias);
$alias = self::validateEnvironmentAlias($alias);
$environment = $this->getEnvironmentFromAliasArg($alias);
if (!isset($environment->sshUrl)) {
throw new AcquiaCliException('Cannot determine environment SSH URL. Check that you have SSH permissions on this environment.');
}
$sshCommand = [
'cd /var/www/html/' . $alias,
];
Expand Down
16 changes: 5 additions & 11 deletions src/Helpers/SshHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@ public function __construct(
/**
* Execute the command in a remote environment.
*
* @param \AcquiaCloudApi\Response\EnvironmentResponse|string $target
* @param array $commandArgs
* @param bool $printOutput
* @param int|null $timeout
* @return \Symfony\Component\Process\Process
*/
public function executeCommand(EnvironmentResponse|string $target, array $commandArgs, bool $printOutput = TRUE, int $timeout = NULL): Process {
$commandSummary = $this->getCommandSummary($commandArgs);
Expand Down Expand Up @@ -66,6 +69,7 @@ private function sendCommand($url, $command, $printOutput, $timeout = NULL): Pro
* Return the first item of the $commandArgs that is not an option.
*
* @param array $commandArgs
* @return string
*/
private function firstArguments(array $commandArgs): string {
$result = '';
Expand All @@ -80,9 +84,6 @@ private function firstArguments(array $commandArgs): string {
return $result;
}

/**
* @return \Closure
*/
private function getOutputCallback(): callable {
if ($this->localMachineHelper->useTty() === FALSE) {
$output = $this->output;
Expand All @@ -101,15 +102,12 @@ private function getOutputCallback(): callable {
* CI scripts.
*
* @param array $commandArgs
* @return string
*/
private function getCommandSummary(array $commandArgs): string {
return $this->firstArguments($commandArgs);
}

/**
* @param $url
* @return array SSH connection string
*/
private function getConnectionArgs($url): array {
return [
'ssh',
Expand All @@ -121,10 +119,6 @@ private function getConnectionArgs($url): array {
];
}

/**
* @param $command
* @return array
*/
private function getSshCommand(string $url, $command): array {
return array_merge($this->getConnectionArgs($url), $command);
}
Expand Down

0 comments on commit 43058df

Please sign in to comment.