Passed
Branch main (ec0923)
by Seth
01:27
created

SaasServiceProvider::boot()   A

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\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...
22
use SaasReady\Services\TranslationRepositories\DatabaseTranslationRepository;
23
24
class SaasServiceProvider extends ServiceProvider
25
{
26
    public function boot(): void
27
    {
28
        AboutCommand::add('ShipSaaS/Ready', fn () => ['Version' => '1.0.0']);
29
30
        $this->mergeConfigFrom(__DIR__ . '/Configs/saas-ready.php', 'saas-ready');
31
32
        $this->publishes([
33
            __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

33
            __DIR__ . '/Configs/saas-ready.php' => /** @scrutinizer ignore-call */ config_path('saas-ready.php'),
Loading history...
34
        ], 'saas-ready');
35
36
        $this->loadMigrationsFrom(__DIR__ . '/Database/Migrations');
37
        $this->loadRoutesFrom(__DIR__ . '/Routes/saas-ready-routes.php');
38
        $this->loadArtisanCommands();
39
40
        Event::listen(EventSourcingContract::class, function (EventSourcingContract $event) {
41
            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

41
            if (!/** @scrutinizer ignore-call */ config('saas-ready.event-sourcing.should-queue')) {
Loading history...
42
                EventSourcingListener::dispatchSync($event);
43
44
                return;
45
            }
46
47
            EventSourcingListener::dispatch($event)
48
                ->onQueue(config('saas-ready.event-sourcing.queue-name'))
49
                ->onConnection(config('saas-ready.event-sourcing.queue-connection'));
50
        });
51
52
        Route::model('currency', Currency::class);
53
        Route::model('country', Country::class);
54
        Route::model('event', EventModel::class);
55
        Route::model('translation', Translation::class);
56
        Route::model('dynamicSetting', DynamicSetting::class);
57
        Route::model('releaseNote', ReleaseNote::class);
58
    }
59
60
    public function register(): void
61
    {
62
        $this->app->singleton(DatabaseTranslationRepository::class);
63
        $this->app->singleton(CacheTranslationRepository::class);
64
65
        $this->app->bind(TranslationRepositoryContract::class, function () {
66
            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

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