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 ( dec958...1175d2 )
by Jacky
32s
created

Session::remove()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Asylamba\Classes\Library\Session;
4
5
use Asylamba\Classes\Library\Utils;
6
use Asylamba\Classes\Library\Flashbag;
7
8
use Asylamba\Classes\Container\ArrayList;
9
use Asylamba\Classes\Container\StackList;
10
use Asylamba\Classes\Container\EventList;
11
12
class Session {
13
	/** @var array **/
14
	public $flashbags = [];
15
    /** @var array **/
16
    protected $items = [];
17
	/** @var array **/
18
	protected $history = [];
19
	
20
	/**
21
	 * @param string $message
22
	 * @param string $type
23
	 */ 
24
	public function addFlashbag($message, $type)
25
	{
26
		$this->flashbags[] = new Flashbag($message, $type);
27
	}
28
	
29
	/**
30
	 * @return array
31
	 */
32
	public function getFlashbags()
33
	{
34
		return $this->flashbags;
35
	}
36
	
37
	public function flushFlashbags()
38
	{
39
		$this->flashbags = [];
40
	}
41
	
42
	/**
43
	 * @param string $key
44
	 * @param string $value
45
	 */ 
46
	public function add($key, $value)
47
	{
48
		$this->items[$key] = $value;
49
	}
50
    
51
    /**
52
     * @param string $key
53
     * @return boolean
54
     */
55
    public function exist($key)
56
    {
57
        return isset($this->items[$key]);
58
    }
59
	
60
	/**
61
     * @param string $key
62
	 * @return mixed
63
	 */
64
	public function get($key)
65
	{
66
		return $this->exist($key) ? $this->items[$key] : null;
67
	}
68
	
69
	/**
70
	 * @return array
71
	 */
72
	public function all()
73
	{
74
		return $this->items;
75
	}
76
	
77
    /**
78
     * @param string $key
79
     * @return boolean
80
     */
81
    public function remove($key) {
82
        if (isset($this->items[$key])) {
83
            unset($this->items[$key]);
84
        }
85
        return false;
86
    }
87
	
88
    public function destroy() {
89
		$this->items = [];
90
		$this->flashbags = [];
91
		$this->history = [];
92
    }
93
94
    public function clear() {
95
        $this->remove('playerInfo');
96
        $this->remove('playerBase');
97
        $this->remove('playerEvent');
98
    }
99
100
    ##
101
102
    public function initPlayerInfo() {
103
            $this->add('playerInfo', new ArrayList());
0 ignored issues
show
Documentation introduced by
new \Asylamba\Classes\Container\ArrayList() is of type object<Asylamba\Classes\Container\ArrayList>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
104
    }
105
106
    public function initPlayerBase() {
107
            $a = new ArrayList();
108
            $a->add('ob', new StackList());
109
            $a->add('ms', new StackList());
110
111
            $this->add('playerBase', $a);
0 ignored issues
show
Documentation introduced by
$a is of type object<Asylamba\Classes\Container\ArrayList>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
112
    }
113
114
    public function initPlayerEvent() {
115
            $this->add('playerEvent', new EventList());
0 ignored issues
show
Documentation introduced by
new \Asylamba\Classes\Container\EventList() is of type object<Asylamba\Classes\Container\EventList>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
116
    }
117
118
    public function initLastUpdate() {
119
            $l = new ArrayList();
120
            $l->add('game',  Utils::now());
0 ignored issues
show
Coding Style introduced by
Expected 1 space instead of 2 after comma in function call.
Loading history...
121
            $l->add('event', Utils::now());
122
123
            $this->add('lastUpdate', $l);
0 ignored issues
show
Documentation introduced by
$l is of type object<Asylamba\Classes\Container\ArrayList>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
124
    }
125
126
    public function initPlayerBonus() {
127
            $this->add('playerBonus', new StackList());
0 ignored issues
show
Documentation introduced by
new \Asylamba\Classes\Container\StackList() is of type object<Asylamba\Classes\Container\StackList>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
128
    }
129
130
    ##
131
    /**
132
     * @param string $key
133
     * @param int $id
134
     * @param string $name
135
     * @param string $sector
136
     * @param string $system
137
     * @param string $img
138
     * @param string $type
139
     * @return boolean
140
     */
141
    public function addBase($key, $id, $name, $sector, $system, $img, $type) {
142
        if ($this->exist('playerBase')) {
143
            if ($key != 'ob' && $key != 'ms') {
144
                return false;
145
            }
146
            $a = new ArrayList();
147
148
            $a->add('id', $id);
149
            $a->add('name', $name);
150
            $a->add('sector', $sector);
151
            $a->add('system', $system);
152
            $a->add('img', $img);
153
            $a->add('type', $type);
154
155
            $this->get('playerBase')->get($key)->append($a);
156
        }
157
    }
158
159
    /**
160
     * @param string $key
161
     * @param int $id
162
     */
163
    public function removeBase($key, $id) {
164
        if ($this->exist('playerBase')) {
165
            $size = $this->get('playerBase')->get($key)->size();
166
            for ($i = 0; $i < $size; $i++) {
167
                if ($this->get('playerBase')->get($key)->get($i)->get('id') == $id) {
168
                    $this->get('playerBase')->get($key)->remove($i);
169
					return;
170
                }
171
            }
172
        }
173
    }
174
175
    /**
176
     * @param int $id
177
     * @return boolean
178
     */
179
    public function baseExist($id) {
180
        $obSize = $this->get('playerBase')->get('ob')->size();
181
        for ($i = 0; $i < $obSize; $i++) {
182
            if ($id == $this->get('playerBase')->get('ob')->get($i)->get('id')) {
183
                return TRUE;
184
            }
185
        }
186
        $msSize = $this->get('playerBase')->get('ms')->size();
187
        for ($i = 0; $i < $msSize; $i++) {
188
            if ($id == $this->get('playerBase')->get('ms')->get($i)->get('id')) {
189
                return TRUE;
190
            }
191
        }
192
        return FALSE;
193
    }
194
	
195
	/**
196
	 * @param string $path
197
	 */
198
	public function addHistory($path)
199
	{
200
		$this->history[] = $path;
201
	}
202
	
203
	/**
204
	 * @return array
205
	 */
206
	public function getHistory()
207
	{
208
		return $this->history;
209
	}
210
	
211
	/**
212
	 * @return string
213
	 */
214
	public function getLastHistory()
215
	{
216
		return $this->history[count($this->history) - 1];
217
	}
218
	
219
	/**
220
	 * @return int
221
	 */
222
	public function getLifetime()
223
	{
224
		return $this->lifetime;
0 ignored issues
show
Bug introduced by
The property lifetime does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
225
	}
226
	
227
	public function setData($data)
228
	{
229
		$this->history = $data['history'];
230
		$this->flashbags = $data['flashbags'];
231
		$this->items = $data['items'];
232
	}
233
	
234
	public function getData()
235
	{
236
		return [
237
			'history' => $this->history,
238
			'flashbags' => $this->flashbags,
239
			'items' => $this->items
240
		];
241
	}
242
}