SaasServiceProvider::boot()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 32
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
cc 2
eloc 21
nc 1
nop 0
dl 0
loc 32
rs 9.584
c 4
b 0
f 0
1
<?php
2
3
namespace SaasReady;
4
5
use Illuminate\Foundation\Console\AboutCommand;
0 ignored issues
show
Bug introduced by
The type Illuminate\Foundation\Console\AboutCommand 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...
6
use Illuminate\Support\Facades\Event;
0 ignored issues
show
Bug introduced by
The type Illuminate\Support\Facades\Event 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...
7
use Illuminate\Support\Facades\Route;
0 ignored issues
show
Bug introduced by
The type Illuminate\Support\Facades\Route 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...
8
use Illuminate\Support\ServiceProvider;
0 ignored issues
show
Bug introduced by
The type Illuminate\Support\ServiceProvider 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...
9
use SaasReady\Commands\ActivateEntityCommand;
10
use SaasReady\Commands\DeactivateEntityCommand;
11
use SaasReady\Commands\RenderTranslationsCommand;
12
use SaasReady\Contracts\EventSourcingContract;
13
use SaasReady\Contracts\TranslationRepositoryContract;
14
use SaasReady\Listeners\EventSourcingListener;
15
use SaasReady\Models\Country;
0 ignored issues
show
Bug introduced by
The type SaasReady\Models\Country 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...
16
use SaasReady\Models\Currency;
0 ignored issues
show
Bug introduced by
The type SaasReady\Models\Currency 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...
17
use SaasReady\Models\DynamicSetting;
0 ignored issues
show
Bug introduced by
The type SaasReady\Models\DynamicSetting 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...
18
use SaasReady\Models\Event as EventModel;
19
use SaasReady\Models\ReleaseNote;
20
use SaasReady\Models\Translation;
0 ignored issues
show
Bug introduced by
The type SaasReady\Models\Translation 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...
21
use SaasReady\Services\FileManager\FileManager;
22
use SaasReady\Services\TranslationRepositories\CacheTranslationRepository;
0 ignored issues
show
Bug introduced by
The type SaasReady\Services\Trans...heTranslationRepository 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...
23
use SaasReady\Services\TranslationRepositories\DatabaseTranslationRepository;
24
25
class SaasServiceProvider extends ServiceProvider
26
{
27
    public function boot(): void
28
    {
29
        AboutCommand::add('ShipSaaS/Ready', fn () => ['Version' => '1.0.0']);
30
31
        $this->mergeConfigFrom(__DIR__ . '/Configs/saas-ready.php', 'saas-ready');
32
33
        $this->publishes([
34
            __DIR__ . '/Configs/saas-ready.php' => config_path('saas-ready.php'),
0 ignored issues
show
Bug introduced by
The function config_path was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

34
            __DIR__ . '/Configs/saas-ready.php' => /** @scrutinizer ignore-call */ config_path('saas-ready.php'),
Loading history...
35
        ], 'saas-ready');
36
37
        $this->loadMigrationsFrom(__DIR__ . '/Database/Migrations');
38
        $this->loadRoutesFrom(__DIR__ . '/Routes/saas-ready-routes.php');
39
        $this->loadArtisanCommands();
40
41
        Event::listen(EventSourcingContract::class, function (EventSourcingContract $event) {
42
            if (!config('saas-ready.event-sourcing.should-queue')) {
0 ignored issues
show
Bug introduced by
The function config was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

42
            if (!/** @scrutinizer ignore-call */ config('saas-ready.event-sourcing.should-queue')) {
Loading history...
43
                EventSourcingListener::dispatchSync($event);
44
45
                return;
46
            }
47
48
            EventSourcingListener::dispatch($event)
49
                ->onQueue(config('saas-ready.event-sourcing.queue-name'))
50
                ->onConnection(config('saas-ready.event-sourcing.queue-connection'));
51
        });
52
53
        Route::model('currency', Currency::class);
54
        Route::model('country', Country::class);
55
        Route::model('event', EventModel::class);
56
        Route::model('translation', Translation::class);
57
        Route::model('dynamicSetting', DynamicSetting::class);
58
        Route::model('releaseNote', ReleaseNote::class);
59
    }
60
61
    public function register(): void
62
    {
63
        $this->app->singleton(DatabaseTranslationRepository::class);
64
        $this->app->singleton(CacheTranslationRepository::class);
65
        $this->app->singleton(FileManager::class);
66
67
        $this->app->bind(TranslationRepositoryContract::class, function () {
68
            if (config('saas-ready.translation.should-cache')) {
0 ignored issues
show
Bug introduced by
The function config was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

68
            if (/** @scrutinizer ignore-call */ config('saas-ready.translation.should-cache')) {
Loading history...
69
                return $this->app->make(CacheTranslationRepository::class);
70
            }
71
72
            return $this->app->make(DatabaseTranslationRepository::class);
73
        });
74
    }
75
76
    private function loadArtisanCommands(): void
77
    {
78
        if (!$this->app->runningInConsole()) {
79
            return;
80
        }
81
82
        $this->commands([
83
            ActivateEntityCommand::class,
84
            DeactivateEntityCommand::class,
85
            RenderTranslationsCommand::class,
86
        ]);
87
    }
88
}
89