Passed
Push — master ( 92dc8b...8279be )
by Smoren
01:43
created

MassSchemator::exec()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 10
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 2
1
<?php
2
3
namespace Smoren\Schemator\Components;
4
5
use Smoren\Schemator\Interfaces\SchematorInterface;
6
use Smoren\Schemator\Interfaces\MassSchematorInterface;
7
use Smoren\Schemator\Exceptions\SchematorException;
8
use Generator;
9
10
/**
11
 * Class for mass schematic data converting
12
 * @author Smoren <[email protected]>
13
 */
14
class MassSchemator implements MassSchematorInterface
15
{
16
    /**
17
     * @var SchematorInterface Schemator instance
18
     */
19
    protected SchematorInterface $schemator;
20
21
    /**
22
     * MassSchemator constructor.
23
     * @param SchematorInterface $schemator Schemator instance
24
     */
25
    public function __construct(SchematorInterface $schemator)
26
    {
27
        $this->schemator = $schemator;
28
    }
29
30
    /**
31
     * @inheritDoc
32
     */
33
    public function generate(iterable $source, array $schema): Generator
34
    {
35
        foreach($source as $item) {
36
            yield $this->schemator->convert($item, $schema);
37
        }
38
    }
39
40
    /**
41
     * @inheritDoc
42
     */
43
    public function convert(iterable $source, array $schema): array
44
    {
45
        $gen = $this->generate($source, $schema);
46
        $result = [];
47
48
        foreach($gen as $item) {
49
            $result[] = $item;
50
        }
51
52
        return $result;
53
    }
54
}
55