Completed
Pull Request — master (#366)
by Beñat
04:55
created

NotificationSpec   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 52
Duplicated Lines 53.85 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 28
loc 52
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A it_can_be_built() 14 14 1
A it_can_be_built_with_read_on() 14 14 1
A it_can_be_built_from_array() 0 19 1

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
/*
4
 * This file is part of the Kreta package.
5
 *
6
 * (c) Beñat Espiña <[email protected]>
7
 * (c) Gorka Laucirica <[email protected]>
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
declare(strict_types=1);
14
15
namespace Spec\Kreta\Notifier\Domain\ReadModel\Inbox\Notification;
16
17
use Kreta\Notifier\Domain\ReadModel\Inbox\Notification\Notification;
18
use PhpSpec\ObjectBehavior;
19
20
class NotificationSpec extends ObjectBehavior
21
{
22 View Code Duplication
    function it_can_be_built()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
23
    {
24
        $this->beConstructedWith('notification-id', 'user-id', 'The notification body', 638323200, 'unread');
25
        $this->shouldHaveType(Notification::class);
26
        $this->shouldImplement(\JsonSerializable::class);
27
        $this->jsonSerialize()->shouldReturn([
28
            'id'           => 'notification-id',
29
            'user_id'      => 'user-id',
30
            'body'         => 'The notification body',
31
            'published_on' => 638323200,
32
            'status'       => 'unread',
33
            'read_on'      => null,
34
        ]);
35
    }
36
37 View Code Duplication
    function it_can_be_built_with_read_on()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
38
    {
39
        $this->beConstructedWith('notification-id', 'user-id', 'The notification body', 638323200, 'read', 238343200);
40
        $this->shouldHaveType(Notification::class);
41
        $this->shouldImplement(\JsonSerializable::class);
42
        $this->jsonSerialize()->shouldReturn([
43
            'id'           => 'notification-id',
44
            'user_id'      => 'user-id',
45
            'body'         => 'The notification body',
46
            'published_on' => 638323200,
47
            'status'       => 'read',
48
            'read_on'      => 238343200,
49
        ]);
50
    }
51
52
    function it_can_be_built_from_array()
53
    {
54
        $this->beConstructedFromArray([
55
            'id'           => 'notification-id',
56
            'user_id'      => 'user-id',
57
            'body'         => 'The notification body',
58
            'published_on' => 638323200,
59
            'status'       => 'unread',
60
            'read_on'      => null,
61
        ]);
62
        $this->jsonSerialize()->shouldReturn([
63
            'id'           => 'notification-id',
64
            'user_id'      => 'user-id',
65
            'body'         => 'The notification body',
66
            'published_on' => 638323200,
67
            'status'       => 'unread',
68
            'read_on'      => null,
69
        ]);
70
    }
71
}
72