ToAllTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 84
Duplicated Lines 85.71 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 7
dl 72
loc 84
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testInstanceOf() 0 6 1
B testRunIndependent() 24 24 1
B testStaticInstance() 24 24 1
B testInvokeFlow() 24 24 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\Runner;
15
16
use Graze\DataFlow\Flow;
17
use Graze\DataFlow\Flow\FlowCollection;
18
use Graze\DataFlow\Flow\Runner\ToAll;
19
use Graze\DataFlow\FlowInterface;
20
use Graze\DataFlow\Test\TestCase;
21
use Graze\DataNode\NodeCollection;
22
use Graze\DataNode\NodeInterface;
23
use Mockery as m;
24
25
class ToAllTest extends TestCase
26
{
27
    public function testInstanceOf()
28
    {
29
        $runner = new ToAll();
30
        static::assertInstanceOf(FlowCollection::class, $runner);
31
        static::assertInstanceOf(FlowInterface::class, $runner);
32
    }
33
34 View Code Duplication
    public function testRunIndependent()
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...
35
    {
36
        $flow1 = m::mock(FlowInterface::class);
37
        $flow2 = m::mock(FlowInterface::class);
38
39
        $runner = new ToAll($flow1, $flow2);
40
41
        $node1 = m::mock(NodeInterface::class);
42
        $node2 = m::mock(NodeInterface::class);
43
        $node3 = m::mock(NodeInterface::class);
44
45
        $flow1->shouldReceive('flow')
46
              ->with($node1)
47
              ->andReturn($node2);
48
        $flow2->shouldReceive('flow')
49
              ->with($node1)
50
              ->andReturn($node3);
51
52
        $output = $runner->flow($node1);
53
54
        static::assertInstanceOf(NodeCollection::class, $output);
55
56
        static::assertEquals([$node2, $node3], $output->getAll());
57
    }
58
59 View Code Duplication
    public function testStaticInstance()
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...
60
    {
61
        $flow1 = m::mock(FlowInterface::class);
62
        $flow2 = m::mock(FlowInterface::class);
63
64
        $runner = Flow::toAll($flow1, $flow2);
0 ignored issues
show
Unused Code introduced by
The call to Flow::toAll() has too many arguments starting with $flow2.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
65
66
        $node1 = m::mock(NodeInterface::class);
67
        $node2 = m::mock(NodeInterface::class);
68
        $node3 = m::mock(NodeInterface::class);
69
70
        $flow1->shouldReceive('flow')
71
              ->with($node1)
72
              ->andReturn($node2);
73
        $flow2->shouldReceive('flow')
74
              ->with($node1)
75
              ->andReturn($node3);
76
77
        $output = $runner->flow($node1);
78
79
        static::assertInstanceOf(NodeCollection::class, $output);
80
81
        static::assertEquals([$node2, $node3], $output->getAll());
82
    }
83
84 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...
85
    {
86
        $flow1 = m::mock(FlowInterface::class);
87
        $flow2 = m::mock(FlowInterface::class);
88
89
        $runner = Flow::toAll($flow1, $flow2);
0 ignored issues
show
Unused Code introduced by
The call to Flow::toAll() has too many arguments starting with $flow2.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
90
91
        $node1 = m::mock(NodeInterface::class);
92
        $node2 = m::mock(NodeInterface::class);
93
        $node3 = m::mock(NodeInterface::class);
94
95
        $flow1->shouldReceive('flow')
96
              ->with($node1)
97
              ->andReturn($node2);
98
        $flow2->shouldReceive('flow')
99
              ->with($node1)
100
              ->andReturn($node3);
101
102
        $output = call_user_func($runner, $node1);
103
104
        static::assertInstanceOf(NodeCollection::class, $output);
105
106
        static::assertEquals([$node2, $node3], $output->getAll());
107
    }
108
}
109