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

FieldSpec   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 29.73 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 11
loc 37
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\Field;
4
5
use PhpSpec\ObjectBehavior;
6
7
use Yproximite\Api\Model\Field\Field;
8
use Yproximite\Api\Model\Inheritance\InheritanceStatuses;
9
10
class FieldSpec extends ObjectBehavior
11
{
12
    function it_is_initializable()
13
    {
14
        $this->shouldHaveType(Field::class);
15
    }
16
17
    function let()
18
    {
19
        $transData = ['value' => 'Required field'];
20
21
        $data = [
22
            'id'                 => '7',
23
            'token'              => 'required-field',
24
            'description'        => 'Some information about it',
25
            'translations'       => ['en' => $transData],
26
            'dataParent'         => '8',
27
            'createdAt'          => ['date' => '2011-05-19 20:46:21.000000', 'timezone_type' => 3, 'timezone' => 'UTC'],
28
            'updatedAt'          => ['date' => '2016-01-11 00:00:00.000000', 'timezone_type' => 3, 'timezone' => 'UTC'],
29
            'inheritance_status' => 'inherited',
30
        ];
31
32
        $this->beConstructedWith($data);
33
    }
34
35
    function it_should_be_hydrated()
36
    {
37
        $this->getId()->shouldReturn(7);
38
        $this->getToken()->shouldReturn('required-field');
39
        $this->getDescription()->shouldReturn('Some information about it');
40
        $this->getTranslations()->shouldHaveCount(1);
41
        $this->getDataParentId()->shouldReturn(8);
42
        $this->getCreatedAt()->shouldBeLike(new \DateTime('2011-05-19 20:46:21'));
43
        $this->getUpdatedAt()->shouldBeLike(new \DateTime('2016-01-11 00:00:00'));
44
        $this->getInheritanceStatus()->shouldReturn(InheritanceStatuses::INHERITED);
45
    }
46
}
47