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

HasItem::validateParams()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 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 Matecat\SimpleS3\Commands\CommandHandler;
15
16
class HasItem extends CommandHandler
17
{
18
    /**
19
     * Check if a item already exists.
20
     * For a complete reference:
21
     * https://docs.aws.amazon.com/cli/latest/reference/s3api/head-object.html
22
     *
23
     * @param array $params
24
     *
25
     * @return bool
26
     */
27 5
    public function handle($params = [])
28
    {
29 5
        $bucketName = $params['bucket'];
30 5
        $keyName = $params['key'];
31
32 5
        if ($this->client->hasEncoder()) {
33 4
            $keyName = $this->client->getEncoder()->encode($keyName);
34
        }
35
36 5
        if ($this->client->hasCache() and $this->client->getCache()->has($bucketName, $keyName)) {
37 3
            return true;
38
        }
39
40 2
        return $this->client->getConn()->doesObjectExist($bucketName, $keyName);
41
    }
42
43
    /**
44
     * @param array $params
45
     *
46
     * @return bool
47
     */
48 5
    public function validateParams($params = [])
49
    {
50
        return (
51 5
            isset($params['bucket']) and
52 5
            isset($params['key'])
53
        );
54
    }
55
}
56