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

LocationSpec   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 52
Duplicated Lines 50 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 26
loc 52
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\Model\Location;
4
5
use PhpSpec\ObjectBehavior;
6
7
use Yproximite\Api\Model\Inheritance\InheritanceStatuses;
8
use Yproximite\Api\Model\Location\Location;
9
10
class LocationSpec extends ObjectBehavior
11
{
12
    function it_is_initializable()
13
    {
14
        $this->shouldHaveType(Location::class);
15
    }
16
17
    function let()
18
    {
19
        $translation = [
20
            'title'        => 'Some location',
21
            'openingHours' => '24/7',
22
        ];
23
24
        $data = [
25
            'id'                 => '3',
26
            'tel'                => '+1 123 456 78 90',
27
            'fax'                => '+2 456 111 78 90',
28
            'mail'               => '[email protected]',
29
            'address'            => '88 St Patrick St',
30
            'postalCode'         => 'M5T 1V1',
31
            'town'               => 'City',
32
            'latitude'           => '43.6527222',
33
            'longitude'          => '-79.3918831',
34
            'country'            => 'Canada',
35
            'defaultLocation'    => 0,
36
            'dataParent'         => '11',
37
            'translations'       => ['en' => $translation],
38
            'inheritance_status' => 'overridden',
39
        ];
40
41
        $this->beConstructedWith($data);
42
    }
43
44
    function it_should_be_hydrated()
45
    {
46
        $this->getId()->shouldReturn(3);
47
        $this->getTel()->shouldReturn('+1 123 456 78 90');
48
        $this->getFax()->shouldReturn('+2 456 111 78 90');
49
        $this->getMail()->shouldReturn('[email protected]');
50
        $this->getAddress()->shouldReturn('88 St Patrick St');
51
        $this->getPostalCode()->shouldReturn('M5T 1V1');
52
        $this->getTown()->shouldReturn('City');
53
        $this->getLatitude()->shouldReturn('43.6527222');
54
        $this->getLongitude()->shouldReturn('-79.3918831');
55
        $this->getCountry()->shouldReturn('Canada');
56
        $this->isDefaultLocation()->shouldReturn(false);
57
        $this->getDataParentId()->shouldReturn(11);
58
        $this->getTranslations()->shouldHaveCount(1);
59
        $this->getInheritanceStatus()->shouldReturn(InheritanceStatuses::OVERRIDDEN);
60
    }
61
}
62