Completed
Push — master ( c15104...eb04a4 )
by Dmitry
14:35
created

FakeEndpointBuilder   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
dl 0
loc 36
c 0
b 0
f 0
wmc 3
lcom 0
cbo 4
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getBuildersList() 0 7 1
A build() 0 11 2
1
<?php
2
3
namespace hiapi\tests\unit\Endpoints;
4
5
use Closure;
6
use hiapi\endpoints\EndpointBuilderInterface;
7
use hiapi\endpoints\EndpointConfig;
8
use hiapi\endpoints\Module\Builder\OrderedBuildersCallTrait;
9
use hiapi\endpoints\Module\Builder\ReflectionBasedEndpointBuilderTrait;
10
use hiapi\endpoints\Module\InOutControl\ExamplesAwareBuilderInterface;
11
use hiapi\endpoints\Module\InOutControl\ExamplesAwareBuilderTrait;
12
use hiapi\endpoints\Module\InOutControl\InOutControlBuilderInterface;
13
use hiapi\endpoints\Module\InOutControl\InOutControlBuilderTrait;
14
use hiapi\tests\unit\Endpoints\support\FakeEndpoint;
15
use hiapi\tests\unit\Endpoints\support\InputStub;
16
use hiapi\tests\unit\Endpoints\support\ReturnStub;
17
use PHPUnit\Framework\TestCase;
18
19
/**
20
 * @group endpoints
21
 */
22
class EndpointBuilderTest extends TestCase
23
{
24
    protected $builder;
25
26
    protected function setUp()
27
    {
28
        parent::setUp();
29
30
        $this->builder = new FakeEndpointBuilder();
31
    }
32
33
    public function testBuilderProducesEndpoints()
34
    {
35
        $builder = $this->builder
36
            ->take(InputStub::class)
37
            ->return(ReturnStub::class);
38
39
        $endpoint = $builder->build();
0 ignored issues
show
Unused Code introduced by
$endpoint is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
40
    }
41
}
42
43
/**
44
 * Class TestABC
45
 *
46
 * @author Dmytro Naumenko <[email protected]>
47
 */
48
class FakeEndpointBuilder implements
49
    EndpointBuilderInterface,
50
    ExamplesAwareBuilderInterface,
51
    InOutControlBuilderInterface
52
{
53
    use ExamplesAwareBuilderTrait;
54
    use InOutControlBuilderTrait {
55
        buildInOutParameters as buildInOutControl;
56
    }
57
58
    /**
59
     * @return Closure[]
60
     */
61
    protected function getBuildersList(): array
62
    {
63
        return [
64
            Closure::fromCallable([$this, 'buildExamples']),
65
            Closure::fromCallable([$this, 'buildInOutControl']),
66
        ];
67
    }
68
69
    /**
70
     * @inheritDoc
71
     */
72
    public function build()
73
    {
74
        $builders = $this->getBuildersList();
75
76
        $config = new EndpointConfig();
77
        foreach ($builders as $builder) {
78
            $builder($config);
79
        }
80
81
        return FakeEndpoint::fromConfig($config);
82
    }
83
};
84