SearchEndpointFactory   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 2
c 0
b 0
f 0
lcom 1
cbo 0
dl 0
loc 33
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A get() 0 8 2
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
namespace ONGR\ElasticsearchDSL\SearchEndpoint;
13
14
/**
15
 * Factory for search endpoints.
16
 */
17
class SearchEndpointFactory
18
{
19
    /**
20
     * @var array Holds namespaces for endpoints.
21
     */
22
    private static $endpoints = [
23
        'query' => 'ONGR\ElasticsearchDSL\SearchEndpoint\QueryEndpoint',
24
        'post_filter' => 'ONGR\ElasticsearchDSL\SearchEndpoint\PostFilterEndpoint',
25
        'sort' => 'ONGR\ElasticsearchDSL\SearchEndpoint\SortEndpoint',
26
        'highlight' => 'ONGR\ElasticsearchDSL\SearchEndpoint\HighlightEndpoint',
27
        'aggregations' => 'ONGR\ElasticsearchDSL\SearchEndpoint\AggregationsEndpoint',
28
        'suggest' => 'ONGR\ElasticsearchDSL\SearchEndpoint\SuggestEndpoint',
29
        'inner_hits' => 'ONGR\ElasticsearchDSL\SearchEndpoint\InnerHitsEndpoint',
30
    ];
31
32
    /**
33
     * Returns a search endpoint instance.
34
     *
35
     * @param string $type Type of endpoint.
36
     *
37
     * @return SearchEndpointInterface
38
     *
39
     * @throws \RuntimeException Endpoint does not exist.
40
     */
41
    public static function get($type)
42
    {
43
        if (!array_key_exists($type, self::$endpoints)) {
44
            throw new \RuntimeException('Endpoint does not exist.');
45
        }
46
47
        return new self::$endpoints[$type]();
48
    }
49
}
50