Completed
Push — master ( a55d6c...85c19c )
by Jesse
01:53
created

Extract::current()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 0
1
<?php
2
declare(strict_types=1);
3
4
namespace Stratadox\TableLoader;
5
6
use Stratadox\IdentityMap\MapsObjectsByIdentity as Map;
7
use Stratadox\ImmutableCollection\ImmutableCollection;
8
9
/**
10
 * Makes partially hydrated objects from an input array.
11
 *
12
 * @author Stratadox
13
 */
14
final class Extract extends ImmutableCollection implements MakesObjects
15
{
16
    private function __construct(MakesObjects ...$objects)
17
    {
18
        parent::__construct(...$objects);
19
    }
20
21
    /**
22
     * Makes a new object extractor that composes more object extractors.
23
     *
24
     * @param MakesObjects ...$objects The other object extractors.
25
     *
26
     * @return MakesObjects            The composed extractor.
27
     */
28
    public static function these(MakesObjects ...$objects): MakesObjects
29
    {
30
        return new self(...$objects);
31
    }
32
33
    public function current(): MakesObjects
34
    {
35
        return parent::current();
36
    }
37
38
    /** @inheritdoc */
39
    public function from(array $input, Map $map): ContainsResultingObjects
40
    {
41
        $result = Result::fromArray([], $map);
42
        foreach ($this as $objects) {
43
            $result = $result->mergeWith($objects->from(
44
                $input,
45
                $result->identityMap()
46
            ));
47
        }
48
        return $result;
49
    }
50
}
51