Completed
Pull Request — master (#348)
by
unknown
10:14
created

Highlight   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 7
c 0
b 0
f 0
lcom 1
cbo 1
dl 0
loc 71
rs 10
1
<?php
2
3
/*
4
 * This file is part of the ONGR package.
5
 *
6
 * (c) NFQ Technologies UAB <[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 ONGR\ElasticsearchDSL\Highlight;
15
16
use ONGR\ElasticsearchDSL\BuilderInterface;
17
use ONGR\ElasticsearchDSL\ParametersTrait;
18
19
/**
20
 * Data holder for highlight api.
21
 */
22
class Highlight implements BuilderInterface
23
{
24
    use ParametersTrait;
25
26
    private array $fields = [];
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_ARRAY, expecting T_FUNCTION or T_CONST
Loading history...
27
28
    private ?array $tags = null;
29
30
    public function addField(string $name, array $params = []): static
31
    {
32
        $this->fields[$name] = $params;
33
34
        return $this;
35
    }
36
37
    public function setTags(array $preTags, array $postTags): static
38
    {
39
        $this->tags['pre_tags'] = $preTags;
40
        $this->tags['post_tags'] = $postTags;
41
42
        return $this;
43
    }
44
45
    public function getType(): string
46
    {
47
        return 'highlight';
48
    }
49
50
    public function toArray(): array
51
    {
52
        $output = [];
53
54
        if (is_array($this->tags)) {
55
            $output = $this->tags;
56
        }
57
58
        $output = $this->processArray($output);
59
60
        foreach ($this->fields as $field => $params) {
61
            $output['fields'][$field] = count($params) ? $params : new \stdClass();
62
        }
63
64
        return $output;
65
    }
66
}
67