Passed
Pull Request — master (#1999)
by Antoine
02:58
created

DocumentMetadata   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getType() 0 3 1
A getIndex() 0 3 1
A withIndex() 0 6 1
A withType() 0 6 1
1
<?php
2
3
/*
4
 * This file is part of the API Platform project.
5
 *
6
 * (c) Kévin Dunglas <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace ApiPlatform\Core\Bridge\Elasticsearch\Metadata;
15
16
/**
17
 * Document metadata.
18
 *
19
 * @see https://www.elastic.co/guide/en/elasticsearch/guide/current/_document_metadata.html
20
 *
21
 * @experimental
22
 *
23
 * @author Baptiste Meyer <[email protected]>
24
 */
25
final class DocumentMetadata
26
{
27
    const DEFAULT_TYPE = '_doc';
28
29
    private $index;
30
    private $type;
31
32
    public function __construct(string $index = null, string $type = self::DEFAULT_TYPE)
33
    {
34
        $this->index = $index;
35
        $this->type = $type;
36
    }
37
38
    /**
39
     * Gets a new instance with the given index.
40
     */
41
    public function withIndex(string $index): self
42
    {
43
        $metadata = clone $this;
44
        $metadata->index = $index;
45
46
        return $metadata;
47
    }
48
49
    /**
50
     * Gets the document index.
51
     */
52
    public function getIndex()
53
    {
54
        return $this->index;
55
    }
56
57
    /**
58
     * Gets a new instance with the given type.
59
     */
60
    public function withType(string $type): self
61
    {
62
        $metadata = clone $this;
63
        $metadata->type = $type;
64
65
        return $metadata;
66
    }
67
68
    /**
69
     * Gets the document type.
70
     */
71
    public function getType(): string
72
    {
73
        return $this->type;
74
    }
75
}
76