Extract   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 36
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A current() 0 3 1
A from() 0 10 2
A __construct() 0 3 1
A these() 0 3 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Stratadox\TableLoader\Loader;
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
 * This class is a composition of zero or more implementations of its own
13
 * interface. It Makes Objects by delegating the work to each of its
14
 * subcontractors, merging their work into one final result.
15
 *
16
 * @author Stratadox
17
 */
18
final class Extract extends ImmutableCollection implements MakesObjects
19
{
20
    private function __construct(MakesObjects ...$objects)
21
    {
22
        parent::__construct(...$objects);
23
    }
24
25
    /**
26
     * Makes a new object extractor that composes more object extractors.
27
     *
28
     * @param MakesObjects ...$objects The other object extractors.
29
     *
30
     * @return MakesObjects            The composed extractor.
31
     */
32
    public static function these(MakesObjects ...$objects): MakesObjects
33
    {
34
        return new self(...$objects);
35
    }
36
37
    /** @inheritdoc */
38
    public function current(): MakesObjects
39
    {
40
        return parent::current();
41
    }
42
43
    /** @inheritdoc */
44
    public function from(array $input, Map $map): ContainsResultingObjects
45
    {
46
        $result = Result::fromArray([], $map);
47
        foreach ($this as $objects) {
48
            $result = $result->mergeWith($objects->from(
49
                $input,
50
                $result->identityMap()
51
            ));
52
        }
53
        return $result;
54
    }
55
}
56