GetBucketLifeCycleConfiguration   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 75%

Importance

Changes 0
Metric Value
wmc 3
eloc 11
dl 0
loc 39
ccs 9
cts 12
cp 0.75
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A validateParams() 0 3 1
A handle() 0 16 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 Aws\Result;
15
use Aws\S3\Exception\S3Exception;
16
use Exception;
17
use Matecat\SimpleS3\Commands\CommandHandler;
18
19
class GetBucketLifeCycleConfiguration extends CommandHandler
20
{
21
    /**
22
     * Get the lifecycle configuration of a bucket.
23
     * For a complete reference:
24
     * https://docs.aws.amazon.com/cli/latest/reference/s3api/get-bucket-lifecycle-configuration.html
25
     *
26
     * @param array $params
27
     *
28
     * @return Result
29
     * @throws Exception
30
     */
31 1
    public function handle(array $params = []): Result
32
    {
33 1
        $bucketName = $params[ 'bucket' ];
34
35
        try {
36 1
            $result = $this->client->getConn()->getBucketLifecycle([
37 1
                    'Bucket' => $bucketName
38 1
            ]);
39
40 1
            $this->commandHandlerLogger?->log($this, sprintf('LifeCycleConfiguration of \'%s\' bucket was successfully obtained', $bucketName));
41
42 1
            return $result;
43
        } catch (S3Exception $e) {
44
            $this->commandHandlerLogger?->logExceptionAndReturnFalse($e);
45
46
            throw $e;
47
        }
48
    }
49
50
    /**
51
     * @param array $params
52
     *
53
     * @return bool
54
     */
55 1
    public function validateParams(array $params = []): bool
56
    {
57 1
        return isset($params[ 'bucket' ]);
58
    }
59
}
60