Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
42.86% |
3 / 7 |
CRAP | |
61.54% |
8 / 13 |
Parameters | |
0.00% |
0 / 1 |
|
42.86% |
3 / 7 |
17.88 | |
61.54% |
8 / 13 |
__construct(array $parameters = array()) | |
100.00% |
1 / 1 |
1 | |
100.00% |
2 / 2 |
|||
get($key, $default = null) | |
100.00% |
1 / 1 |
3 | |
100.00% |
3 / 3 |
|||
set($key, $value) | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
has($key) | |
100.00% |
1 / 1 |
3 | |
100.00% |
3 / 3 |
|||
getKeys() | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
toArray() | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
clear() | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
<?php | |
namespace Environaut\Config; | |
/** | |
* Class that wraps an associative array for | |
* more convenient access of keys and values. | |
*/ | |
class Parameters | |
{ | |
/** | |
* @var array | |
*/ | |
protected $parameters = array(); | |
/** | |
* Create a new instance with the given parameters as | |
* initial value set. | |
* | |
* @param array $parameters | |
*/ | |
public function __construct(array $parameters = array()) | |
{ | |
$this->parameters = $parameters; | |
} | |
/** | |
* Returns the value for the given key. | |
* | |
* @param string $key name of key | |
* @param mixed $default value to return if key doesn't exist | |
* | |
* @return mixed value for that key or default given | |
*/ | |
public function get($key, $default = null) | |
{ | |
if (isset($this->parameters[$key]) || array_key_exists($key, $this->parameters)) { | |
return $this->parameters[$key]; | |
} | |
return $default; | |
} | |
/** | |
* Sets a given value for the specified key. | |
* | |
* @param string $key name of entry | |
* @param mixed $value value to set for the given key | |
* | |
* @return mixed the value set | |
*/ | |
public function set($key, $value) | |
{ | |
return $this->parameters[$key] = $value; | |
} | |
/** | |
* Returns whether the key exists or not. | |
* | |
* @param string $key name of key to check | |
* | |
* @return bool true, if key exists; false otherwise | |
*/ | |
public function has($key) | |
{ | |
if (isset($this->parameters[$key]) || array_key_exists($key, $this->parameters)) { | |
return true; | |
} | |
return false; | |
} | |
/** | |
* Returns all first level key names. | |
* | |
* @return array of keys | |
*/ | |
public function getKeys() | |
{ | |
return array_keys($this->parameters); | |
} | |
/** | |
* Returns the data as an associative array. | |
* | |
* @return array with all data | |
*/ | |
public function toArray() | |
{ | |
return $this->parameters; | |
} | |
/** | |
* Delete all key/value pairs. | |
*/ | |
public function clear() | |
{ | |
$this->parameters = array(); | |
} | |
} |