Test Failed
Push — master ( a92e12...446184 )
by Domenico
04:27
created

IsBucketVersioned   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
eloc 8
dl 0
loc 33
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A validateParams() 0 3 1
A handle() 0 10 3
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 Matecat\SimpleS3\Commands\CommandHandler;
15
16
class IsBucketVersioned extends CommandHandler
17
{
18
    /**
19
     * Check if is enabled versioning for a bucket.
20
     * For a complete reference:
21
     * https://docs.aws.amazon.com/cli/latest/reference/s3api/put-bucket-versioning.html?highlight=versioning%20bucket
22
     *
23
     * @param mixed $params
24
     *
25
     * @return bool
26
     * @throws \Exception
27
     */
28 18
    public function handle($params = [])
29
    {
30
        try {
31 18
            $ver = $this->client->getConn()->getBucketVersioning([
32 18
                    'Bucket' => $params['bucket']
33
            ]);
34
35 17
            return ($ver['Status'] === 'Enabled') ? true : false;
36 1
        } catch (\Exception $e) {
37 1
            return false;
38
        }
39
    }
40
41
    /**
42
     * @param array $params
43
     *
44
     * @return bool
45
     */
46 18
    public function validateParams($params = [])
47
    {
48 18
        return isset($params['bucket']);
49
    }
50
}
51