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

DynamoDbCollection::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 1
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