MergeTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 57
Duplicated Lines 73.68 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
c 2
b 0
f 0
lcom 1
cbo 6
dl 42
loc 57
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testHeadNotOnLocalFileWillThrowAnException() 0 9 1
A testMakeDirectory() 14 14 1
A testStaticFlow() 14 14 1
A testInvokeFlow() 14 14 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\FileNodeCollection;
17
use Graze\DataFile\Node\FileNodeInterface;
18
use Graze\DataFlow\Flow;
19
use Graze\DataFlow\Flow\File\Merge;
20
use Graze\DataFlow\Test\RealFileTestCase;
21
use Graze\DataNode\NodeCollectionInterface;
22
use InvalidArgumentException;
23
use Mockery as m;
24
25
class MergeTest extends RealFileTestCase
26
{
27
    public function testHeadNotOnLocalFileWillThrowAnException()
28
    {
29
        $file = m::mock(NodeCollectionInterface::class);
30
        $flow = new Merge(m::mock(FileNodeInterface::class));
31
32
        $this->expectException(InvalidArgumentException::class);
33
34
        $flow->flow($file);
35
    }
36
37 View Code Duplication
    public function testMakeDirectory()
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...
38
    {
39
        $file1 = $this->makeFile('merge/initial/file1', "line 1\nline 2\n");
40
        $file2 = $this->makeFile('merge/initial/file2', "line 3\nline 4\n");
41
        $merged = $this->makeFile('merge/initial/merged');
42
43
        $flow = new Merge($merged);
44
        $collection = new FileNodeCollection([$file1, $file2]);
45
46
        $output = $flow->flow($collection);
47
48
        static::assertSame($output, $merged);
49
        static::assertEquals(["line 1", "line 2", "line 3", "line 4"], $output->getContents());
50
    }
51
52 View Code Duplication
    public function testStaticFlow()
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...
53
    {
54
        $file1 = $this->makeFile('merge/static/file1', "line 1\nline 2\n");
55
        $file2 = $this->makeFile('merge/static/file2', "line 3\nline 4\n");
56
        $merged = $this->makeFile('merge/static/merged');
57
58
        $flow = Flow::merge($merged);
59
        $collection = new FileNodeCollection([$file1, $file2]);
60
61
        $output = $flow->flow($collection);
62
63
        static::assertSame($output, $merged);
64
        static::assertEquals(["line 1", "line 2", "line 3", "line 4"], $output->getContents());
65
    }
66
67 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...
68
    {
69
        $file1 = $this->makeFile('merge/invoke/file1', "line 1\nline 2\n");
70
        $file2 = $this->makeFile('merge/invoke/file2', "line 3\nline 4\n");
71
        $merged = $this->makeFile('merge/invoke/merged');
72
73
        $flow = new Merge($merged);
74
        $collection = new FileNodeCollection([$file1, $file2]);
75
76
        $output = call_user_func($flow, $collection);
77
78
        static::assertSame($output, $merged);
79
        static::assertEquals(["line 1", "line 2", "line 3", "line 4"], $output->getContents());
80
    }
81
}
82