RawDynamoDbQuery::internal()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Hoooklife\DynamodbPodm\DynamoDB;
4
5
/**
6
 * Class RawDynamoDbQuery
7
 *
8
 * @package BaoPham\DynamoDb
9
 */
10
class RawDynamoDbQuery implements \IteratorAggregate, \ArrayAccess, \Countable
11
{
12
    /**
13
     * 'Scan', 'Query', etc.
14
     *
15
     * @var string
16
     */
17
    public $op;
18
19
    /**
20
     * The query body being sent to AWS
21
     *
22
     * @var array
23
     */
24
    public $query;
25
26
    public function __construct($op, $query)
27
    {
28
        $this->op = $op;
29
        $this->query = $query;
30
    }
31
32
    /**
33
     * Perform any final clean up.
34
     * Remove any empty values to avoid errors.
35
     *
36
     * @return $this
37
     */
38
    public function finalize()
39
    {
40
        $this->query = array_filter($this->query, function ($value) {
41
            return !empty($value) || is_bool($value) || is_numeric($value);
42
        });
43
44
        return $this;
45
    }
46
47
    /**
48
     * Whether a offset exists
49
     * @link http://php.net/manual/en/arrayaccess.offsetexists.php
50
     * @param mixed $offset <p>
51
     * An offset to check for.
52
     * </p>
53
     * @return boolean true on success or false on failure.
54
     * </p>
55
     * <p>
56
     * The return value will be casted to boolean if non-boolean was returned.
57
     * @since 5.0.0
58
     */
59
    public function offsetExists($offset)
60
    {
61
        return isset($this->internal()[$offset]);
62
    }
63
64
    /**
65
     * Offset to retrieve
66
     * @link http://php.net/manual/en/arrayaccess.offsetget.php
67
     * @param mixed $offset <p>
68
     * The offset to retrieve.
69
     * </p>
70
     * @return mixed Can return all value types.
71
     * @since 5.0.0
72
     */
73
    public function offsetGet($offset)
74
    {
75
        return $this->internal()[$offset];
76
    }
77
78
    /**
79
     * Offset to set
80
     * @link http://php.net/manual/en/arrayaccess.offsetset.php
81
     * @param mixed $offset <p>
82
     * The offset to assign the value to.
83
     * </p>
84
     * @param mixed $value <p>
85
     * The value to set.
86
     * </p>
87
     * @return void
88
     * @since 5.0.0
89
     */
90
    public function offsetSet($offset, $value)
91
    {
92
        $this->internal()[$offset] = $value;
93
    }
94
95
    /**
96
     * Offset to unset
97
     * @link http://php.net/manual/en/arrayaccess.offsetunset.php
98
     * @param mixed $offset <p>
99
     * The offset to unset.
100
     * </p>
101
     * @return void
102
     * @since 5.0.0
103
     */
104
    public function offsetUnset($offset)
105
    {
106
        unset($this->internal()[$offset]);
107
    }
108
109
    /**
110
     * Retrieve an external iterator
111
     * @link http://php.net/manual/en/iteratoraggregate.getiterator.php
112
     * @return \Traversable An instance of an object implementing <b>Iterator</b> or
113
     * <b>Traversable</b>
114
     * @since 5.0.0
115
     */
116
    public function getIterator()
117
    {
118
        return new \ArrayObject($this->internal());
119
    }
120
121
    /**
122
     * Count elements of an object
123
     * @link http://php.net/manual/en/countable.count.php
124
     * @return int The custom count as an integer.
125
     * </p>
126
     * <p>
127
     * The return value is cast to an integer.
128
     * @since 5.1.0
129
     */
130
    public function count()
131
    {
132
        return count($this->internal());
133
    }
134
135
    /**
136
     * For backward compatibility, previously we use array to represent the raw query
137
     *
138
     * @var array
139
     */
140
    private function internal()
141
    {
142
        return [$this->op, $this->query];
143
    }
144
}