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

AbstractKeyAwareOperation   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
eloc 10
c 0
b 0
f 0
dl 0
loc 42
rs 10
ccs 11
cts 11
cp 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A toArray() 0 6 1
A setKey() 0 4 1
A __construct() 0 4 1
1
<?php
2
3
namespace Guillermoandrae\DynamoDb\Contract;
4
5
use Aws\DynamoDb\DynamoDbClient;
6
use Aws\DynamoDb\Marshaler;
7
8
abstract class AbstractKeyAwareOperation extends AbstractItemOperation
9
{
10
    /**
11
     * @var array The primary key values to be used when retrieving items.
12
     */
13
    protected $key;
14
    
15
    /**
16
     * Registers the DynamoDb client, Marshaler, table name, and primary key with this object.
17
     *
18
     * @param DynamoDbClient $client The DynamoDb client.
19
     * @param Marshaler $marshaler The Marshaler.
20
     * @param string $tableName The table name.
21
     * @param array $key The primary key values to be used when retrieving items.
22
     */
23 4
    public function __construct(DynamoDbClient $client, Marshaler $marshaler, string $tableName, array $key)
24
    {
25 4
        parent::__construct($client, $marshaler, $tableName);
26 4
        $this->setKey($key);
27 4
    }
28
29
    /**
30
     * Registers the operation's primary key with this object.
31
     *
32
     * @param array $key The primary key values to be used when retrieving items.
33
     * @return AbstractKeyAwareOperation An implementation of this abstract.
34
     */
35 4
    public function setKey(array $key): AbstractKeyAwareOperation
36
    {
37 4
        $this->key = $this->marshaler->marshalItem($key);
38 4
        return $this;
39
    }
40
41
    /**
42
     * {@inheritDoc}
43
     */
44 4
    public function toArray(): array
45
    {
46
        return [
47 4
            'TableName' => $this->tableName,
48 4
            'ReturnConsumedCapacity' => $this->returnConsumedCapacity,
49 4
            'Key' => $this->key
50
        ];
51
    }
52
}
53