Completed
Push — master ( 96adce...435a1a )
by Rudie
02:06
created

BehatVariablesDatabase::instance()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 2
eloc 4
nc 2
nop 0
1
<?php
2
3
namespace rdx\behatvars;
4
5
class BehatVariablesDatabase {
6
7
	static protected $instance;
8
9
	protected $storage = array();
10
11
	/**
12
	 *
13
	 */
14
	public function _get($name) {
15
		if (!isset($this->storage[$name])) {
16
			throw new \Exception("'$name' does not exist.");
17
		}
18
19
		return $this->storage[$name];
20
	}
21
22
	/**
23
	 *
24
	 */
25
	public function _set($name, $value) {
26
		if (!is_scalar($value)) {
27
			$type = gettype($value);
28
			throw new \Exception("Storing value must be scalar, but it's a '$type'.");
29
		}
30
31
		$this->storage[$name] = $value;
32
	}
33
34
	/**
35
	 *
36
	 */
37
	public function _all() {
38
		return $this->storage;
39
	}
40
41
	/**
42
	 *
43
	 */
44
	public function _clear() {
45
		$this->storage = array();
46
	}
47
48
	/**
49
	 *
50
	 */
51
	static public function instance() {
0 ignored issues
show
Coding Style introduced by
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
52
		if (!self::$instance) {
53
			self::$instance = new static;
54
		}
55
56
		return self::$instance;
57
	}
58
59
	/**
60
	 *
61
	 */
62
	static public function __callStatic($method, $args) {
0 ignored issues
show
Coding Style introduced by
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
63
		$instance = static::instance();
64
		return call_user_func_array(array($instance, '_' . $method), $args);
65
	}
66
67
}
68