CopyFiles::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 7
Ratio 100 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 7
loc 7
ccs 5
cts 5
cp 1
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
crap 2
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\Node\FileNode;
17
use Graze\DataFile\Node\FileNodeCollectionInterface;
18
use Graze\DataFlow\Flow\AbstractFlow;
19
use Graze\DataFlow\Flow\Collection\Each;
20
use Graze\DataNode\NodeInterface;
21
use InvalidArgumentException;
22
23 View Code Duplication
class CopyFiles extends AbstractFlow
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...
24
{
25
    /**
26
     * @var FileNode
27
     */
28
    private $targetDirectory;
29
30
    /**
31
     * MoveFiles constructor.
32
     *
33
     * @param FileNode $targetDirectory
34
     */
35 5
    public function __construct(FileNode $targetDirectory)
36
    {
37 5
        if (substr($targetDirectory, -1) != '/') {
38 1
            throw new InvalidArgumentException("The targetDirectory: '$targetDirectory' does not end in '/'");
39
        }
40 4
        $this->targetDirectory = $targetDirectory;
41 4
    }
42
43
    /**
44
     * @param NodeInterface $node
45
     *
46
     * @return NodeInterface
47
     */
48 4
    public function flow(NodeInterface $node)
49
    {
50 4
        if (!($node instanceof FileNodeCollectionInterface)) {
51 1
            throw new InvalidArgumentException("Node: $node should be an instance of FileNodeCollectionInterface");
52
        }
53
54 3
        $each = new Each(new CopyFile($this->targetDirectory));
55 3
        return $each->flow($node);
56
    }
57
}
58