Completed
Push — master ( 20a668...02e94f )
by Guillermo A.
02:17
created

AbstractItemRequest::get()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 8
c 0
b 0
f 0
ccs 6
cts 6
cp 1
rs 10
cc 2
nc 2
nop 0
crap 2
1
<?php
2
3
namespace Guillermoandrae\DynamoDb;
4
5
abstract class AbstractItemRequest extends AbstractTableAwareRequest
6
{
7
    /**
8
     * @var array Values that can be substituted in an expression.
9
     */
10
    protected $expressionAttributeValues = [];
11
    
12
    /**
13
     * @var string The level of detail about provisioned throughput consumption that is returned in the response.
14
     */
15
    protected $returnConsumedCapacity = ConsumedCapacityOptions::NONE;
16
17
    /**
18
     * Adds an ExpressionAttributeValue to the request.
19
     *
20
     * @param string $key The attribute token.
21
     * @param mixed $value The attribute value.
22
     * @return AbstractItemRequest An implementation of this abstract.
23
     */
24 8
    final public function addExpressionAttributeValue(string $key, $value): AbstractItemRequest
25
    {
26 8
        $this->expressionAttributeValues[sprintf(':%s', $key)] = $this->marshaler->marshalValue($value);
27 8
        return $this;
28
    }
29
30
    /**
31
     * Registers the desired level of consumption detail to return.
32
     *
33
     * @param string $returnConsumedCapacity The level of consumption detail to return.
34
     * @return AbstractItemRequest An implementation of this abstract.
35
     */
36 1
    final public function setReturnConsumedCapacity(string $returnConsumedCapacity): AbstractItemRequest
37
    {
38 1
        $this->returnConsumedCapacity = $returnConsumedCapacity;
39 1
        return $this;
40
    }
41
42
    /**
43
     * {@inheritDoc}
44
     */
45 21
    public function get(): array
46
    {
47 21
        $query = parent::get();
48 21
        if (!empty($this->expressionAttributeValues)) {
49 8
            $query['ExpressionAttributeValues'] = $this->expressionAttributeValues;
50
        }
51 21
        $query['ReturnConsumedCapacity'] = $this->returnConsumedCapacity;
52 21
        return $query;
53
    }
54
}
55