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

IsBucketVersioned::handle()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 10
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0
cc 3
nc 4
nop 1
crap 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