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

ListTablesOperation::toArray()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 10
rs 10
ccs 7
cts 7
cp 1
cc 3
nc 4
nop 0
crap 3
1
<?php
2
3
namespace Guillermoandrae\DynamoDb\Operation;
4
5
use Aws\DynamoDb\Exception\DynamoDbException;
6
use Guillermoandrae\DynamoDb\Contract\AbstractOperation;
7
use Guillermoandrae\DynamoDb\Contract\LimitAwareOperationTrait;
8
use Guillermoandrae\DynamoDb\Exception;
9
10
final class ListTablesOperation extends AbstractOperation
11
{
12
    use LimitAwareOperationTrait;
13
14
    /**
15
     * @var string The name of the last table in the current page of results.
16
     */
17
    protected $lastEvaluatedTableName;
18
19
    /**
20
     * Registers the name of table to be used as the last in the current page of results.
21
     *
22
     * @param string $lastEvaluatedTableName The name of the last table in the current page of results.
23
     * @return ListTablesOperation This object.
24
     */
25 1
    public function setLastEvaluatedTableName(string $lastEvaluatedTableName): ListTablesOperation
26
    {
27 1
        $this->lastEvaluatedTableName = $lastEvaluatedTableName;
28 1
        return $this;
29
    }
30
31
    /**
32
     * {@inheritDoc}
33
     */
34 19
    public function toArray(): array
35
    {
36 19
        $query = [];
37 19
        if ($this->lastEvaluatedTableName) {
38 1
            $query['LastEvaluatedTableName'] = $this->lastEvaluatedTableName;
39
        }
40 19
        if ($this->limit) {
41 1
            $query['Limit'] = $this->limit;
42
        }
43 19
        return $query;
44
    }
45
46
    /**
47
     * {@inheritDoc}
48
     * @link https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-dynamodb-2012-08-10.html#listtables
49
     */
50 17
    public function execute(): ?array
51
    {
52
        try {
53 17
            $tables = $this->client->listTables($this->toArray());
54 17
            return $tables['TableNames'];
55
        } catch (DynamoDbException $ex) {
56
            throw new Exception($ex->getMessage());
57
        }
58
    }
59
}
60