FactoryResult::getIterator()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 2
nc 2
nop 0
dl 0
loc 4
rs 10
c 1
b 0
f 1
ccs 3
cts 3
cp 1
crap 2
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