MassSchemator   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 5
eloc 10
c 1
b 1
f 0
dl 0
loc 39
rs 10

3 Methods

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