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

p$1   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 10
Duplicated Lines 100 %

Coupling/Cohesion

Dependencies 2

Importance

Changes 0
Metric Value
wmc 1
cbo 2
dl 10
loc 10
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
2
3
declare(strict_types=1);
4
5
namespace Nimo\Tests;
6
7
use Nimo\Interfaces\RequestPredictionInterface;
8
use Nimo\Middlewares\PredictionWrapperMiddleware;
9
use PHPUnit\Framework\Assert;
10
use Psr\Http\Message\ServerRequestInterface;
11
12
class PredictionWrapperMiddlewareTest extends NimoTestCase
13
{
14 View Code Duplication
    public function testPositiveCase()
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...
15
    {
16
        $req = $this->getRequestMock();
17
        $res = $this->getResponseMock();
18
        $hdl = $this->throwHandler();
19
        $inner = $this->assertedMiddleware($req, $hdl, $res);
0 ignored issues
show
Documentation introduced by
$req is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Psr\Http\Message\ServerRequestInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
$res is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Psr\Http\Message\ResponseInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
20
21
        $prediction = new class($req) implements RequestPredictionInterface
22
        {
23
            use RememberConstructorParamTrait;
24
25
            public function isTrue(ServerRequestInterface $request): bool
26
            {
27
                Assert::assertSame($this->params[0], $request);
28
                return true;
29
            }
30
        };
31
32
        $middleware = new PredictionWrapperMiddleware($inner, $prediction);
33
        $actualResponse = $middleware->process($req, $hdl);
0 ignored issues
show
Documentation introduced by
$req is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Psr\Http\Message\ServerRequestInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
34
        Assert::assertSame($res, $actualResponse);
35
    }
36
37
38 View Code Duplication
    public function testNegativeCase()
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...
39
    {
40
        $req = $this->getRequestMock();
41
        $res = $this->getResponseMock();
42
        $hdl = $this->assertedHandler($req, $res);
0 ignored issues
show
Documentation introduced by
$req is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Psr\Http\Message\ServerRequestInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
$res is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Psr\Http\Message\ResponseInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
43
44
        $falsePrediction = new class($req) implements RequestPredictionInterface
45
        {
46
            use RememberConstructorParamTrait;
47
48
            public function isTrue(ServerRequestInterface $request): bool
49
            {
50
                Assert::assertSame($this->params[0], $request);
51
                return false;
52
            }
53
        };
54
55
        $inner = $this->throwMiddleware($req, $hdl, new \Exception('should not call inner'));
0 ignored issues
show
Documentation introduced by
$req is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Psr\Http\Message\ServerRequestInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
56
        $middleware = new PredictionWrapperMiddleware($inner, $falsePrediction);
57
58
        $actualResponse = $middleware->process($req, $hdl);
0 ignored issues
show
Documentation introduced by
$req is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Psr\Http\Message\ServerRequestInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
59
        Assert::assertSame($res, $actualResponse);
60
    }
61
}
62