CopyFileTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 73
Duplicated Lines 31.51 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 5
dl 23
loc 73
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testCopyNotOnLocalFileWillThrowAnException() 9 9 1
A testCopyFileCreatesANewFile() 0 14 1
A testStaticFlow() 0 14 1
A testInvokeFlow() 14 14 1
A testCopyFileWithDirectoryTargetWillUseOriginalFileName() 0 15 1

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\Test\Integration\Flow\File;
15
16
use Graze\DataFile\Node\FileNode;
17
use Graze\DataFlow\Flow;
18
use Graze\DataFlow\Flow\File\CopyFile;
19
use Graze\DataFlow\Test\MemoryFileTestCase;
20
use Graze\DataNode\NodeInterface;
21
use InvalidArgumentException;
22
use Mockery as m;
23
24
class CopyFileTest extends MemoryFileTestCase
25
{
26 View Code Duplication
    public function testCopyNotOnLocalFileWillThrowAnException()
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...
27
    {
28
        $file = m::mock(NodeInterface::class);
29
        $flow = new CopyFile(m::mock(FileNode::class));
30
31
        $this->expectException(InvalidArgumentException::class);
32
33
        $flow->flow($file);
34
    }
35
36
    public function testCopyFileCreatesANewFile()
37
    {
38
        $file = $this->makeFile('copy/flow/source', 'some text');
39
        $target = $this->makeFile('copy/flow/target');
40
41
        $flow = new CopyFile($target);
42
43
        $output = $flow->flow($file);
44
45
        static::assertSame($target, $output);
46
        static::assertInstanceOf(FileNode::class, $output);
47
        static::assertEquals($file->getContents(), $output->getContents());
48
        static::assertTrue($file->exists(), "The original file should still exist");
49
    }
50
51
    public function testStaticFlow()
52
    {
53
        $file = $this->makeFile('copy/static/source', 'some text');
54
        $target = $this->makeFile('copy/static/target');
55
56
        $flow = Flow::copyFile($target);
57
58
        $output = $flow->flow($file);
59
60
        static::assertSame($target, $output);
61
        static::assertInstanceOf(FileNode::class, $output);
62
        static::assertEquals($file->getContents(), $output->getContents());
63
        static::assertTrue($file->exists(), "The original file should still exist");
64
    }
65
66 View Code Duplication
    public function testInvokeFlow()
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...
67
    {
68
        $file = $this->makeFile('copy/invoke/source', 'some text');
69
        $target = $this->makeFile('copy/invoke/target');
70
71
        $flow = Flow::copyFile($target);
72
73
        $output = call_user_func($flow, $file);
74
75
        static::assertSame($target, $output);
76
        static::assertInstanceOf(FileNode::class, $output);
77
        static::assertEquals($file->getContents(), $output->getContents());
78
        static::assertTrue($file->exists(), "The original file should still exist");
79
    }
80
81
    public function testCopyFileWithDirectoryTargetWillUseOriginalFileName()
82
    {
83
        $file = $this->makeFile('copy/todir/source', 'some text');
84
        $target = $this->makeFile('copy/todir/target/');
85
86
        $flow = Flow::copyFile($target);
87
88
        $output = $flow->flow($file);
89
90
        static::assertNotSame($target, $output);
91
        static::assertInstanceOf(FileNode::class, $output);
92
        static::assertEquals($file->getContents(), $output->getContents());
93
        static::assertEquals('source', $output->getFilename());
94
        static::assertEquals('copy/todir/target/source', $output->getPath());
95
    }
96
}
97