Completed
Push — master ( a7a349...3fc402 )
by Guillermo A.
03:23
created

AbstractItemOperation::setReturnConsumedCapacity()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

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