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

ListTablesOperation::execute()   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 2
Bugs 0 Features 0
Metric Value
eloc 2
c 2
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
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