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

DynamoDbCollection   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 12
c 1
b 0
f 0
dl 0
loc 31
ccs 0
cts 13
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 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