CopyFile::flow()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 8

Duplication

Lines 14
Ratio 100 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 14
loc 14
ccs 8
cts 8
cp 1
rs 9.4285
cc 3
eloc 8
nc 3
nop 1
crap 3
1
<?php
2
/**
3
 * This file is part of graze/data-flow
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-flow/blob/master/LICENSE.md
11
 * @link    https://github.com/graze/data-flow
12
 */
13
14
namespace Graze\DataFlow\Flow\File;
15
16
use Graze\DataFile\Modify\Transfer\Transfer;
17
use Graze\DataFile\Node\FileNode;
18
use Graze\DataFile\Node\FileNodeInterface;
19
use Graze\DataFlow\Flow\InvokeTrait;
20
use Graze\DataFlow\FlowInterface;
21
use Graze\DataNode\NodeInterface;
22
use InvalidArgumentException;
23
24 View Code Duplication
class CopyFile extends Transfer implements FlowInterface
0 ignored issues
show
Duplication introduced by
This class 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...
25
{
26
    use InvokeTrait;
27
28
    /**
29
     * @var FileNodeInterface
30
     */
31
    private $target;
32
33
    /**
34
     * CopyFile constructor.
35
     *
36
     * @param FileNode $target
37
     */
38 9
    public function __construct(FileNode $target)
39
    {
40 9
        $this->target = $target;
41 9
    }
42
43
    /**
44
     * @param NodeInterface $node
45
     *
46
     * @return FileNode
47
     */
48 9
    public function flow(NodeInterface $node)
49
    {
50 9
        if (!($node instanceof FileNode)) {
51 1
            throw new InvalidArgumentException("Node: $node should be an instance of FileNode");
52
        }
53
54 8
        if (substr($this->target->getPath(), -1) == '/') {
55 5
            $target = $this->target->getClone()->setPath($this->target->getPath() . $node->getFilename());
56 5
        } else {
57 3
            $target = $this->target;
58
        }
59
60 8
        return $this->copyTo($node, $target);
61
    }
62
}
63