Completed
Push — master ( 19c355...d500cb )
by Guillermo A.
02:33
created

ListTablesOperation::__construct()   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
ccs 3
cts 3
cp 1
rs 10
cc 1
nc 1
nop 2
crap 1
1
<?php
2
3
namespace Guillermoandrae\DynamoDb\Operation;
4
5
use Aws\DynamoDb\DynamoDbClient;
6
use Aws\DynamoDb\Marshaler;
7
use Guillermoandrae\DynamoDb\Contract\AbstractTableOperation;
8
use Guillermoandrae\DynamoDb\Contract\LimitAwareOperationTrait;
9
10
/**
11
 * @link https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-dynamodb-2012-08-10.html#listtables
12
 */
13
final class ListTablesOperation extends AbstractTableOperation
14
{
15
    use LimitAwareOperationTrait {
16
        LimitAwareOperationTrait::toArray as limitAwareTraitToArray;
17
    }
18
19
    /**
20
     * @var string The name of the last table in the current page of results.
21
     */
22
    protected $lastEvaluatedTableName;
23
24
    /**
25
     * Registers the DynamoDb client and Marshaler with this object.
26
     *
27
     * @param DynamoDbClient $client The DynamoDb client.
28
     * @param Marshaler $marshaler The Marshaler.
29
     */
30 26
    public function __construct(DynamoDbClient $client, Marshaler $marshaler)
31
    {
32 26
        $this->setClient($client);
33 26
        $this->setMarshaler($marshaler);
34 26
    }
35
36
    /**
37
     * Registers the name of table to be used as the last in the current page of results.
38
     *
39
     * @param string $lastEvaluatedTableName The name of the last table in the current page of results.
40
     * @return ListTablesOperation This object.
41
     */
42 1
    public function setLastEvaluatedTableName(string $lastEvaluatedTableName): ListTablesOperation
43
    {
44 1
        $this->lastEvaluatedTableName = $lastEvaluatedTableName;
45 1
        return $this;
46
    }
47
48
    /**
49
     * {@inheritDoc}
50
     */
51 24
    public function execute(): ?array
52
    {
53 24
        $tables = $this->client->listTables($this->toArray());
54 24
        return $tables['TableNames'];
55
    }
56
57
    /**
58
     * {@inheritDoc}
59
     */
60 26
    public function toArray(): array
61
    {
62 26
        $query = parent::toArray();
63 26
        unset($query['TableName']);
64 26
        if ($this->lastEvaluatedTableName) {
65 1
            $query['LastEvaluatedTableName'] = $this->lastEvaluatedTableName;
66
        }
67 26
        if ($this->limit) {
68 1
            $query += $this->limitAwareTraitToArray();
69
        }
70 26
        return $query;
71
    }
72
}
73