GetBucketLifeCycleConfiguration   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

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

2 Methods

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