Test Failed
Push — develop ( ace3b9...fc2314 )
by Nuno
03:41
created

ScoutExtendedServiceProvider::boot()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
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 ReflectionClass;
17
use Laravel\Scout\Builder;
18
use Algolia\AlgoliaSearch\Analytics;
0 ignored issues
show
Bug introduced by
The type Algolia\AlgoliaSearch\Analytics was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
19
use Illuminate\Support\Facades\Blade;
20
use Illuminate\Support\ServiceProvider;
21
use Laravel\Scout\ScoutServiceProvider;
22
use Algolia\ScoutExtended\Engines\AlgoliaEngine;
23
use Algolia\ScoutExtended\Managers\EngineManager;
24
use Algolia\AlgoliaSearch\Interfaces\ClientInterface;
0 ignored issues
show
Bug introduced by
The type Algolia\AlgoliaSearch\Interfaces\ClientInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
25
use Algolia\ScoutExtended\Console\Commands\SyncCommand;
26
use Algolia\ScoutExtended\Console\Commands\FlushCommand;
27
use Algolia\ScoutExtended\Searchable\AggregatorObserver;
28
use Algolia\ScoutExtended\Console\Commands\ImportCommand;
29
use Algolia\ScoutExtended\Console\Commands\StatusCommand;
30
use Algolia\ScoutExtended\Console\Commands\OptimizeCommand;
31
use Algolia\ScoutExtended\Console\Commands\ReImportCommand;
32
use Algolia\ScoutExtended\Console\Commands\MakeAggregatorCommand;
33
34
final class ScoutExtendedServiceProvider extends ServiceProvider
35
{
36
    /**
37
     * {@inheritdoc}
38
     */
39 21
    public function boot(): void
40
    {
41 21
        $this->loadViewsFrom(__DIR__.'/../resources/views', 'algolia');
42
43 21
        Blade::component('algolia::components.scout', 'scout');
44 21
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49 21
    public function register(): void
50
    {
51 21
        $this->app->register(ScoutServiceProvider::class);
52
53 21
        $this->registerBinds();
54 21
        $this->registerCommands();
55 21
        $this->registerMacros();
56 21
    }
57
58
    /**
59
     * Binds Algolia services into the container.
60
     *
61
     * @return void
62
     */
63 21
    private function registerBinds(): void
64
    {
65
        $this->app->bind(Algolia::class, function () {
66 1
            return new Algolia($this->app);
67 21
        });
68
69 21
        $this->app->alias(Algolia::class, 'algolia');
70
71
        $this->app->singleton(EngineManager::class, function ($app) {
72 19
            return new EngineManager($app);
73 21
        });
74
75 21
        $this->app->alias(EngineManager::class, \Laravel\Scout\EngineManager::class);
76
77
        $this->app->bind(AlgoliaEngine::class, function (): AlgoliaEngine {
78 19
            return $this->app->make(\Laravel\Scout\EngineManager::class)->createAlgoliaDriver();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->app->make(...->createAlgoliaDriver() returns the type Laravel\Scout\Engines\AlgoliaEngine which includes types incompatible with the type-hinted return Algolia\ScoutExtended\Engines\AlgoliaEngine.
Loading history...
79 21
        });
80
81 21
        $this->app->alias(AlgoliaEngine::class, 'algolia.engine');
82
83
        $this->app->bind(ClientInterface::class, function (): ClientInterface {
84 19
            $engine = $this->app->make('algolia.engine');
85
            $reflection = new ReflectionClass(AlgoliaEngine::class);
86
            $property = $reflection->getProperty('algolia');
87
            $property->setAccessible(true);
88
89
            return $property->getValue($engine);
90 21
        });
91
92 21
        $this->app->alias(ClientInterface::class, 'algolia.client');
93
94
        $this->app->bind(Analytics::class, function (): Analytics {
95
            return Analytics::create(config('scout.algolia.id'), config('scout.algolia.secret'));
96 21
        });
97
98 21
        $this->app->alias(Analytics::class, 'algolia.analytics');
99
100 21
        $this->app->singleton(AggregatorObserver::class, AggregatorObserver::class);
101 21
    }
102
103
    /**
104
     * Register artisan commands.
105
     *
106
     * @return void
107
     */
108 21
    private function registerCommands(): void
109
    {
110 21
        if ($this->app->runningInConsole()) {
111 21
            $this->commands([
112 21
                MakeAggregatorCommand::class,
113
                ImportCommand::class,
114
                FlushCommand::class,
115
                OptimizeCommand::class,
116
                ReImportCommand::class,
117
                StatusCommand::class,
118
                SyncCommand::class,
119
            ]);
120
        }
121 21
    }
122
123
    /**
124
     * Register macros.
125
     *
126
     * @return void
127
     *
128
     * @throws \ReflectionException
129
     */
130 21
    private function registerMacros(): void
131
    {
132 21
        Builder::mixin(new BuilderMacros);
133 21
    }
134
}
135