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

HighlightEndpoint   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 6
c 0
b 0
f 0
lcom 1
cbo 2
dl 0
loc 58
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\SearchEndpoint;
15
16
use ONGR\ElasticsearchDSL\BuilderInterface;
17
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
18
19
class HighlightEndpoint extends AbstractSearchEndpoint
20
{
21
    public const NAME = 'highlight';
22
23
    private ?BuilderInterface $highlight = null;
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 '?', expecting T_FUNCTION or T_CONST
Loading history...
24
25
    private ?string $key = null;
26
27
    public function normalize(NormalizerInterface $normalizer, string $format = null, array $context = [])
28
    {
29
        if ($this->highlight) {
30
            return $this->highlight->toArray();
31
        }
32
33
        return null;
34
    }
35
36
    public function add(BuilderInterface $builder, ?string $key = null): ?string
37
    {
38
        if ($this->highlight) {
39
            throw new \OverflowException('Only one highlight can be set');
40
        }
41
42
        $this->key = $key;
43
        $this->highlight = $builder;
44
45
        return $key;
46
    }
47
48
    public function getAll(?string $boolType = null): array
49
    {
50
        return [$this->key => $this->highlight];
51
    }
52
53
    public function getHighlight(): ?BuilderInterface
54
    {
55
        return $this->highlight;
56
    }
57
}
58