Completed
Pull Request — master (#128)
by Bao
05:47
created

DynamoDbCollection::lastKey()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 17
ccs 9
cts 9
cp 1
rs 9.7
c 0
b 0
f 0
cc 4
nc 3
nop 0
crap 4
1
<?php
2
3
namespace BaoPham\DynamoDb;
4
5
use Illuminate\Database\Eloquent\Collection;
6
7
class DynamoDbCollection extends Collection
8
{
9
    private $conditionIndexes = null;
10
11 90
    public function __construct(array $items = [], $conditionIndexes = null)
12
    {
13 90
        parent::__construct($items);
14
15 90
        $this->conditionIndexes = $conditionIndexes;
16 90
    }
17
18 4
    public function lastKey()
19
    {
20 4
        $after = $this->last();
21
22 4
        if (empty($after)) {
23 4
            return null;
24
        }
25
26 4
        $afterKey = $after->getKeys();
27
28 4
        $conditionIndexes = $this->conditionIndexes ?: [];
29
30 4
        foreach ($conditionIndexes as $index) {
31 1
            $afterKey[$index] = $after->getAttribute($index);
32
        }
33
34 4
        return $afterKey;
35
    }
36
}
37