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

CategorySpec   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 41
Duplicated Lines 78.05 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 32
loc 41
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\Article;
4
5
use PhpSpec\ObjectBehavior;
6
7
use Yproximite\Api\Model\Article\Category;
8
use Yproximite\Api\Model\Inheritance\InheritanceStatuses;
9
10
class CategorySpec extends ObjectBehavior
11
{
12
    function it_is_initializable()
13
    {
14
        $this->shouldHaveType(Category::class);
15
    }
16
17
    function let()
18
    {
19
        $translation = [
20
            'locale'      => 'en',
21
            'title'       => 'English translation',
22
            'description' => 'Big text',
23
        ];
24
25
        $data = [
26
            'id'                 => '3',
27
            'translations'       => ['en' => $translation],
28
            'enabled'            => 1,
29
            'dataParent'         => '11',
30
            'parentRootId'       => '123',
31
            'createdAt'          => ['date' => '2011-05-19 20:46:21.000000', 'timezone_type' => 3, 'timezone' => 'UTC'],
32
            'updatedAt'          => ['date' => '2016-01-11 00:00:00.000000', 'timezone_type' => 3, 'timezone' => 'UTC'],
33
            'inheritance_status' => 'none',
34
        ];
35
36
        $this->beConstructedWith($data);
37
    }
38
39
    function it_should_be_hydrated()
40
    {
41
        $this->getId()->shouldReturn(3);
42
        $this->getTranslations()->shouldHaveCount(1);
43
        $this->isEnabled()->shouldReturn(true);
44
        $this->getDataParentId()->shouldReturn(11);
45
        $this->getParentRootId()->shouldReturn(123);
46
        $this->getCreatedAt()->shouldBeLike(new \DateTime('2011-05-19 20:46:21'));
47
        $this->getUpdatedAt()->shouldBeLike(new \DateTime('2016-01-11 00:00:00'));
48
        $this->getInheritanceStatus()->shouldReturn(InheritanceStatuses::NONE);
49
    }
50
}
51