Transfer::copyTo()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 10

Duplication

Lines 17
Ratio 100 %

Code Coverage

Tests 10
CRAP Score 2

Importance

Changes 0
Metric Value
dl 17
loc 17
ccs 10
cts 10
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 10
nc 2
nop 2
crap 2
1
<?php
2
/**
3
 * This file is part of graze/data-file
4
 *
5
 * Copyright (c) 2016 Nature Delivered Ltd. <https://www.graze.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @license https://github.com/graze/data-file/blob/master/LICENSE.md
11
 * @link    https://github.com/graze/data-file
12
 */
13
14
namespace Graze\DataFile\Modify\Transfer;
15
16
use Graze\DataFile\Helper\OptionalLoggerTrait;
17
use Graze\DataFile\Modify\Exception\TransferFailedException;
18
use Graze\DataFile\Node\FileNode;
19
use League\Flysystem\MountManager;
20
use Psr\Log\LoggerAwareInterface;
21
use Psr\Log\LogLevel;
22
23
class Transfer implements FileTransferInterface, LoggerAwareInterface
24
{
25
    use OptionalLoggerTrait;
26
27
    /**
28
     * @param FileNode $from
29
     * @param FileNode $to
30
     *
31
     * @return FileNode
32
     * @throws TransferFailedException
33
     */
34 4 View Code Duplication
    public function copyTo(FileNode $from, FileNode $to)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
35
    {
36 4
        $mountManager = new MountManager([
37 4
            'from' => $from->getFilesystem(),
38 4
            'to'   => $to->getFilesystem(),
39
        ]);
40
41 4
        $this->log(LogLevel::INFO, "Copying file from: '{from}', to: '{to}'", [
42 4
            'from' => $from,
43 4
            'to'   => $to,
44
        ]);
45 4
        if (!$mountManager->copy('from://' . $from->getPath(), 'to://' . $to->getPath())) {
46 1
            throw new TransferFailedException($from, $to);
47
        }
48
49 2
        return $to;
50
    }
51
52
    /**
53
     * @param FileNode $from
54
     * @param FileNode $to
55
     *
56
     * @return FileNode
57
     * @throws TransferFailedException
58
     */
59 3 View Code Duplication
    public function moveTo(FileNode $from, FileNode $to)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
60
    {
61 3
        $mountManager = new MountManager([
62 3
            'from' => $from->getFilesystem(),
63 3
            'to'   => $to->getFilesystem(),
64
        ]);
65
66 3
        $this->log(LogLevel::INFO, "Moving file from: '{from}', to: '{to}'", [
67 3
            'from' => $from,
68 3
            'to'   => $to,
69
        ]);
70 3
        if (!$mountManager->move('from://' . $from->getPath(), 'to://' . $to->getPath())) {
71 1
            throw new TransferFailedException($from, $to);
72
        }
73
74 1
        return $to;
75
    }
76
}
77