Test Failed
Push — develop ( 63ed01...7218b8 )
by Nuno
05:28
created

Algolia   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 51
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A index() 0 5 2
A analytics() 0 3 1
A client() 0 3 1
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 function is_string;
17
use Algolia\AlgoliaSearch\Index;
18
use Algolia\AlgoliaSearch\Analytics;
19
use Illuminate\Contracts\Container\Container;
20
use Algolia\AlgoliaSearch\Interfaces\ClientInterface;
21
22
final class Algolia
23
{
24
    /**
25
     * @var \Illuminate\Contracts\Container\Container
26
     */
27
    private $container;
28
29
    /**
30
     * Algolia constructor.
31
     *
32
     * @param \Illuminate\Contracts\Container\Container $container
33
     *
34
     * @return void
35
     */
36 12
    public function __construct(Container $container)
37
    {
38 12
        $this->container = $container;
39 12
    }
40
41
    /**
42
     * Get a index instance.
43
     *
44
     * @param  string|\Illuminate\Database\Eloquent\Model $model
45
     *
46
     * @return \Algolia\AlgoliaSearch\Index
47
     */
48 9
    public function index($model): Index
49
    {
50 9
        $model = is_string($model) ? new $model : $model;
51
52 9
        return $this->client()->initIndex($model->searchableAs());
53
    }
54
55
    /**
56
     * Get a client instance.
57
     *
58
     * @return \Algolia\AlgoliaSearch\Interfaces\ClientInterface
59
     */
60 10
    public function client(): ClientInterface
61
    {
62 10
        return $this->container->get('algolia.client');
63
    }
64
65
    /**
66
     * Get a analytics instance.
67
     *
68
     * @return \Algolia\AlgoliaSearch\Analytics
69
     */
70 1
    public function analytics(): Analytics
71
    {
72 1
        return $this->container->get('algolia.analytics');
73
    }
74
}
75