FactoryResult::take()   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 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 3
rs 10
c 1
b 0
f 1
ccs 2
cts 2
cp 1
crap 1
1
<?php
2
3
namespace Zenstruck\Porpaginas\Factory;
4
5
use Zenstruck\Porpaginas\Page;
6
use Zenstruck\Porpaginas\Result;
7
use Zenstruck\Porpaginas\ResultPaginator;
8
9
/**
10
 * @author Kevin Bond <[email protected]>
11
 */
12
final class FactoryResult implements Result
13
{
14
    use ResultPaginator;
15
16
    private $factory;
17
    private Result $result;
18
19 46
    public function __construct(callable $factory, Result $result)
20
    {
21 46
        $this->factory = $factory;
22 46
        $this->result = $result;
23 46
    }
24
25 8
    public function take(int $offset, int $limit): Page
26
    {
27 8
        return new FactoryPage($this->factory, $this->result->take($offset, $limit));
28
    }
29
30 35
    public function count(): int
31
    {
32 35
        return $this->result->count();
33
    }
34
35 35
    public function getIterator(): \Traversable
36
    {
37 35
        foreach ($this->result as $result) {
38 34
            yield \call_user_func($this->factory, $result);
39
        }
40 35
    }
41
}
42