Completed
Push — master ( 092ec7...c255e1 )
by Victor
9s
created

Registry   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 47.37%

Importance

Changes 3
Bugs 1 Features 0
Metric Value
wmc 7
c 3
b 1
f 0
lcom 1
cbo 0
dl 0
loc 44
ccs 9
cts 19
cp 0.4737
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A set() 0 4 1
A get() 0 9 3
A clear() 0 4 1
A clearAll() 0 5 2
1
<?php
2
3
/**
4
 * @author Victor Dubiniuk <[email protected]>
5
 *
6
 * @copyright Copyright (c) 2015, ownCloud, Inc.
7
 * @license AGPL-3.0
8
 *
9
 * This code is free software: you can redistribute it and/or modify
10
 * it under the terms of the GNU Affero General Public License, version 3,
11
 * as published by the Free Software Foundation.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
 * GNU Affero General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Affero General Public License, version 3,
19
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
20
 *
21
 */
22
23
namespace Owncloud\Updater\Utils;
24
25
class Registry {
26
27
	protected $objects = array();
28
29
	/**
30
	 *
31
	 * @param string $name
32
	 * @param mixed $object
33
	 */
34 3
	public function set($name, $object){
35 3
		$this->objects[$name] = $object;
36 3
		$_SESSION[$name] = serialize($object);
37 3
	}
38
39
	/**
40
	 *
41
	 * @param string $name
42
	 * @return mixed
43
	 */
44 4
	public function get($name){
45 4
		if (isset($this->objects[$name])){
46 3
			return $this->objects[$name];
47 1
		} else if (isset($_SESSION[$name])){
48
			$this->objects[$name] = unserialize($_SESSION[$name]);
49
			return $this->objects[$name];
50
		}
51 1
		return null;
52
	}
53
54
	/**
55
	 *
56
	 * @param string $name
57
	 */
58
	public function clear($name){
59
		unset($this->objects[$name]);
60
		unset($_SESSION[$name]);
61
	}
62
63
	public function clearAll(){
64
		foreach ($this->objects as $name=>$value){
65
			$this->clear($name);
66
		}
67
	}
68
}
69