Passed
Push — feature/initial-implementation ( fae671...591f29 )
by Fike
02:37
created

Operations::extend()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 6
nc 1
nop 2
1
<?php
2
3
namespace AmaTeam\ElasticSearch\Entity\Descriptor;
4
5
use AmaTeam\ElasticSearch\API\Entity\Descriptor;
6
use AmaTeam\ElasticSearch\API\Entity\DescriptorInterface;
7
use AmaTeam\ElasticSearch\Indexing\Operations as IndexingOperations;
8
use AmaTeam\ElasticSearch\Entity\Mapping\Structure\MappingOperations;
9
10
class Operations
11
{
12
    public static function from(DescriptorInterface $source): Descriptor
13
    {
14
        $target = new Descriptor(
15
            $source->getName(),
16
            $source->getMapping(),
17
            $source->getIndexing()
18
        );
19
        if ($source->getParentNames() !== null) {
20
            $target->setParentNames($source->getParentNames());
21
        }
22
        $target->setRootLevelDocument($source->isRootLevelDocument());
23
        return $target;
24
    }
25
26
    public static function extend(DescriptorInterface $parent, DescriptorInterface $child): Descriptor
27
    {
28
        $target = static::from($child);
29
        $mapping = MappingOperations::extend($parent->getMapping(), $child->getMapping());
30
        $indexing = IndexingOperations::merge($parent->getIndexing(), $child->getIndexing());
31
        return $target
32
            ->setMapping($mapping)
33
            ->setIndexing($indexing);
34
    }
35
}
36