ArrayResult   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
dl 0
loc 29
ccs 11
cts 11
cp 1
rs 10
c 1
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A count() 0 3 1
A take() 0 7 1
A __construct() 0 3 1
A getIterator() 0 3 1
1
<?php
2
3
namespace Zenstruck\Porpaginas\Arrays;
4
5
use Zenstruck\Porpaginas\Page;
6
use Zenstruck\Porpaginas\Result;
7
use Zenstruck\Porpaginas\ResultPaginator;
8
9
final class ArrayResult implements Result
10
{
11
    use ResultPaginator;
12
13
    private array $data;
14
15 33
    public function __construct(array $data)
16
    {
17 33
        $this->data = $data;
18 33
    }
19
20 22
    public function take(int $offset, int $limit): Page
21
    {
22 22
        return new ArrayPage(
23 22
            \array_slice($this->data, $offset, $limit),
24
            $offset,
25
            $limit,
26 22
            \count($this->data)
27
        );
28
    }
29
30 17
    public function count(): int
31
    {
32 17
        return \count($this->data);
33
    }
34
35 11
    public function getIterator(): \Traversable
36
    {
37 11
        return new \ArrayIterator($this->data);
38
    }
39
}
40