Completed
Push — master ( a7a349...3fc402 )
by Guillermo A.
03:23
created

ScanOperation::execute()   A

Complexity

Conditions 3
Paths 9

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 11
rs 10
ccs 8
cts 8
cp 1
cc 3
nc 9
nop 0
crap 3
1
<?php
2
3
namespace Guillermoandrae\DynamoDb\Operation;
4
5
use Aws\DynamoDb\Exception\DynamoDbException;
6
use Guillermoandrae\Common\Collection;
7
use Guillermoandrae\Common\CollectionInterface;
8
use Guillermoandrae\DynamoDb\Contract\AbstractSearchOperation;
9
use Guillermoandrae\DynamoDb\Exception;
10
11
final class ScanOperation extends AbstractSearchOperation
12
{
13
    /**
14
     * {@inheritDoc}
15
     * @link https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-dynamodb-2012-08-10.html#scan
16
     */
17 3
    public function execute(): CollectionInterface
18
    {
19
        try {
20 3
            $results = $this->client->scan($this->toArray());
21 2
            $rows = [];
22 2
            foreach ($results['Items'] as $item) {
23 1
                $rows[] = $this->marshaler->unmarshalItem($item);
24
            }
25 2
            return Collection::make($rows);
26 1
        } catch (DynamoDbException $ex) {
27 1
            throw new Exception($ex->getMessage());
28
        }
29
    }
30
}
31