Passed
Push — master ( ff1a3c...f7850f )
by Smoren
01:51
created

MassSchemator::convert()   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
c 0
b 0
f 0
dl 0
loc 10
rs 10
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->exec($item, $schema);
0 ignored issues
show
Deprecated Code introduced by
The function Smoren\Schemator\Interfa...ematorInterface::exec() has been deprecated: please use convert() method ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

36
            yield /** @scrutinizer ignore-deprecated */ $this->schemator->exec($item, $schema);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
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
    /**
56
     * @inheritDoc
57
     * @deprecated please use convert() method
58
     * @see MassSchematorInterface::convert()
59
     */
60
    public function exec(iterable $source, array $schema): array
61
    {
62
        $gen = $this->generate($source, $schema);
63
        $result = [];
64
65
        foreach($gen as $item) {
66
            $result[] = $item;
67
        }
68
69
        return $result;
70
    }
71
}
72