Completed
Pull Request — master (#1)
by David
02:43
created

CompositeIsSafeTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 42
Duplicated Lines 42.86 %

Importance

Changes 0
Metric Value
wmc 5
dl 18
loc 42
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A hp$0 ➔ __construct() 0 4 1
A hp$0 ➔ __invoke() 0 4 1
A getChecker() 0 19 1
A testCompositeAllFalse() 9 9 1
A testCompositeOneTrue() 9 9 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
namespace TheCodingMachine\Middlewares\SafeRequests;
4
5
use PHPUnit\Framework\TestCase;
6
use Psr\Http\Message\ServerRequestInterface;
7
8
class CompositeIsSafeTest extends \PHPUnit_Framework_TestCase
9
{
10
    private function getChecker(bool $result): IsSafeHttpRequestInterface
11
    {
12
        return new class($result) implements IsSafeHttpRequestInterface {
13
            /**
14
             * @var bool
15
             */
16
            private $result;
17
18
            public function __construct(bool $result)
19
            {
20
                $this->result = $result;
21
            }
22
23
            public function __invoke(ServerRequestInterface $request): bool
24
            {
25
                return $this->result;
26
            }
27
        };
28
    }
29
30 View Code Duplication
    public function testCompositeAllFalse()
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...
31
    {
32
        /* @var $request RequestInterface|\PHPUnit_Framework_MockObject_MockObject */
33
        $request = $this->getMockBuilder(ServerRequestInterface::class)->getMock();
34
35
        $composite = new CompositeIsSafe($this->getChecker(false), $this->getChecker(false));
36
37
        $this->assertFalse($composite($request));
38
    }
39
40 View Code Duplication
    public function testCompositeOneTrue()
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...
41
    {
42
        /* @var $request RequestInterface|\PHPUnit_Framework_MockObject_MockObject */
43
        $request = $this->getMockBuilder(ServerRequestInterface::class)->getMock();
44
45
        $composite = new CompositeIsSafe($this->getChecker(false), $this->getChecker(true));
46
47
        $this->assertTrue($composite($request));
48
    }
49
}
50