| Total Complexity | 6 |
| Total Lines | 64 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 8 | class DataBag |
||
| 9 | { |
||
| 10 | /** |
||
| 11 | * @var array |
||
| 12 | */ |
||
| 13 | protected $aData = []; |
||
| 14 | |||
| 15 | /** |
||
| 16 | * @var bool |
||
| 17 | */ |
||
| 18 | protected $bTouched = false; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * The constructor |
||
| 22 | * |
||
| 23 | * @param array $aData |
||
| 24 | */ |
||
| 25 | public function __construct(array $aData) |
||
| 26 | { |
||
| 27 | // Ensure all contents are arrays. |
||
| 28 | $this->aData = array_map(function($aValue) { |
||
| 29 | return is_array($aValue) ? $aValue : []; |
||
| 30 | }, $aData); |
||
| 31 | } |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @return bool |
||
| 35 | */ |
||
| 36 | public function touched(): bool |
||
| 37 | { |
||
| 38 | return $this->bTouched; |
||
| 39 | } |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @return array |
||
| 43 | */ |
||
| 44 | public function getAll(): array |
||
| 45 | { |
||
| 46 | return $this->aData; |
||
| 47 | } |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @param string $sBag |
||
| 51 | * @param string $sKey |
||
| 52 | * @param mixed $xValue |
||
| 53 | * |
||
| 54 | * @return void |
||
| 55 | */ |
||
| 56 | public function set(string $sBag, string $sKey, $xValue) |
||
| 57 | { |
||
| 58 | $this->bTouched = true; |
||
| 59 | $this->aData[$sBag][$sKey] = $xValue; |
||
| 60 | } |
||
| 61 | |||
| 62 | /** |
||
| 63 | * @param string $sBag |
||
| 64 | * @param string $sKey |
||
| 65 | * @param mixed $xValue |
||
| 66 | * |
||
| 67 | * @return mixed |
||
| 68 | */ |
||
| 69 | public function get(string $sBag, string $sKey, $xValue = null) |
||
| 72 | } |
||
| 73 | } |
||
| 74 |