Completed
Push — master ( af77e8...7d9d07 )
by Zack
11s
created

Settings   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 45
ccs 7
cts 7
cp 1
rs 10
c 1
b 0
f 0
wmc 4
lcom 1
cbo 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A set() 0 3 1
A get() 0 3 2
A all() 0 3 1
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 12 and the first side effect is on line 6.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
namespace GV;
3
4
/** If this file is called directly, abort. */
5
if ( ! defined( 'GRAVITYVIEW_DIR' ) ) {
6
	die();
7
}
8
9
/**
10
 * A generic Settings base class.
11
 */
12
class Settings {
13
	/**
14
	 * @var array Main storage for key-avlues in this collection.
15
	 */
16
	private $settings = array();
17
18
	/**
19
	 * Set a setting.
20
	 *
21
	 * @param mixed $key The key the value should be added under.
22
	 * @param mixed $value The value to be added to the key.
23
	 *
24
	 * @api
25
	 * @since future
26
	 * @return void
27
	 */
28 3
	public function set( $key, $value ) {
29 3
		$this->settings[$key] = $value;
0 ignored issues
show
introduced by
Array keys should be surrounded by spaces unless they contain a string or an integer.
Loading history...
30 3
	}
31
32
	/**
33
	 * Set an setting.
34
	 *
35
	 * @param mixed $key The key in this setting to retrieve.
36
	 * @param mixed $default A default in case the key is not set. 
37
	 *
38
	 * @api
39
	 * @since future
40
	 * @return mixed|null
41
	 */
42 1
	public function get( $key, $default = null ) {
43 1
		return isset( $this->settings[$key] ) ? $this->settings[$key] : $default;
0 ignored issues
show
introduced by
Array keys should be surrounded by spaces unless they contain a string or an integer.
Loading history...
44
	}
45
46
	/**
47
	 * Returns all the objects in this collection as an an array.
48
	 *
49
	 * @api
50
	 * @since future
51
	 * @return array The objects in this collection.
52
	 */
53 1
	public function all() {
54 1
		return $this->settings;
55
	}
56
}
57