AsArray   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 0
dl 0
loc 29
ccs 0
cts 20
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A offsetExists() 0 9 2
A offsetGet() 0 4 1
A offsetSet() 0 4 1
A offsetUnset() 0 4 1
1
<?php
2
3
/**
4
 * This software package is licensed under AGPL or Commercial license.
5
 *
6
 * @package maslosoft/mangan
7
 * @licence AGPL or Commercial
8
 * @copyright Copyright (c) Piotr Masełkowski <[email protected]>
9
 * @copyright Copyright (c) Maslosoft
10
 * @copyright Copyright (c) Others as mentioned in code
11
 * @link https://maslosoft.com/mangan/
12
 */
13
14
namespace Maslosoft\Mangan\Traits\Access;
15
16
use ArrayAccess;
17
use Maslosoft\Addendum\Collections\Meta;
18
19
/**
20
 * This trait is intented to stub interface ArrayAccess
21
 * @see ArrayAccess
22
 * @property Meta $meta Metadata of document
23
 * @author Piotr Maselkowski <pmaselkowski at gmail.com>
24
 */
25
trait AsArray
26
{
27
28
	public function offsetExists($offset)
29
	{
30
		// Allow only hash access
31
		if (!is_numeric($offset))
32
		{
33
			return (bool) $this->meta->$offset;
34
		}
35
		return false;
36
	}
37
38
	public function offsetGet($offset)
39
	{
40
		return $this->$offset;
41
	}
42
43
	public function offsetSet($offset, $value)
44
	{
45
		$this->$offset = $value;
46
	}
47
48
	public function offsetUnset($offset)
49
	{
50
		$this->$offset = $this->meta->$offset->default;
51
	}
52
53
}
54