ArticleSpec::let()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 74

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 74
rs 8.5672
c 0
b 0
f 0
cc 1
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace spec\Yproximite\Api\Model\Article;
4
5
use PhpSpec\ObjectBehavior;
6
7
use Yproximite\Api\Model\Article\Article;
8
use Yproximite\Api\Model\Inheritance\InheritanceStatuses;
9
10
class ArticleSpec extends ObjectBehavior
11
{
12
    function it_is_initializable()
13
    {
14
        $this->shouldHaveType(Article::class);
15
    }
16
17
    function let()
18
    {
19
        $translation = [
20
            'locale' => 'en',
21
            'title'  => 'English translation',
22
            'body'   => 'Big text',
23
            'slug'   => 'en-translation',
24
        ];
25
26
        $categoryTranslation = [
27
            'locale'      => 'en',
28
            'title'       => 'English category translation',
29
            'description' => 'Big category text',
30
        ];
31
32
        $category = [
33
            'id'                 => '3',
34
            'translations'       => ['en' => $categoryTranslation],
35
            'enabled'            => 1,
36
            'dataParent'         => '11',
37
            'parentRootId'       => '123',
38
            'createdAt'          => ['date' => '2011-05-19 20:46:21.000000', 'timezone_type' => 3, 'timezone' => 'UTC'],
39
            'updatedAt'          => ['date' => '2016-01-11 00:00:00.000000', 'timezone_type' => 3, 'timezone' => 'UTC'],
40
            'inheritance_status' => 'none',
41
        ];
42
43
        $media = [
44
            'id'                      => '5',
45
            'filename'                => 'apple-box',
46
            'originalFilename'        => 'Apple Box',
47
            'originalFilenameSlugged' => 'App..Box.jpeg',
48
            'description'             => 'The biggest image',
49
            'title'                   => 'Apple Box Title',
50
            'visible'                 => 1,
51
            'created_at'              => '2011-05-19 20:46:21.000000',
52
            'updated_at'              => '2016-01-11 00:00:00.000000',
53
            'mime'                    => 'image/jpeg',
54
            'type'                    => 'image',
55
            'size'                    => 11345,
56
            'extension'               => 'jpg',
57
            'category_ids'            => [1, 2, 3],
58
            'link_url'                => 'http://site.com/media/original/apple-box.jpg',
59
        ];
60
61
        $articleMedia = [
62
            'id'            => '10',
63
            'display_order' => '5',
64
            'media'         => $media,
65
        ];
66
67
        $data = [
68
            'id'                    => '7',
69
            'translations'          => ['en' => $translation],
70
            'categories'            => [$category],
71
            'medias'                => [$articleMedia],
72
            'media_limit'           => '9',
73
            'status'                => 'published',
74
            'display_print_button'  => 1,
75
            'display_print_address' => 0,
76
            'with_return_button'    => 1,
77
            'show_creation_date'    => 1,
78
            'show_image_caption'    => 0,
79
            'auto_play_slider'      => 1,
80
            'routes'                => ['en' => 'simple-route-path'],
81
            'share_on_facebook'     => 1,
82
            'display_order'         => '5',
83
            'dataParent'            => '89',
84
            'createdAt'             => ['date' => '2011-05-19 20:46:21.000000', 'timezone_type' => 3, 'timezone' => 'UTC'],
85
            'updatedAt'             => ['date' => '2016-01-11 00:00:00.000000', 'timezone_type' => 3, 'timezone' => 'UTC'],
86
            'inheritance_status'    => 'inherited',
87
        ];
88
89
        $this->beConstructedWith($data);
90
    }
91
92
    function it_should_be_hydrated()
93
    {
94
        $this->getId()->shouldReturn(7);
95
        $this->getTranslations()->shouldHaveCount(1);
96
        $this->getCategories()->shouldHaveCount(1);
97
        $this->getMedias()->shouldHaveCount(1);
98
        $this->getMediaLimit()->shouldReturn(9);
99
        $this->getStatus()->shouldReturn(Article::STATUS_PUBLISHED);
100
        $this->isDisplayPrintButton()->shouldReturn(true);
101
        $this->isDisplayPrintAddress()->shouldReturn(false);
102
        $this->isWithReturnButton()->shouldReturn(true);
103
        $this->isShowCreationDate()->shouldReturn(true);
104
        $this->isShowImageCaption()->shouldReturn(false);
105
        $this->isAutoPlaySlider()->shouldReturn(true);
106
        $this->getRoutes()->shouldHaveCount(1);
107
        $this->isShareOnFacebook()->shouldReturn(true);
108
        $this->getDisplayOrder()->shouldReturn(5);
109
        $this->getDataParentId()->shouldReturn(89);
110
        $this->getCreatedAt()->shouldBeLike(new \DateTime('2011-05-19 20:46:21'));
111
        $this->getUpdatedAt()->shouldBeLike(new \DateTime('2016-01-11 00:00:00'));
112
        $this->getInheritanceStatus()->shouldReturn(InheritanceStatuses::INHERITED);
113
    }
114
}
115