GetBucketLifeCycleConfiguration::handle()   A
last analyzed

Complexity

Conditions 2
Paths 3

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2.108

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 16
ccs 7
cts 10
cp 0.7
rs 9.9666
c 0
b 0
f 0
cc 2
nc 3
nop 1
crap 2.108
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