CopyFiles   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 3
dl 35
loc 35
ccs 10
cts 10
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 7 7 2
A flow() 9 9 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-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