ListTablesOperation   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 7
eloc 17
c 3
b 0
f 0
dl 0
loc 52
ccs 18
cts 18
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 4 1
A setLastEvaluatedTableName() 0 4 1
A __construct() 0 4 1
A toArray() 0 11 4
1
<?php
2
3
namespace Guillermoandrae\DynamoDb\Operation;
4
5
use Aws\DynamoDb\DynamoDbClient;
6
use Aws\DynamoDb\Marshaler;
7
use Guillermoandrae\DynamoDb\Contract\AbstractTableOperation;
8
use Guillermoandrae\DynamoDb\Contract\LimitAwareOperationTrait;
9
10
/**
11
 * ListTables operation.
12
 *
13
 * @author Guillermo A. Fisher <[email protected]>
14
 * @link https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-dynamodb-2012-08-10.html#listtables
15
 */
16
final class ListTablesOperation extends AbstractTableOperation
17
{
18
    use LimitAwareOperationTrait {
19
        LimitAwareOperationTrait::toArray as limitAwareTraitToArray;
20
    }
21
22
    /**
23
     * @var string The name of the last table in the current page of results.
24
     */
25
    private string $lastEvaluatedTableName = '';
26
27
    /**
28
     * Registers the DynamoDb client and Marshaler with this object.
29
     *
30
     * @param DynamoDbClient $client The DynamoDb client.
31
     * @param Marshaler $marshaler The Marshaler.
32
     */
33 38
    public function __construct(DynamoDbClient $client, Marshaler $marshaler)
34
    {
35 38
        $this->setClient($client);
36 38
        $this->setMarshaler($marshaler);
37 38
    }
38
39
    /**
40
     * Registers the name of table to be used as the last in the current page of results.
41
     *
42
     * @param string $lastEvaluatedTableName The name of the last table in the current page of results.
43
     * @return ListTablesOperation This object.
44
     */
45 1
    public function setLastEvaluatedTableName(string $lastEvaluatedTableName): ListTablesOperation
46
    {
47 1
        $this->lastEvaluatedTableName = $lastEvaluatedTableName;
48 1
        return $this;
49
    }
50
51 36
    public function execute(): ?array
52
    {
53 36
        $tables = $this->client->listTables($this->toArray());
54 36
        return $tables['TableNames'];
55
    }
56
57 38
    public function toArray(): array
58
    {
59 38
        $operation = parent::toArray();
60 38
        unset($operation['TableName']);
61 38
        if ($this->lastEvaluatedTableName) {
62 1
            $operation['LastEvaluatedTableName'] = $this->lastEvaluatedTableName;
63
        }
64 38
        if ($this->offset || $this->limit) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->limit of type integer|null is loosely compared to true; this is ambiguous if the integer can be 0. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
65 1
            $operation += $this->limitAwareTraitToArray();
66
        }
67 38
        return $operation;
68
    }
69
}
70