Completed
Push — master ( bd4c23...b341c0 )
by Filipe
10:29
created

FlashMessagesSpec   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 40.91 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 2
dl 18
loc 44
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 4 1
A it_is_initializable() 0 4 1
A it_registers_a_message_with_provided_type() 9 9 1
A it_registers_an_info_message_when_an_unknown_type_is_given() 9 9 1
A it_flushes_all_messages_when_they_are_retrieved() 0 11 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\Slick\Mvc\Service;
4
5
use PhpSpec\ObjectBehavior;
6
use Slick\Http\SessionDriverInterface;
7
use Slick\Mvc\Service\FlashMessages;
8
9
class FlashMessagesSpec extends ObjectBehavior
10
{
11
    function let(SessionDriverInterface $sessionDriver)
12
    {
13
        $this->beConstructedWith($sessionDriver);
14
    }
15
16
    function it_is_initializable()
17
    {
18
        $this->shouldHaveType(FlashMessages::class);
19
    }
20
21 View Code Duplication
    function it_registers_a_message_with_provided_type(
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...
22
        SessionDriverInterface $sessionDriver
23
    )
24
    {
25
        $this->set(FlashMessages::TYPE_INFO, 'Test!')
26
            ->shouldBe($this->getWrappedObject());
27
        $sessionDriver->set('_messages_', [FlashMessages::TYPE_INFO => ['Test!']])
28
            ->shouldHaveBeenCalled();
29
    }
30
31 View Code Duplication
    function it_registers_an_info_message_when_an_unknown_type_is_given(
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...
32
        SessionDriverInterface $sessionDriver
33
    )
34
    {
35
        $sessionDriver->set('_messages_', [FlashMessages::TYPE_INFO => ['Test!', 'Test!']])
36
            ->shouldBeCalled();
37
        $this->set('other', 'Test!')
38
            ->shouldBe($this->getWrappedObject());
39
    }
40
41
    function it_flushes_all_messages_when_they_are_retrieved(
42
        SessionDriverInterface $sessionDriver
43
    )
44
    {
45
        $messages = [1=>['test']];
46
        $sessionDriver->get('_messages_', [])->shouldBeCalled()
47
            ->willReturn($messages);
48
49
        $sessionDriver->erase('_messages_')->shouldBeCalled();
50
        $this->get()->shouldBe($messages);
51
    }
52
}
53