Skip to content

Commit 621fdfd

Browse files
committed
MAGE-1153 Perform additional refactoring
1 parent 901ce12 commit 621fdfd

File tree

2 files changed

+36
-38
lines changed

2 files changed

+36
-38
lines changed

Console/Command/AbstractReplicaCommand.php

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,48 +2,11 @@
22

33
namespace Algolia\AlgoliaSearch\Console\Command;
44

5-
use Symfony\Component\Console\Question\ConfirmationQuestion;
6-
75
abstract class AbstractReplicaCommand extends AbstractStoreCommand
86
{
9-
abstract protected function getCommandDescription(): string;
10-
11-
abstract protected function getAdditionalDefinition(): array;
12-
13-
/**
14-
* @inheritDoc
15-
*/
16-
protected function configure(): void
17-
{
18-
$definition = [$this->getStoreArgumentDefinition()];
19-
$definition = array_merge($definition, $this->getAdditionalDefinition());
20-
21-
$this->setName($this->getFullCommandName())
22-
->setDescription($this->getCommandDescription())
23-
->setDefinition($definition);
24-
25-
parent::configure();
26-
}
27-
287
protected function getCommandPrefix(): string
298
{
309
return parent::getCommandPrefix() . 'replicas:';
3110
}
3211

33-
protected function confirmOperation(string $okMessage = '', string $cancelMessage = 'Operation cancelled'): bool
34-
{
35-
$helper = $this->getHelper('question');
36-
$question = new ConfirmationQuestion('<question>Are you sure wish to proceed? (y/n)</question> ', false);
37-
if (!$helper->ask($this->input, $this->output, $question)) {
38-
if ($cancelMessage) {
39-
$this->output->writeln("<comment>$cancelMessage</comment>");
40-
}
41-
return false;
42-
}
43-
44-
if ($okMessage) {
45-
$this->output->writeln("<comment>$okMessage</comment>");
46-
}
47-
return true;
48-
}
4912
}

Console/Command/AbstractStoreCommand.php

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Symfony\Component\Console\Input\InputArgument;
1212
use Symfony\Component\Console\Input\InputInterface;
1313
use Symfony\Component\Console\Output\OutputInterface;
14+
use Symfony\Component\Console\Question\ConfirmationQuestion;
1415

1516
abstract class AbstractStoreCommand extends Command
1617
{
@@ -19,8 +20,10 @@ abstract class AbstractStoreCommand extends Command
1920
protected ?OutputInterface $output = null;
2021
protected ?InputInterface $input = null;
2122

22-
abstract protected function getStoreArgumentDescription(): string;
2323
abstract protected function getCommandName(): string;
24+
abstract protected function getCommandDescription(): string;
25+
abstract protected function getAdditionalDefinition(): array;
26+
abstract protected function getStoreArgumentDescription(): string;
2427

2528
public function __construct(
2629
protected State $state,
@@ -41,6 +44,21 @@ protected function getFullCommandName(): string
4144
return $this->getCommandPrefix() . $this->getCommandName();
4245
}
4346

47+
/**
48+
* @inheritDoc
49+
*/
50+
protected function configure(): void
51+
{
52+
$definition = [$this->getStoreArgumentDefinition()];
53+
$definition = array_merge($definition, $this->getAdditionalDefinition());
54+
55+
$this->setName($this->getFullCommandName())
56+
->setDescription($this->getCommandDescription())
57+
->setDefinition($definition);
58+
59+
parent::configure();
60+
}
61+
4462
protected function setAreaCode(): void
4563
{
4664
try {
@@ -90,4 +108,21 @@ protected function decorateOperationAnnouncementMessage(string $msg, array $stor
90108
? "<info>$msg: " . join(", ", $this->storeNameFetcher->getStoreNames($storeIds)) . '</info>'
91109
: "<info>$msg</info>";
92110
}
111+
112+
protected function confirmOperation(string $okMessage = '', string $cancelMessage = 'Operation cancelled'): bool
113+
{
114+
$helper = $this->getHelper('question');
115+
$question = new ConfirmationQuestion('<question>Are you sure wish to proceed? (y/n)</question> ', false);
116+
if (!$helper->ask($this->input, $this->output, $question)) {
117+
if ($cancelMessage) {
118+
$this->output->writeln("<comment>$cancelMessage</comment>");
119+
}
120+
return false;
121+
}
122+
123+
if ($okMessage) {
124+
$this->output->writeln("<comment>$okMessage</comment>");
125+
}
126+
return true;
127+
}
93128
}

0 commit comments

Comments
 (0)