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

GetItemOperation::execute()   A

Complexity

Conditions 3
Paths 5

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 5
nop 0
crap 3
1
<?php
2
3
namespace Guillermoandrae\DynamoDb\Operation;
4
5
use Aws\DynamoDb\Exception\DynamoDbException;
6
use Guillermoandrae\DynamoDb\Contract\AbstractKeyAwareOperation;
7
use Guillermoandrae\DynamoDb\Exception;
8
9
final class GetItemOperation extends AbstractKeyAwareOperation
10
{
11
    /**
12
     * {@inheritDoc}
13
     * @link https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-dynamodb-2012-08-10.html#getitem
14
     */
15 2
    public function execute(): array
16
    {
17
        try {
18 2
            $results = $this->client->getItem($this->toArray());
19 1
            $item = [];
20 1
            if (is_array($results['Item'])) {
21 1
                $item = $this->marshaler->unmarshalItem($results['Item']);
0 ignored issues
show
Bug introduced by
It seems like $results['Item'] can also be of type null; however, parameter $data of Aws\DynamoDb\Marshaler::unmarshalItem() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

21
                $item = $this->marshaler->unmarshalItem(/** @scrutinizer ignore-type */ $results['Item']);
Loading history...
22
            }
23 1
            return $item;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $item could return the type stdClass which is incompatible with the type-hinted return array. Consider adding an additional type-check to rule them out.
Loading history...
24 1
        } catch (DynamoDbException $ex) {
25 1
            throw new Exception($ex->getMessage());
26
        }
27
    }
28
}
29