Passed
Push — master ( 77859c...e0031c )
by Mauro
02:25 queued 18s
created

Transfer   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 8
eloc 18
dl 0
loc 55
ccs 0
cts 18
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A transfer() 0 17 4
A handle() 0 7 2
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 Matecat\SimpleS3\Commands\CommandHandler;
15
16
class Transfer extends CommandHandler
17
{
18
    /**
19
     * @param array $params
20
     *
21
     * @return bool
22
     * @throws \Exception
23
     */
24
    public function handle($params = [])
25
    {
26
        $dest = $params['dest'];
27
        $source = $params['source'];
28
        $options = (isset($params['options'])) ? $params['options'] : [];
29
30
        return $this->transfer($dest, $source, $options);
31
    }
32
33
    /**
34
     * @param array $params
35
     *
36
     * @return bool
37
     */
38
    public function validateParams($params = [])
39
    {
40
        return (
41
            isset($params['dest']) and
42
            isset($params['source'])
43
        );
44
    }
45
46
    /**
47
     * @param string $dest
48
     * @param string $source
49
     * @param array $options
50
     *
51
     * @return bool
52
     * @throws \Exception
53
     */
54
    private function transfer($dest, $source, $options = [])
55
    {
56
        try {
57
            $manager = new \Aws\S3\Transfer($this->client->getConn(), $source, $dest, $options);
58
            $manager->transfer();
59
60
            if (null !== $this->commandHandlerLogger) {
61
                $this->commandHandlerLogger->log($this, sprintf('Files were successfully transfered from \'%s\' to \'%s\'', $source, $dest));
62
            }
63
64
            return true;
65
        } catch (\RuntimeException $e) {
66
            if (null !== $this->commandHandlerLogger) {
67
                $this->commandHandlerLogger->logExceptionAndReturnFalse($e);
68
            }
69
70
            throw $e;
71
        }
72
    }
73
}
74