BucketDeleteCommand::configure()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 7
ccs 0
cts 6
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Matecat\SimpleS3\Console;
4
5
use Exception;
6
use Matecat\SimpleS3\Client;
7
use Symfony\Component\Console\Command\Command;
8
use Symfony\Component\Console\Input\InputArgument;
9
use Symfony\Component\Console\Input\InputInterface;
10
use Symfony\Component\Console\Output\OutputInterface;
11
use Symfony\Component\Console\Style\SymfonyStyle;
12
13
class BucketDeleteCommand extends Command
14
{
15
    /**
16
     * @var Client
17
     */
18
    private Client $s3Client;
19
20
    /**
21
     * CacheFlushCommand constructor.
22
     *
23
     * @param Client      $s3Client
24
     * @param string|null $name
25
     */
26
    public function __construct(Client $s3Client, ?string $name = null)
27
    {
28
        parent::__construct($name);
29
30
        $this->s3Client = $s3Client;
31
    }
32
33
    protected function configure(): void
34
    {
35
        $this
36
                ->setName('ss3:bucket:delete')
37
                ->setDescription('Deletes a bucket.')
38
                ->setHelp('This command deletes a bucket on S3.')
39
                ->addArgument('bucket', InputArgument::REQUIRED, 'The name of the bucket');
40
    }
41
42
    protected function execute(InputInterface $input, OutputInterface $output): int
43
    {
44
        $bucket = $input->getArgument('bucket');
45
        $io     = new SymfonyStyle($input, $output);
46
47
        try {
48
            if (true === $this->s3Client->deleteBucket(['bucket' => $bucket])) {
49
                $io->success('The bucket was successfully deleted');
50
51
                return 0;
52
            } else {
53
                $io->error('There was an error in deleting bucket');
54
55
                return 1;
56
            }
57
        } catch (Exception $e) {
58
            $io->error($e->getMessage());
59
60
            return 1;
61
        }
62
    }
63
}
64