Test Failed
Branch master (3a0aa4)
by Domenico
16:55
created

DeleteFolder   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 7
eloc 21
dl 0
loc 54
ccs 0
cts 20
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 29 5
A validateParams() 0 5 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
use Matecat\SimpleS3\Helpers\File;
17
18
class DeleteFolder extends CommandHandler
19
{
20
    /**
21
     * Delete a folder.
22
     * For a complete reference:
23
     * https://docs.aws.amazon.com/cli/latest/reference/s3api/delete-object.html
24
     *
25
     * @param array $params
26
     *
27
     * @return true
28
     * @throws Exception
29
     */
30
    public function handle(array $params = []): true
0 ignored issues
show
Bug introduced by
The type Matecat\SimpleS3\Commands\Handlers\true was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
31
    {
32
        $bucketName = $params[ 'bucket' ];
33
        $prefix     = $params[ 'prefix' ];
34
35
        if (false === File::endsWith($prefix, $this->client->getPrefixSeparator())) {
36
            $prefix .= $this->client->getPrefixSeparator();
37
        }
38
39
        try {
40
            $this->client->getConn()->deleteMatchingObjects($bucketName, $prefix);
41
            $this->commandHandlerLogger?->log($this, sprintf('Folder \'%s\' was successfully deleted from \'%s\' bucket', $prefix, $bucketName));
42
43
            if ($this->client->hasCache()) {
44
                $items = $this->client->getItemsInABucket([
45
                        'bucket' => $bucketName,
46
                        'prefix' => $prefix,
47
                ]);
48
49
                foreach ($items as $key) {
50
                    $this->client->getCache()->remove($bucketName, $key);
51
                }
52
            }
53
54
            return true;
0 ignored issues
show
Bug Best Practice introduced by
The expression return true returns the type true which is incompatible with the type-hinted return Matecat\SimpleS3\Commands\Handlers\true.
Loading history...
55
        } catch (Exception $e) {
56
            $this->commandHandlerLogger?->logExceptionAndReturnFalse($e);
57
58
            throw $e;
59
        }
60
    }
61
62
    /**
63
     * @param array $params
64
     *
65
     * @return bool
66
     */
67
    public function validateParams(array $params = []): bool
68
    {
69
        return (
70
                isset($params[ 'bucket' ]) and
71
                isset($params[ 'prefix' ])
72
        );
73
    }
74
}
75