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

CompanyServiceSpec   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 53
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 5
dl 53
loc 53
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\Company\Company;
10
use Yproximite\Api\Service\CompanyService;
11
use Yproximite\Api\Message\Company\CompanyPostMessage;
12
use Yproximite\Api\Message\Company\CompanyPatchMessage;
13
14
class CompanyServiceSpec extends ObjectBehavior
15
{
16
    function it_is_initializable()
17
    {
18
        $this->shouldHaveType(CompanyService::class);
19
    }
20
21
    function let(Client $client, ModelFactory $factory)
22
    {
23
        $this->beConstructedWith($client, $factory);
24
    }
25
26
    function it_should_post_company(
27
        Client $client,
28
        ModelFactory $factory,
29
        CompanyPostMessage $message,
30
        Company $company
31
    ) {
32
        $message->build()->willReturn([]);
33
34
        $method = 'POST';
35
        $path   = 'companies';
36
        $data   = ['api_company' => []];
37
38
        $client->sendRequest($method, $path, $data)->willReturn([]);
39
        $client->sendRequest($method, $path, $data)->shouldBeCalled();
40
41
        $factory->create(Company::class, [])->willReturn($company);
42
43
        $this->postCompany($message);
44
    }
45
46
    function it_should_patch_company(
47
        Client $client,
48
        ModelFactory $factory,
49
        CompanyPatchMessage $message,
50
        Company $company
51
    ) {
52
        $message->getId()->willReturn(2);
53
        $message->build()->willReturn([]);
54
55
        $method = 'PATCH';
56
        $path   = 'companies/2';
57
        $data   = ['api_company' => []];
58
59
        $client->sendRequest($method, $path, $data)->willReturn([]);
60
        $client->sendRequest($method, $path, $data)->shouldBeCalled();
61
62
        $factory->create(Company::class, [])->willReturn($company);
63
64
        $this->patchCompany($message);
65
    }
66
}
67