Passed
Push — master ( 1a63d3...1ce1e4 )
by Bao
07:40
created

DynamoDbCollection   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
eloc 12
dl 0
loc 31
c 0
b 0
f 0
ccs 13
cts 13
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A lastKey() 0 17 4
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 90
    public function __construct(array $items = [], Index $conditionIndex = null)
16
    {
17 90
        parent::__construct($items);
18
19 90
        $this->conditionIndex = $conditionIndex;
20 90
    }
21
22 4
    public function lastKey()
23
    {
24 4
        $after = $this->last();
25
26 4
        if (empty($after)) {
27 4
            return null;
28
        }
29
30 4
        $afterKey = $after->getKeys();
31
32 4
        $attributes = $this->conditionIndex ? $this->conditionIndex->columns() : [];
33
34 4
        foreach ($attributes as $attribute) {
35 1
            $afterKey[$attribute] = $after->getAttribute($attribute);
36
        }
37
38 4
        return $afterKey;
39
    }
40
}
41