Completed
Push — master ( ee9403...effd37 )
by Guillermo A.
02:12
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 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