Transfer   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 54
Duplicated Lines 62.96 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 4
dl 34
loc 54
ccs 20
cts 20
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A copyTo() 17 17 2
A moveTo() 17 17 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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