Completed
Push β€” master ( 8fed1f...e9fa87 )
by hook
02:13
created

Collection::offsetSet()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: hooklife
5
 * Date: 2018/12/5
6
 * Time: δΈ‹εˆ4:59
7
 */
8
9
namespace Hoooklife\DynamodbPodm;
10
11
12
use Aws\DynamoDb\Marshaler;
13
use Aws\Result;
14
15
class Collection implements \ArrayAccess
16
{
17
    /** @var Result $data */
18
    private $data;
19
    private $marshaler;
20
21
    public function __construct($data)
22
    {
23
        $this->data = $data;
24
25
    }
26
27
    public function __get($var)
28
    {
29
        var_dump(1);
0 ignored issues
show
Security Debugging Code introduced by
var_dump(1) looks like debug code. Are you sure you do not want to remove it?
Loading history...
30
        die;
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
31
    }
32
33
    private function getMarshaler()
34
    {
35
        if (!$this->marshaler) {
36
            $this->marshaler = new Marshaler();
37
        }
38
        return $this->marshaler;
39
40
    }
41
42
43
    public function offsetExists($offset)
44
    {
45
        return isset($this->data[$offset]);
46
    }
47
48
49
    public function offsetGet($offset)
50
    {
51
        if (isset($this->data[$offset])) {
52
            return $this->getMarshaler()->unmarshalItem($this->data[$offset]);
53
        }
54
        return null;
55
    }
56
57
58
    public function offsetSet($offset, $value)
59
    {
60
        $this->data[$offset] = $value;
61
    }
62
63
64
    public function offsetUnset($offset)
65
    {
66
        unset($this->data[$offset]);
67
    }
68
69
    public function toArray()
70
    {
71
72
        $result = [];
73
        foreach ($this->data["Items"] as $item) {
74
            $result[] = $this->getMarshaler()->unmarshalItem($item);
75
        }
76
        return $result;
77
    }
78
79
    public function first()
80
    {
81
        $item = reset($this->data["Items"]);
0 ignored issues
show
Bug introduced by
It seems like $this->data['Items'] can also be of type null; however, parameter $array of reset() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

81
        $item = reset(/** @scrutinizer ignore-type */ $this->data["Items"]);
Loading history...
82
        return $this->getMarshaler()->unmarshalItem($item);
83
    }
84
}