Test Failed
Pull Request — master (#272)
by Manabu
06:33
created

DynamoDbCollection::lastKey()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 17
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

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