Completed
Push — master ( 0c808d...cd48f7 )
by Guillermo A.
02:23
created

AbstractSearchOperation   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 9
eloc 30
c 0
b 0
f 0
dl 0
loc 86
ccs 26
cts 26
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setConsistentRead() 0 4 1
A toArray() 0 19 5
A setProjectionExpression() 0 4 1
A setSelect() 0 4 1
A setIndexName() 0 4 1
1
<?php
2
3
namespace Guillermoandrae\DynamoDb\Contract;
4
5
abstract class AbstractSearchOperation extends AbstractOperation implements SearchOperationInterface
6
{
7
    use LimitAwareOperationTrait, FilterExpressionAwareOperationTrait, ReturnConsumedCapacityAwareOperationTrait {
8
        LimitAwareOperationTrait::toArray as limitAwareTraitToArray;
9
        FilterExpressionAwareOperationTrait::toArray as filterExpressionAwareTraitToArray;
10
        ReturnConsumedCapacityAwareOperationTrait::toArray as returnConsumedCapacityAwareTraitToArray;
11
    }
12
13
    /**
14
     * @var boolean Whether or not the read should be consistent.
15
     */
16
    private $consistentRead = false;
17
18
    /**
19
     * @var string The name of a secondary index to request against.
20
     */
21
    private $indexName = '';
22
23
    /**
24
     * @var string The attributes to retrieve from the specified table or index.
25
     */
26
    private $projectionExpression = '';
27
28
    /**
29
     * @var string The attributes to be returned in the result.
30
     */
31
    private $select = '';
32
33
    /**
34
     * {@inheritDoc}
35
     */
36 1
    final public function setConsistentRead(bool $consistentRead): SearchOperationInterface
37
    {
38 1
        $this->consistentRead = $consistentRead;
39 1
        return $this;
40
    }
41
42
    /**
43
     * {@inheritDoc}
44
     */
45 1
    final public function setIndexName(string $indexName): SearchOperationInterface
46
    {
47 1
        $this->indexName = $indexName;
48 1
        return $this;
49
    }
50
51
    /**
52
     * {@inheritDoc}
53
     */
54 1
    final public function setSelect(string $select): SearchOperationInterface
55
    {
56 1
        $this->select = $select;
57 1
        return $this;
58
    }
59
60
    /**
61
     * {@inheritDoc}
62
     */
63 1
    final public function setProjectionExpression(string $projectionExpression): SearchOperationInterface
64
    {
65 1
        $this->projectionExpression = $projectionExpression;
66 1
        return $this;
67
    }
68
69
    /**
70
     * {@inheritDoc}
71
     */
72 19
    public function toArray(): array
73
    {
74 19
        $operation = parent::toArray();
75 19
        if ($this->limit) {
76 1
            $operation += $this->limitAwareTraitToArray();
77
        }
78 19
        $operation += $this->returnConsumedCapacityAwareTraitToArray();
79 19
        $operation += $this->filterExpressionAwareTraitToArray();
80 19
        $operation['ConsistentRead'] = $this->consistentRead;
81 19
        if (!empty($this->indexName)) {
82 1
            $operation['IndexName'] = $this->indexName;
83
        }
84 19
        if (!empty($this->select)) {
85 1
            $operation['Select'] = $this->select;
86
        }
87 19
        if (!empty($this->projectionExpression)) {
88 1
            $operation['ProjectionExpression'] = $this->projectionExpression;
89
        }
90 19
        return $operation;
91
    }
92
}
93