BucketDeleteCommand   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
eloc 21
dl 0
loc 48
ccs 0
cts 20
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A execute() 0 19 3
A configure() 0 7 1
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