SearchServiceProvider::register()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 23
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 23
rs 9.9666
cc 2
nc 1
nop 0
1
<?php
2
3
namespace App\Providers;
4
5
use App\Services\Search\Contracts\SearchServiceInterface;
6
use App\Services\Search\ElasticSearchService;
7
use App\Services\Search\ManticoreSearchService;
8
use Illuminate\Support\ServiceProvider;
9
10
class SearchServiceProvider extends ServiceProvider
11
{
12
    /**
13
     * Register any application services.
14
     */
15
    public function register(): void
16
    {
17
        // Register ManticoreSearchService as singleton
18
        $this->app->singleton(ManticoreSearchService::class, function ($app) {
0 ignored issues
show
Unused Code introduced by
The parameter $app is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

18
        $this->app->singleton(ManticoreSearchService::class, function (/** @scrutinizer ignore-unused */ $app) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
19
            return new ManticoreSearchService();
20
        });
21
22
        // Register ElasticSearchService as singleton
23
        $this->app->singleton(ElasticSearchService::class, function ($app) {
0 ignored issues
show
Unused Code introduced by
The parameter $app is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

23
        $this->app->singleton(ElasticSearchService::class, function (/** @scrutinizer ignore-unused */ $app) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
24
            return new ElasticSearchService();
25
        });
26
27
        // Bind the interface to the appropriate implementation based on config
28
        $this->app->singleton(SearchServiceInterface::class, function ($app) {
29
            if (config('nntmux.elasticsearch_enabled') === true) {
30
                return $app->make(ElasticSearchService::class);
31
            }
32
33
            return $app->make(ManticoreSearchService::class);
34
        });
35
36
        // Register alias for ManticoreSearch (for backward compatibility)
37
        $this->app->alias(ManticoreSearchService::class, 'manticore');
38
    }
39
40
    /**
41
     * Bootstrap any application services.
42
     */
43
    public function boot(): void
44
    {
45
        //
46
    }
47
}
48
49