FactoryResult   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getIterator() 0 4 2
A take() 0 3 1
A __construct() 0 4 1
A count() 0 3 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