GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Branch v2 (a88462)
by Hilari
02:38
created

ChainCacheSpec   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 120
Duplicated Lines 38.33 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 14
c 1
b 0
f 0
lcom 0
cbo 3
dl 46
loc 120
rs 10

14 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 4 1
A it_is_initializable() 0 5 1
A it_executes_set_command_in_all_the_caches() 7 7 1
A it_returns_false_if_a_cache_fails() 7 7 1
A it_does_not_ask_to_all_caches_if_one_has_the_item() 0 8 1
A it_tries_all_the_caches_before_failing_to_checking_for_an_item() 7 7 1
A it_does_not_ask_to_all_caches_if_one_get_the_item() 0 9 1
A it_populates_previous_caches_if_they_have_failed_to_get_the_item() 0 9 1
A it_tries_all_the_caches_before_failing_to_get_an_item() 0 7 1
A it_can_demand_an_item() 0 9 1
A it_tries_all_the_caches_before_failing_to_demand_an_item() 0 7 1
A it_deletes_the_item_in_all_caches() 7 7 1
A it_flushes_all_caches() 7 7 1
A it_can_retrieve_the_time_to_live() 11 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\Cmp\Cache\Backend;
4
5
use Cmp\Cache\Cache;
6
use Cmp\Cache\Exceptions\NotFoundException;
7
use PhpSpec\ObjectBehavior;
8
9
/**
10
 * Class ChainCacheSpec
11
 *
12
 * @package spec\Cmp\Cache\Infrastructure\Backend
13
 * @mixin \Cmp\Cache\Backend\ChainCache
14
 */
15
class ChainCacheSpec extends ObjectBehavior
16
{
17
    function let(Cache $cacheOne, Cache $cacheTwo)
18
    {
19
        $this->pushCache($cacheOne)->pushCache($cacheTwo);
20
    } 
21
22
    function it_is_initializable()
23
    {
24
        $this->shouldHaveType('Cmp\Cache\Backend\ChainCache');
25
        $this->shouldHaveType('Cmp\Cache\Cache');
26
    }
27
28 View Code Duplication
    function it_executes_set_command_in_all_the_caches(Cache $cacheOne, Cache $cacheTwo)
1 ignored issue
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...
29
    {
30
        $cacheOne->set('foo', 'bar', 123)->willReturn(true);
31
        $cacheTwo->set('foo', 'bar', 123)->willReturn(true);
32
33
        $this->set('foo', 'bar', 123)->shouldReturn(true);
34
    }
35
36 View Code Duplication
    function it_returns_false_if_a_cache_fails(Cache $cacheOne, Cache $cacheTwo)
1 ignored issue
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...
37
    {
38
        $cacheOne->set('foo', 'bar', 123)->willReturn(true);
39
        $cacheTwo->set('foo', 'bar', 123)->willReturn(false);
40
41
        $this->set('foo', 'bar', 123)->shouldReturn(false);
42
    }
43
44
    function it_does_not_ask_to_all_caches_if_one_has_the_item(Cache $cacheOne, Cache $cacheTwo)
45
    {
46
        $cacheOne->has('foo')->willReturn(true);
47
48
        $this->has('foo')->shouldReturn(true);
49
50
        $cacheTwo->set('foo')->shouldNotHaveBeenCalled();
51
    }
52
53 View Code Duplication
    function it_tries_all_the_caches_before_failing_to_checking_for_an_item(Cache $cacheOne, Cache $cacheTwo)
1 ignored issue
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...
54
    {
55
        $cacheOne->has('foo')->willReturn(false);
56
        $cacheTwo->has('foo')->willReturn(false);
57
58
        $this->has('foo')->shouldReturn(false);
59
    }
60
61
    function it_does_not_ask_to_all_caches_if_one_get_the_item(Cache $cacheOne, Cache $cacheTwo)
62
    {
63
        $cacheOne->get('foo')->willReturn('item');
64
        $cacheOne->getTimeToLive('foo')->willReturn(null);
65
66
        $this->get('foo')->shouldReturn('item');
67
68
        $cacheTwo->get('foo')->shouldNotHaveBeenCalled();
69
    }
70
71
    function it_populates_previous_caches_if_they_have_failed_to_get_the_item(Cache $cacheOne, Cache $cacheTwo)
72
    {
73
        $cacheOne->get('foo')->willReturn(false);
74
        $cacheTwo->get('foo')->willReturn('item');
75
        $cacheTwo->getTimeToLive('foo')->willReturn(10);
76
        $cacheOne->set('foo', 'item', 10)->shouldBeCalled();
77
78
        $this->get('foo')->shouldReturn('item');
79
    }
80
81
    function it_tries_all_the_caches_before_failing_to_get_an_item(Cache $cacheOne, Cache $cacheTwo)
82
    {
83
        $cacheOne->get('foo')->willReturn(false);
84
        $cacheTwo->get('foo')->willReturn(false);
85
86
        $this->get('foo', 'default')->shouldReturn('default');
87
    }
88
89
    function it_can_demand_an_item(Cache $cacheOne, Cache $cacheTwo)
90
    {
91
        $cacheOne->get('foo')->willReturn(false);
92
        $cacheTwo->get('foo')->willReturn('bar');
93
        $cacheTwo->getTimeToLive('foo')->willReturn(null);
94
        $cacheOne->set('foo', 'bar', null)->shouldBeCalled();
95
96
        $this->demand('foo')->shouldReturn('bar');
97
    }
98
99
    function it_tries_all_the_caches_before_failing_to_demand_an_item(Cache $cacheOne, Cache $cacheTwo)
100
    {
101
        $cacheOne->get('foo')->willReturn(false);
102
        $cacheTwo->get('foo')->willReturn(false);
103
104
        $this->shouldThrow(new NotFoundException('foo'))->duringDemand('foo');
105
    }
106
107 View Code Duplication
    function it_deletes_the_item_in_all_caches(Cache $cacheOne, Cache $cacheTwo)
1 ignored issue
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...
108
    {
109
        $cacheOne->delete('foo')->willReturn(true);
110
        $cacheTwo->delete('foo')->willReturn(true);
111
112
        $this->delete('foo')->shouldReturn(true);
113
    }
114
115 View Code Duplication
    function it_flushes_all_caches(Cache $cacheOne, Cache $cacheTwo)
1 ignored issue
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...
116
    {
117
        $cacheOne->flush()->willReturn(true);
118
        $cacheTwo->flush()->willReturn(true);
119
120
        $this->flush()->shouldReturn(true);
121
    }
122
123 View Code Duplication
    function it_can_retrieve_the_time_to_live(Cache $cacheOne, Cache $cacheTwo)
1 ignored issue
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...
124
    {
125
        $cacheOne->getTimeToLive('foo')->willReturn(null);
126
        $cacheTwo->getTimeToLive('foo')->willReturn(100);
127
128
        $cacheOne->getTimeToLive('bar')->willReturn(null);
129
        $cacheTwo->getTimeToLive('bar')->willReturn(null);
130
131
        $this->getTimeToLive('foo')->shouldReturn(100);
132
        $this->getTimeToLive('bar')->shouldReturn(null);
133
    }
134
}
135