Completed
Push — master ( 9abbc7...a687e5 )
by Fabrizio
03:03
created

SenderManagerSpec   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 82
Duplicated Lines 36.59 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 7
c 2
b 1
f 0
lcom 0
cbo 5
dl 30
loc 82
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 4 1
A it_is_initializable() 0 4 1
A it_send_now_a_notification() 15 15 1
A it_send_one_notification() 15 15 1
A it_send_multiple_notification() 0 14 1
A it_call_an_extended_method() 0 12 1
A it_try_to_call_an_inexistent_extended_method() 0 4 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
namespace spec\Fenos\Notifynder\Senders;
4
5
use BadMethodCallException;
6
use Fenos\Notifynder\Contracts\DefaultSender;
7
use Fenos\Notifynder\Contracts\StoreNotification;
8
use Fenos\Notifynder\Senders\SenderFactory;
9
use Illuminate\Contracts\Foundation\Application;
10
use PhpSpec\ObjectBehavior;
11
12
class SenderManagerSpec extends ObjectBehavior
13
{
14
    public function let(SenderFactory $senderFactory, StoreNotification $storeNotification, Application $application)
15
    {
16
        $this->beConstructedWith($senderFactory, $storeNotification, $application);
17
    }
18
19
    public function it_is_initializable()
20
    {
21
        $this->shouldHaveType('Fenos\Notifynder\Senders\SenderManager');
22
    }
23
24
    /** @test */
25 View Code Duplication
    public function it_send_now_a_notification(SenderFactory $senderFactory,
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...
26
                                        DefaultSender $sender,
27
                                        StoreNotification $storeNotification)
28
    {
29
        $notifications = [];
30
        $category = 1;
31
32
        $senderFactory->getSender($notifications, $category)->shouldBeCalled()
33
                ->willReturn($sender);
34
35
        $sender->send($storeNotification)->shouldBeCalled()
36
                ->willReturn(1);
37
38
        $this->sendNow($notifications, $category)->shouldReturn(1);
39
    }
40
41
    /** @test */
42 View Code Duplication
    public function it_send_one_notification(SenderFactory $senderFactory,
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...
43
                                      DefaultSender $sender,
44
                                      StoreNotification $storeNotification)
45
    {
46
        $notifications = [];
47
        $category = 1;
48
49
        $senderFactory->sendSingle($notifications, $category)->shouldBeCalled()
50
            ->willReturn($sender);
51
52
        $sender->send($storeNotification, $category)->shouldBeCalled()
53
            ->willReturn(1);
54
55
        $this->sendOne($notifications, $category)->shouldReturn(1);
56
    }
57
58
    /** @test */
59
    public function it_send_multiple_notification(SenderFactory $senderFactory,
60
                                      DefaultSender $sender,
61
                                      StoreNotification $storeNotification)
62
    {
63
        $notifications = [];
64
65
        $senderFactory->sendMultiple($notifications)->shouldBeCalled()
66
            ->willReturn($sender);
67
68
        $sender->send($storeNotification)->shouldBeCalled()
69
            ->willReturn(1);
70
71
        $this->sendMultiple($notifications)->shouldReturn(1);
72
    }
73
74
    /** @test */
75
    public function it_call_an_extended_method(SenderFactory $senderFactory,
0 ignored issues
show
Unused Code introduced by
The parameter $senderFactory is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
76
                                        DefaultSender $sender,
77
                                        StoreNotification $storeNotification)
0 ignored issues
show
Unused Code introduced by
The parameter $storeNotification is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
78
    {
79
        $notifications = [];
80
81
        $this->extend('sendExtended', function ($app) use ($sender) {
0 ignored issues
show
Bug introduced by
The method extend() does not exist on spec\Fenos\Notifynder\Senders\SenderManagerSpec. Did you maybe mean it_call_an_extended_method()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
Unused Code introduced by
The parameter $app is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
82
            return new TestExtender();
83
        });
84
85
        $this->sendExtended($notifications)->shouldReturn([]);
86
    }
87
88
    /** @test */
89
    public function it_try_to_call_an_inexistent_extended_method()
90
    {
91
        $this->shouldThrow(BadMethodCallException::class)->during('NotExistingExtender', []);
92
    }
93
}
94
95
/*
96
|--------------------------------------------------------------------------
97
| Extended class
98
|--------------------------------------------------------------------------
99
| Test Extender sender class
100
--------------------------------------------------------------------------*/
101
102
class TestExtender implements DefaultSender
103
{
104
    /**
105
     * Send Single notification.
106
     *
107
     * @param StoreNotification $sender
108
     * @return mixed
109
     */
110
    public function send(StoreNotification $sender)
111
    {
112
        return [];
113
    }
114
}
115