diff --git a/src/Command/CommandBase.php b/src/Command/CommandBase.php index 691a7c5c1..bff811383 100644 --- a/src/Command/CommandBase.php +++ b/src/Command/CommandBase.php @@ -48,6 +48,7 @@ use Psr\Log\LoggerAwareInterface; use Psr\Log\LoggerAwareTrait; use Psr\Log\LoggerInterface; +use Safe\Exceptions\FilesystemException; use stdClass; use Symfony\Component\Cache\Adapter\FilesystemAdapter; use Symfony\Component\Console\Command\Command; @@ -454,16 +455,12 @@ public function promptChooseFromObjectsOrArrays(array|ArrayObject $items, string /** * Load configuration from .git/config. * - * @return string[][]|null + * @return string[][] * A multidimensional array keyed by file section. */ - private function getGitConfig(): ?array { + private function getGitConfig(): array { $filePath = $this->projectDir . '/.git/config'; - if (file_exists($filePath)) { - return parse_ini_file($filePath, TRUE); - } - - return NULL; + return @\Safe\parse_ini_file($filePath, TRUE); } /** @@ -574,7 +571,8 @@ protected function inferCloudAppFromLocalGitConfig( $answer = $this->io->confirm('Would you like Acquia CLI to search for a Cloud application that matches your local git config?'); if ($answer) { $this->output->writeln('Searching for a matching Cloud application...'); - if ($gitConfig = $this->getGitConfig()) { + try { + $gitConfig = $this->getGitConfig(); $localGitRemotes = $this->getGitRemotes($gitConfig); if ($cloudApplication = $this->findCloudApplicationByGitUrl($acquiaCloudClient, $localGitRemotes)) { @@ -585,6 +583,9 @@ protected function inferCloudAppFromLocalGitConfig( $this->output->writeln('Could not find a matching Cloud application.'); return NULL; } + catch (FilesystemException $e) { + throw new AcquiaCliException($e->getMessage()); + } } } diff --git a/tests/phpunit/src/Commands/Ssh/SshKeyUploadCommandTest.php b/tests/phpunit/src/Commands/Ssh/SshKeyUploadCommandTest.php index 2a5e3fc00..47f9696ba 100644 --- a/tests/phpunit/src/Commands/Ssh/SshKeyUploadCommandTest.php +++ b/tests/phpunit/src/Commands/Ssh/SshKeyUploadCommandTest.php @@ -36,7 +36,7 @@ public function providerTestUpload(): array { // Would you like to wait until Cloud Platform is ready? (yes/no) 'y', // Would you like Acquia CLI to search for a Cloud application that matches your local git config? (yes/no) - 'y', + 'n', ], // Perms. TRUE, @@ -52,7 +52,7 @@ public function providerTestUpload(): array { // Would you like to wait until Cloud Platform is ready? (yes/no) 'y', // Would you like Acquia CLI to search for a Cloud application that matches your local git config? (yes/no) - 'y', + 'n', ], // Perms. FALSE, @@ -63,7 +63,7 @@ public function providerTestUpload(): array { /** * @dataProvider providerTestUpload */ - public function testUpload(mixed $args, mixed $inputs, mixed $perms): void { + public function testUpload(array $args, array $inputs, bool $perms): void { $sshKeysRequestBody = $this->getMockRequestBodyFromSpec('/account/ssh-keys'); $body = [ 'json' => [