CompositeIsSafeTest::getChecker()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A CompositeIsSafeTest.php$0 ➔ __construct() 0 4 1
A CompositeIsSafeTest.php$0 ➔ __invoke() 0 4 1
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 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