Completed
Pull Request — master (#217)
by Thomas
02:42
created

Registry   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 45%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 7
c 2
b 0
f 0
lcom 1
cbo 0
dl 0
loc 30
ccs 9
cts 20
cp 0.45
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 3
	public function set($name, $object){
30 3
		$this->objects[$name] = $object;
31 3
		$_SESSION[$name] = serialize($object);
32 3
	}
33
34 4
	public function get($name){
35 4
		if (isset($this->objects[$name])){
36 3
			return $this->objects[$name];
37 1
		} else if (isset($_SESSION[$name])){
38
			$this->objects[$name] = unserialize($_SESSION[$name]);
39
			return $this->objects[$name];
40
		}
41 1
		return null;
42
	}
43
44
	public function clear($name){
45
		unset($this->objects[$name]);
46
		unset($_SESSION[$name]);
47
	}
48
49
	public function clearAll(){
50
		foreach ($this->objects as $name=>$value){
51
			$this->clear($name);
52
		}
53
	}
54
}
55