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.
Cancelled
Push — master ( 316b2b...ea2786 )
by Hilari
02:20
created

TestCacheDecorator::hasBeenRetrieved()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Cmp\Cache\Application;
4
5
/**
6
 * Class TestCacheDecorator
7
 *
8
 * A backend especially designed for testing
9
 *
10
 * @package Cmp\Cache\Infrastureture
11
 */
12
class TestCacheDecorator extends CacheDecorator
13
{
14
    /**
15
     * Calls made to the cache
16
     *
17
     * @var array
18
     */
19
    private $calls = [
20
        'delete' => [],
21
        'set'    => [],
22
        'has'    => [],
23
        'get'    => [],
24
    ];
25
26
    /**
27
     * Checks if an item has been deleted
28
     *
29
     * @param string $key
30
     *
31
     * @return bool
32
     */
33
    public function hasBeenDeleted($key)
34
    {
35
        return $this->hasBeenDoneByKey($this->calls['delete'], $key);
36
    }
37
38
    /**
39
     * Checks if an item has been requested with 'get' or 'pull'
40
     *
41
     * @param string $key
42
     *
43
     * @return bool
44
     */
45
    public function hasBeenRetrieved($key)
46
    {
47
        return $this->hasBeenDoneByKey($this->calls['get'], $key);
48
    }
49
50
    /**
51
     * Checks if an item has been checked with the 'has' method
52
     *
53
     * @param string $key
54
     *
55
     * @return bool
56
     */
57
    public function hasBeenChecked($key)
58
    {
59
        return $this->hasBeenDoneByKey($this->calls['has'], $key);
60
    }
61
62
    /**
63
     * Checks if an item has been set
64
     *
65
     * @param string   $key
66
     * @param mixed    $value
67
     * @param int|null $timeToLive
68
     *
69
     * @return bool
70
     */
71
    public function hasBeenSet($key, $value = null, $timeToLive = null)
72
    {
73
        foreach ($this->calls['set'] as $set) {
74
            if ($this->callMatches($set, $key, $value, $timeToLive)) {
75
                return true;
76
            }
77
        }
78
79
        return false;
80
    }
81
82
    /**
83
     * @return array
84
     */
85
    public function getCalls()
86
    {
87
        return $this->calls;
88
    }
89
90
    /**
91
     * {@inheritdoc}
92
     */
93
    public function delete($key)
94
    {
95
        $this->calls['delete'][] = $key;
96
97
        parent::delete($key);
98
    }
99
100
    /**
101
     * {@inheritdoc}
102
     */
103
    public function set($key, $value, $timeToLive = 0)
104
    {
105
        $this->calls['set'][] = [
106
            'key'        => $key,
107
            'value'      => $value,
108
            'timeToLive' => $timeToLive,
109
        ];
110
111
        parent::set($key, $value, $timeToLive);
112
    }
113
114
    /**
115
     * {@inheritdoc}
116
     */
117
    public function has($key)
118
    {
119
        $this->calls['has'][] = $key;
120
121
        return parent::has($key);
122
    }
123
124
    /**
125
     * {@inheritdoc}
126
     */
127
    public function get($key)
128
    {
129
        $this->calls['get'][] = $key;
130
131
        return parent::has($key);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (has() instead of get()). Are you sure this is correct? If so, you might want to change this to $this->has().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
132
    }
133
134
    /**
135
     * Tries to match a call by the key
136
     *
137
     * @param array  $calls
138
     * @param string $key
139
     *
140
     * @return bool
141
     */
142
    private function hasBeenDoneByKey(array $calls, $key)
143
    {
144
        foreach ($calls as $keyOnCall) {
145
            if ($keyOnCall == $key) {
146
                return true;
147
            }
148
        }
149
150
        return false;
151
    }
152
153
    /**
154
     * @param array    $set
155
     * @param string   $key
156
     * @param mixed    $value
157
     * @param null|int $timeToLive
158
     *
159
     * @return bool
160
     */
161
    private function callMatches(array $set, $key, $value = null, $timeToLive)
162
    {
163
        if ($set['key'] != $key) {
164
            return false;
165
        }
166
167
        if ($value !== null && $set['value'] != $value) {
168
            return false;
169
        }
170
171
        if ($timeToLive !== null && $set['timeToLive'] !== $timeToLive) {
172
            return false;
173
        }
174
175
        return true;
176
    }
177
}
178