Test Failed
Push — master ( d8d5ef...b9f7fc )
by mcfog
01:56
created

anonymous//Tests/NimoTestCase.php$0   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 12
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 1
lcom 1
cbo 3
dl 12
loc 12
rs 10
c 0
b 0
f 0

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 namespace Nimo\Tests;
2
3
/**
4
 * User: mcfog
5
 * Date: 15/9/13
6
 */
7
8
use Interop\Http\Server\RequestHandlerInterface;
9
use Nimo\AbstractHandler;
10
use Nimo\AbstractMiddleware;
11
use Nimo\Handlers\CallableHandler;
12
use PHPUnit\Framework\Assert;
13
use PHPUnit\Framework\TestCase;
14
use Psr\Http\Message\ResponseInterface;
15
use Psr\Http\Message\ServerRequestInterface;
16
17
abstract class NimoTestCase extends TestCase
18
{
19
    protected function throwHandler()
20
    {
21
        return CallableHandler::wrap(function (ServerRequestInterface $request) {
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
22
            throw new \Exception('should throw');
23
        });
24
    }
25
26
    /**
27
     * @return ServerRequestInterface
28
     */
29
    protected function getRequestMock()
30
    {
31
        return $this->getMockForAbstractClass(ServerRequestInterface::class);
32
    }
33
34
    /**
35
     * @return ResponseInterface
36
     */
37
    protected function getResponseMock()
38
    {
39
        return $this->getMockForAbstractClass(ResponseInterface::class);
40
    }
41
42 View Code Duplication
    protected function assertedHandler(ServerRequestInterface $expectedRequest, ResponseInterface $response)
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...
43
    {
44
        return new class($expectedRequest, $response) extends AbstractHandler
45
        {
46
            use RememberConstructorParamTrait;
47
48
            protected function main(): ResponseInterface
49
            {
50
                /** @noinspection PhpUndefinedFieldInspection */
51
                list($expectedRequest, $response) = $this->params;
52
                Assert::assertSame($expectedRequest, $this->request);
53
                return $response;
54
            }
55
        };
56
57
    }
58
59 View Code Duplication
    protected function assertedNoopMiddleware(
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
        ServerRequestInterface $expectedRequest,
61
        ServerRequestInterface $passedRequest = null
62
    ) {
63
        return new class($expectedRequest, $passedRequest) extends AbstractMiddleware
64
        {
65
            use RememberConstructorParamTrait;
66
67
            protected function main(): ResponseInterface
68
            {
69
                /** @noinspection PhpUndefinedFieldInspection */
70
                list($expectedRequest, $passedRequest) = $this->params;
71
                Assert::assertSame($expectedRequest, $this->request);
72
                return $this->delegate($passedRequest);
73
            }
74
        };
75
    }
76
77 View Code Duplication
    protected function assertedMiddleware(
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...
78
        ServerRequestInterface $expectedRequest,
79
        RequestHandlerInterface $expectedHandler,
80
        ResponseInterface $response
81
    ) {
82
        return new class($expectedRequest, $expectedHandler, $response) extends AbstractMiddleware
83
        {
84
            use RememberConstructorParamTrait;
85
86
            protected function main(): ResponseInterface
87
            {
88
                /** @noinspection PhpUndefinedFieldInspection */
89
                list($expectedRequest, $expectedHandler, $response) = $this->params;
90
                Assert::assertSame($expectedRequest, $this->request);
91
                Assert::assertSame($expectedHandler, $this->handler);
92
                return $response;
93
            }
94
        };
95
    }
96
97 View Code Duplication
    protected function throwMiddleware(
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...
98
        ServerRequestInterface $expectedRequest,
99
        RequestHandlerInterface $expectedHandler,
100
        \Throwable $throwable
101
    ) {
102
        return new class($expectedRequest, $expectedHandler, $throwable) extends AbstractMiddleware
103
        {
104
            use RememberConstructorParamTrait;
105
106
            protected function main(): ResponseInterface
107
            {
108
                /** @noinspection PhpUndefinedFieldInspection */
109
                list($expectedRequest, $expectedHandler, $throwable) = $this->params;
110
                Assert::assertSame($expectedRequest, $this->request);
111
                Assert::assertSame($expectedHandler, $this->handler);
112
                throw $throwable;
113
            }
114
        };
115
    }
116
}
117