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

ListTablesOperation   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Test Coverage

Coverage 86.67%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 16
c 1
b 0
f 0
dl 0
loc 47
rs 10
ccs 13
cts 15
cp 0.8667

3 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 7 2
A setLastEvaluatedTableName() 0 4 1
A toArray() 0 10 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