Completed
Push — master ( ee9403...effd37 )
by Guillermo A.
02:12
created

ListTablesOperation   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
eloc 13
c 2
b 0
f 0
dl 0
loc 43
ccs 13
cts 13
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 4 1
A setLastEvaluatedTableName() 0 4 1
A toArray() 0 10 3
1
<?php
2
3
namespace Guillermoandrae\DynamoDb\Operation;
4
5
use Guillermoandrae\DynamoDb\Contract\AbstractOperation;
6
use Guillermoandrae\DynamoDb\Contract\LimitAwareOperationTrait;
7
8
/**
9
 * @link https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-dynamodb-2012-08-10.html#listtables
10
 */
11
final class ListTablesOperation extends AbstractOperation
12
{
13
    use LimitAwareOperationTrait;
14
15
    /**
16
     * @var string The name of the last table in the current page of results.
17
     */
18
    protected $lastEvaluatedTableName;
19
20
    /**
21
     * Registers the name of table to be used as the last in the current page of results.
22
     *
23
     * @param string $lastEvaluatedTableName The name of the last table in the current page of results.
24
     * @return ListTablesOperation This object.
25
     */
26 1
    public function setLastEvaluatedTableName(string $lastEvaluatedTableName): ListTablesOperation
27
    {
28 1
        $this->lastEvaluatedTableName = $lastEvaluatedTableName;
29 1
        return $this;
30
    }
31
32
    /**
33
     * {@inheritDoc}
34
     */
35 19
    public function toArray(): array
36
    {
37 19
        $query = [];
38 19
        if ($this->lastEvaluatedTableName) {
39 1
            $query['LastEvaluatedTableName'] = $this->lastEvaluatedTableName;
40
        }
41 19
        if ($this->limit) {
42 1
            $query['Limit'] = $this->limit;
43
        }
44 19
        return $query;
45
    }
46
47
    /**
48
     * {@inheritDoc}
49
     */
50 17
    public function execute(): ?array
51
    {
52 17
        $tables = $this->client->listTables($this->toArray());
53 17
        return $tables['TableNames'];
54
    }
55
}
56