Completed
Pull Request — master (#212)
by Alexandru
43:58 queued 01:14
created

DynamoDbCollection   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A lastKey() 0 17 4
1
<?php
2
3
namespace Rennokki\DynamoDb;
4
5
use Illuminate\Database\Eloquent\Collection;
6
use Rennokki\DynamoDb\ConditionAnalyzer\Index;
7
8
class DynamoDbCollection extends Collection
9
{
10
    /**
11
     * @var \Rennokki\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;
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