IsBucketVersioned::handle()   A
last analyzed

Complexity

Conditions 2
Paths 3

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 10
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 3
nop 1
crap 2
1
<?php
2
/**
3
 *  This file is part of the Simple S3 package.
4
 *
5
 * (c) Mauro Cassani<https://github.com/mauretto78>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 */
11
12
namespace Matecat\SimpleS3\Commands\Handlers;
13
14
use Exception;
15
use Matecat\SimpleS3\Commands\CommandHandler;
16
17
class IsBucketVersioned extends CommandHandler
18
{
19
    /**
20
     * Check if is enabled versioning for a bucket.
21
     * For a complete reference:
22
     * https://docs.aws.amazon.com/cli/latest/reference/s3api/put-bucket-versioning.html?highlight=versioning%20bucket
23
     *
24
     * @param array $params
25
     *
26
     * @return bool
27
     * @throws Exception
28
     */
29 18
    public function handle(array $params = []): mixed
30
    {
31
        try {
32 18
            $ver = $this->client->getConn()->getBucketVersioning([
33 18
                    'Bucket' => $params[ 'bucket' ]
34 18
            ]);
35
36 17
            return $ver[ 'Status' ] === 'Enabled';
37 1
        } catch (Exception $e) {
38 1
            return $this->commandHandlerLogger?->logExceptionAndReturnFalse($e) ?? false;
39
        }
40
    }
41
42
    /**
43
     * @param array $params
44
     *
45
     * @return bool
46
     */
47 18
    public function validateParams(array $params = []): bool
48
    {
49 18
        return isset($params[ 'bucket' ]);
50
    }
51
}
52