Issues (4)

src/DynamoDb/Operation/GetItemOperation.php (2 issues)

1
<?php
2
3
namespace Guillermoandrae\DynamoDb\Operation;
4
5
use Aws\DynamoDb\Exception\DynamoDbException;
6
use Guillermoandrae\DynamoDb\Contract\AbstractItemOperation;
7
use Guillermoandrae\DynamoDb\Factory\ExceptionFactory;
8
9
/**
10
 * GetItem operation.
11
 *
12
 * @author Guillermo A. Fisher <[email protected]>
13
 * @link https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-dynamodb-2012-08-10.html#getitem
14
 */
15
final class GetItemOperation extends AbstractItemOperation
16
{
17 3
    public function execute(): array
18
    {
19
        try {
20 3
            $item = [];
21 3
            $results = $this->client->getItem($this->toArray());
22 2
            if (is_array($results['Item'])) {
23 2
                $item = $this->getMarshaler()->unmarshalItem($results['Item'], false);
0 ignored issues
show
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

23
                $item = $this->getMarshaler()->unmarshalItem(/** @scrutinizer ignore-type */ $results['Item'], false);
Loading history...
24
            }
25 2
            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...
26 1
        } catch (DynamoDbException $ex) {
27 1
            throw ExceptionFactory::factory($ex);
28
        }
29
    }
30
}
31