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

CallTrackingServiceSpec   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 54
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 5
dl 54
loc 54
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\Model\CallTracking\CallTracking;
9
use Yproximite\Api\Service\CallTrackingService;
10
use Yproximite\Api\Factory\ModelFactory;
11
use Yproximite\Api\Message\CallTracking\CallTrackingPostMessage;
12
use Yproximite\Api\Message\CallTracking\CallTrackingPatchMessage;
13
14
class CallTrackingServiceSpec extends ObjectBehavior
15
{
16
    function it_is_initializable()
17
    {
18
        $this->shouldHaveType(CallTrackingService::class);
19
    }
20
21
    function let(Client $client, ModelFactory $factory)
22
    {
23
        $this->beConstructedWith($client, $factory);
24
    }
25
26
    function it_should_post_call_tracking(
27
        Client $client,
28
        ModelFactory $factory,
29
        CallTrackingPostMessage $message,
30
        CallTracking $callTracking
31
    ) {
32
        $message->getSiteId()->willReturn(1);
33
        $message->build()->willReturn([]);
34
35
        $method = 'POST';
36
        $path   = 'sites/1/call_trackings';
37
        $data   = ['api_call_tracking' => []];
38
39
        $client->sendRequest($method, $path, $data)->willReturn([]);
40
        $client->sendRequest($method, $path, $data)->shouldBeCalled();
41
42
        $factory->create(CallTracking::class, [])->willReturn($callTracking);
43
44
        $this->postCallTracking($message);
45
    }
46
47
    function it_should_patch_call_tracking(
48
        Client $client,
49
        ModelFactory $factory,
50
        CallTrackingPatchMessage $message,
51
        CallTracking $callTracking
52
    ) {
53
        $message->getSiteId()->willReturn(1);
54
        $message->build()->willReturn([]);
55
56
        $method = 'PATCH';
57
        $path   = 'sites/1/call_trackings/update';
58
        $data   = ['api_call_tracking_edit' => []];
59
60
        $client->sendRequest($method, $path, $data)->willReturn([]);
61
        $client->sendRequest($method, $path, $data)->shouldBeCalled();
62
63
        $factory->create(CallTracking::class, [])->willReturn($callTracking);
64
65
        $this->patchCallTracking($message);
66
    }
67
}
68