FirstTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 76
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 3
Bugs 1 Features 0
Metric Value
wmc 5
c 3
b 1
f 0
lcom 1
cbo 6
dl 76
loc 76
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testInstanceOf() 8 8 1
A testInvalidInputThrowsAnException() 10 10 1
A testFlow() 17 17 1
A testStaticFlow() 17 17 1
A testInvokeFlow() 17 17 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\Unit\Flow\Collection;
15
16
use Graze\DataFlow\Flow;
17
use Graze\DataFlow\Flow\Collection\First;
18
use Graze\DataFlow\FlowInterface;
19
use Graze\DataFlow\Test\TestCase;
20
use Graze\DataNode\NodeCollectionInterface;
21
use Graze\DataNode\NodeInterface;
22
use InvalidArgumentException;
23
use Mockery as m;
24
25 View Code Duplication
class FirstTest extends TestCase
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...
26
{
27
    public function testInstanceOf()
28
    {
29
        $flow = new First(function () {
30
            return true;
31
        });
32
33
        static::assertInstanceOf(FlowInterface::class, $flow);
34
    }
35
36
    public function testInvalidInputThrowsAnException()
37
    {
38
        $file = m::mock(NodeInterface::class);
39
        $flow = new First(function () {
40
        });
41
42
        $this->expectException(InvalidArgumentException::class);
43
44
        $flow->flow($file);
45
    }
46
47
    public function testFlow()
48
    {
49
        $func = function () use (&$called) {
50
            $called = true;
51
            return true;
52
        };
53
        $flow = new First($func);
54
55
        $node = m::mock(NodeCollectionInterface::class);
56
        $node->shouldReceive('first')
57
             ->with($func)
58
             ->andReturn($node);
59
60
        $response = $flow->flow($node);
61
62
        static::assertSame($response, $node);
63
    }
64
65
    public function testStaticFlow()
66
    {
67
        $func = function () use (&$called) {
68
            $called = true;
69
            return true;
70
        };
71
        $flow = Flow::first($func);
72
73
        $node = m::mock(NodeCollectionInterface::class);
74
        $node->shouldReceive('first')
75
             ->with($func)
76
             ->andReturn($node);
77
78
        $response = $flow->flow($node);
79
80
        static::assertSame($response, $node);
81
    }
82
83
    public function testInvokeFlow()
84
    {
85
        $func = function () use (&$called) {
86
            $called = true;
87
            return true;
88
        };
89
        $flow = Flow::first($func);
90
91
        $node = m::mock(NodeCollectionInterface::class);
92
        $node->shouldReceive('first')
93
             ->with($func)
94
             ->andReturn($node);
95
96
        $response = call_user_func($flow, $node);
97
98
        static::assertSame($response, $node);
99
    }
100
}
101