AbstractItemOperation   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
eloc 18
c 0
b 0
f 0
dl 0
loc 43
ccs 14
cts 14
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A toArray() 0 7 1
A __construct() 0 5 1
A setPrimaryKey() 0 4 1
1
<?php
2
3
namespace Guillermoandrae\DynamoDb\Contract;
4
5
use Aws\DynamoDb\DynamoDbClient;
6
use Aws\DynamoDb\Marshaler;
7
8
/**
9
 * Abstract for item operations.
10
 *
11
 * @author Guillermo A. Fisher <[email protected]>
12
 */
13
abstract class AbstractItemOperation extends AbstractOperation implements ItemOperationInterface
14
{
15
    use TableAwareOperationTrait,
16
        ExpressionAttributeValueAwareOperationTrait,
17
        ReturnConsumedCapacityAwareOperationTrait {
18
        TableAwareOperationTrait::toArray as tableAwareTraitToArray;
19
        ExpressionAttributeValueAwareOperationTrait::toArray as expressionAwareTraitToArray;
20
        ReturnConsumedCapacityAwareOperationTrait::toArray as returnConsumedCapacityAwareTraitToArray;
21
    }
22
23
    /**
24
     * @var array The primary key.
25
     */
26
    protected array $primaryKey = [];
27
28
    /**
29
     * Registers the DynamoDb client, Marshaler, table name, and primary key with this object.
30
     *
31
     * @param DynamoDbClient $client The DynamoDb client.
32
     * @param Marshaler $marshaler The Marshaler.
33
     * @param string $tableName The table name.
34
     * @param array $primaryKey The primary key.
35
     */
36 7
    public function __construct(DynamoDbClient $client, Marshaler $marshaler, string $tableName, array $primaryKey)
37
    {
38 7
        parent::__construct($client, $marshaler);
39 7
        $this->setTableName($tableName);
40 7
        $this->setPrimaryKey($primaryKey);
41 7
    }
42
43 7
    final public function setPrimaryKey(array $primaryKey): ItemOperationInterface
44
    {
45 7
        $this->primaryKey = $this->getMarshaler()->marshalItem($primaryKey);
46 7
        return $this;
47
    }
48
49 12
    public function toArray(): array
50
    {
51 12
        $operation = $this->tableAwareTraitToArray();
52 12
        $operation += $this->returnConsumedCapacityAwareTraitToArray();
53 12
        $operation += $this->expressionAwareTraitToArray();
54 12
        $operation['Key'] = $this->primaryKey;
55 12
        return $operation;
56
    }
57
}
58