Algolia   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 65
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0
wmc 7

5 Methods

Rating   Name   Duplication   Size   Complexity  
A index() 0 5 2
A __construct() 0 3 1
A analytics() 0 3 1
A client() 0 3 1
A searchKey() 0 5 2
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * This file is part of Scout Extended.
7
 *
8
 * (c) Algolia Team <[email protected]>
9
 *
10
 *  For the full copyright and license information, please view the LICENSE
11
 *  file that was distributed with this source code.
12
 */
13
14
namespace Algolia\ScoutExtended;
15
16
use Algolia\AlgoliaSearch\AnalyticsClient;
17
use Algolia\AlgoliaSearch\SearchClient;
18
use Algolia\AlgoliaSearch\SearchIndex;
19
use Algolia\ScoutExtended\Repositories\ApiKeysRepository;
20
use Illuminate\Contracts\Container\Container;
21
use function is_string;
22
23
final class Algolia
24
{
25
    /**
26
     * @var \Illuminate\Contracts\Container\Container
27
     */
28
    private $container;
29
30
    /**
31
     * Algolia constructor.
32
     *
33
     * @param \Illuminate\Contracts\Container\Container $container
34
     *
35
     * @return void
36
     */
37 23
    public function __construct(Container $container)
38
    {
39 23
        $this->container = $container;
40 23
    }
41
42
    /**
43
     * Get a index instance.
44
     *
45
     * @param  string|object $searchable
46
     *
47
     * @return \Algolia\AlgoliaSearch\SearchIndex
48
     */
49 15
    public function index($searchable): SearchIndex
50
    {
51 15
        $searchable = is_string($searchable) ? new $searchable : $searchable;
52
53 15
        return $this->client()->initIndex($searchable->searchableAs());
54
    }
55
56
    /**
57
     * Get a client instance.
58
     *
59
     * @return \Algolia\AlgoliaSearch\SearchClient
60
     */
61 16
    public function client(): SearchClient
62
    {
63 16
        return $this->container->get('algolia.client');
64
    }
65
66
    /**
67
     * Get a analytics instance.
68
     *
69
     * @return \Algolia\AlgoliaSearch\AnalyticsClient
70
     */
71 1
    public function analytics(): AnalyticsClient
72
    {
73 1
        return $this->container->get('algolia.analytics');
74
    }
75
76
    /**
77
     * Get a search key for the given searchable.
78
     *
79
     * @param  string|object $searchable
80
     *
81
     * @return string
82
     */
83 3
    public function searchKey($searchable): string
84
    {
85 3
        $searchable = is_string($searchable) ? new $searchable : $searchable;
86
87 3
        return $this->container->make(ApiKeysRepository::class)->getSearchKey($searchable);
88
    }
89
}
90