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
Push — master ( 70c46b...316b2b )
by Hilari
02:09
created

TestCache::hasBeenSet()   B

Complexity

Conditions 7
Paths 5

Size

Total Lines 20
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 20
rs 8.2222
cc 7
eloc 10
nc 5
nop 3
1
<?php
2
3
namespace Cmp\Cache\Application;
4
5
/**
6
 * Class TestCache
7
 *
8
 * A backend especially designed for testing
9
 *
10
 * @package Cmp\Cache\Infrastureture
11
 */
12
class TestCache 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 ($set['key'] != $key) {
75
                continue;
76
            }
77
78
            if ($value !== null && $set['value'] != $value) {
79
                continue;
80
            }
81
82
            if ($timeToLive !== null && $set['timeToLive'] !== $timeToLive) {
83
                continue;
84
            }
85
86
            return true;
87
        }
88
89
        return false;
90
    }
91
92
    /**
93
     * @return array
94
     */
95
    public function getCalls()
96
    {
97
        return $this->calls;
98
    }
99
100
    /**
101
     * {@inheritdoc}
102
     */
103
    public function delete($key)
104
    {
105
        $this->calls['delete'][] = $key;
106
107
        parent::delete($key);
108
    }
109
110
    /**
111
     * {@inheritdoc}
112
     */
113
    public function set($key, $value, $timeToLive = 0)
114
    {
115
        $this->calls['set'][] = [
116
            'key'        => $key,
117
            'value'      => $value,
118
            'timeToLive' => $timeToLive,
119
        ];
120
121
        parent::set($key, $value, $timeToLive);
122
    }
123
124
    /**
125
     * {@inheritdoc}
126
     */
127
    public function has($key)
128
    {
129
        $this->calls['has'][] = $key;
130
131
        return parent::has($key);
132
    }
133
134
    /**
135
     * {@inheritdoc}
136
     */
137
    public function get($key)
138
    {
139
        $this->calls['get'][] = $key;
140
141
        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...
142
    }
143
144
    /**
145
     * Tries to match a call by the key
146
     *
147
     * @param array  $calls
148
     * @param string $key
149
     *
150
     * @return bool
151
     */
152
    private function hasBeenDoneByKey(array $calls, $key)
153
    {
154
        foreach ($calls as $keyOnCall) {
155
            if ($keyOnCall == $key) {
156
                return true;
157
            }
158
        }
159
160
        return false;
161
    }
162
}
163