GetBucketPolicy::handle()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 11
ccs 7
cts 7
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 Exception;
15
use Matecat\SimpleS3\Commands\CommandHandler;
16
17
class GetBucketPolicy extends CommandHandler
18
{
19
    /**
20
     * Get the policy of a bucket.
21
     *
22
     * @param array $params
23
     *
24
     * @return int|mixed
25
     * @throws Exception
26
     */
27 1
    public function handle(array $params = []): mixed
28
    {
29 1
        $bucketName = $params[ 'bucket' ];
30
31 1
        $result = $this->client->getConn()->getBucketPolicy([
32 1
                'Bucket' => $bucketName,
33 1
        ]);
34
35 1
        $this->commandHandlerLogger?->log($this, sprintf('Size of \'%s\' bucket was successfully obtained', $bucketName));
36
37 1
        return (isset($result[ 'Policy' ])) ? json_decode($result[ 'Policy' ]->getContents(), true) : '';
0 ignored issues
show
Bug introduced by
The method getContents() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

37
        return (isset($result[ 'Policy' ])) ? json_decode($result[ 'Policy' ]->/** @scrutinizer ignore-call */ getContents(), true) : '';

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
38
    }
39
40
    /**
41
     * @param array $params
42
     *
43
     * @return bool
44
     */
45 1
    public function validateParams(array $params = []): bool
46
    {
47 1
        return isset($params[ 'bucket' ]);
48
    }
49
}
50