Passed
Pull Request — master (#12)
by romain
09:45
created

TeamWorkerServiceSpec   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 55
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 5
dl 55
loc 55
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
namespace spec\Yproximite\Api\Service;
4
5
use PhpSpec\ObjectBehavior;
6
7
use Yproximite\Api\Client\Client;
8
use Yproximite\Api\Factory\ModelFactory;
9
use Yproximite\Api\Model\TeamWorker\TeamWorker;
10
use Yproximite\Api\Service\TeamWorkerService;
11
use Yproximite\Api\Message\TeamWorker\TeamWorkerPostMessage;
12
use Yproximite\Api\Message\TeamWorker\TeamWorkerPatchMessage;
13
14
class TeamWorkerServiceSpec extends ObjectBehavior
15
{
16
    function it_is_initializable()
17
    {
18
        $this->shouldHaveType(TeamWorkerService::class);
19
    }
20
21
    function let(Client $client, ModelFactory $factory)
22
    {
23
        $this->beConstructedWith($client, $factory);
24
    }
25
26
    function it_should_post_team_worker(
27
        Client $client,
28
        ModelFactory $factory,
29
        TeamWorkerPostMessage $message,
30
        TeamWorker $teamWorker
31
    ) {
32
        $message->getSiteId()->willReturn(1);
33
        $message->build()->willReturn([]);
34
35
        $method = 'POST';
36
        $path   = 'sites/1/teams/workers';
37
        $data   = ['api_team_worker' => []];
38
39
        $client->sendRequest($method, $path, $data)->willReturn([]);
40
        $client->sendRequest($method, $path, $data)->shouldBeCalled();
41
42
        $factory->create(TeamWorker::class, [])->willReturn($teamWorker);
43
44
        $this->postTeamWorker($message);
45
    }
46
47
    function it_should_patch_team_worker(
48
        Client $client,
49
        ModelFactory $factory,
50
        TeamWorkerPatchMessage $message,
51
        TeamWorker $teamWorker
52
    ) {
53
        $message->getId()->willReturn(2);
54
        $message->getSiteId()->willReturn(1);
55
        $message->build()->willReturn([]);
56
57
        $method = 'PATCH';
58
        $path   = 'sites/1/teams/2/worker';
59
        $data   = ['api_team_worker' => []];
60
61
        $client->sendRequest($method, $path, $data)->willReturn([]);
62
        $client->sendRequest($method, $path, $data)->shouldBeCalled();
63
64
        $factory->create(TeamWorker::class, [])->willReturn($teamWorker);
65
66
        $this->patchTeamWorker($message);
67
    }
68
}
69