CallbackTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 56
Duplicated Lines 80.36 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 4
dl 45
loc 56
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testInstanceOf() 0 5 1
A testCallingFlowWillCallTheCallback() 15 15 1
A testStaticCalling() 15 15 1
A testInvokeFlow() 15 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\Unit\Test\Flow;
15
16
use Graze\DataFlow\Flow;
17
use Graze\DataFlow\Flow\Callback;
18
use Graze\DataFlow\FlowInterface;
19
use Graze\DataFlow\Test\TestCase;
20
use Graze\DataNode\NodeInterface;
21
use Mockery as m;
22
23
class CallbackTest extends TestCase
24
{
25
    public function testInstanceOf()
26
    {
27
        static::assertInstanceOf(FlowInterface::class, new Callback(function () {
28
        }));
29
    }
30
31 View Code Duplication
    public function testCallingFlowWillCallTheCallback()
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...
32
    {
33
        $called = null;
34
        $return = m::mock(NodeInterface::class);
35
        $callbackFlow = new Callback(function ($item) use (&$called, $return) {
36
            $called = $item;
37
            return $return;
38
        });
39
40
        $node = m::mock(NodeInterface::class);
41
42
        $output = $callbackFlow->flow($node);
43
        static::assertEquals($return, $output);
44
        static::assertEquals($called, $node);
45
    }
46
47 View Code Duplication
    public function testStaticCalling()
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...
48
    {
49
        $called = null;
50
        $return = m::mock(NodeInterface::class);
51
        $callbackFlow = Flow::callback(function ($item) use (&$called, $return) {
52
            $called = $item;
53
            return $return;
54
        });
55
56
        $node = m::mock(NodeInterface::class);
57
58
        $output = $callbackFlow->flow($node);
59
        static::assertEquals($return, $output);
60
        static::assertEquals($called, $node);
61
    }
62
63 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...
64
    {
65
        $called = null;
66
        $return = m::mock(NodeInterface::class);
67
        $callbackFlow = Flow::callback(function ($item) use (&$called, $return) {
68
            $called = $item;
69
            return $return;
70
        });
71
72
        $node = m::mock(NodeInterface::class);
73
74
        $output = call_user_func($callbackFlow, $node);
75
        static::assertEquals($return, $output);
76
        static::assertEquals($called, $node);
77
    }
78
}
79