Records::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
c 0
b 0
f 0
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Xsolve\SalesforceClient\QueryBuilder;
4
5
/**
6
 * @todo if the executor was injected to query builder this might have iterated over the next results itself, check if this makes sense
7
 */
8
class Records implements \IteratorAggregate, \Countable
9
{
10
    /**
11
     * @var array
12
     */
13
    private $raw;
14
15 2
    public function __construct(array $raw)
16
    {
17 2
        $this->raw = $raw;
18 2
    }
19
20 2
    public function getIterator(): \Traversable
21
    {
22 2
        return new \ArrayIterator($this->raw['records']);
23
    }
24
25 2
    public function count(): int
26
    {
27 2
        return count($this->raw['records']);
28
    }
29
30 2
    public function hasNext(): bool
31
    {
32 2
        return isset($this->raw['nextRecordsUrl']);
33
    }
34
35 2
    public function getNextIdentifier(): string
36
    {
37 2
        if (!$this->hasNext()) {
38
            throw new \LogicException('Result has no next page');
39
        }
40
41 2
        $uriParts = explode('/', $this->raw['nextRecordsUrl']);
42
43 2
        return end($uriParts);
44
    }
45
46 2
    public function getTotalSize(): int
47
    {
48 2
        return $this->raw['totalSize'];
49
    }
50
}
51