Passed
Push — main ( 8be512...d37a54 )
by Seth
04:30 queued 01:53
created

SaasServiceProvider::loadArtisanCommands()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
c 0
b 0
f 0
nc 2
nop 0
dl 0
loc 9
rs 10
1
<?php
2
3
namespace SaasReady;
4
5
use Illuminate\Database\Eloquent\Factories\Factory;
6
use Illuminate\Foundation\Console\AboutCommand;
7
use Illuminate\Support\Facades\Event;
8
use Illuminate\Support\Facades\Route;
9
use Illuminate\Support\ServiceProvider;
10
use SaasReady\Commands\ActivateEntityCommand;
11
use SaasReady\Commands\DeactivateEntityCommand;
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\Event as EventModel;
18
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...
19
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...
20
use SaasReady\Services\TranslationRepositories\DatabaseTranslationRepository;
21
22
class SaasServiceProvider extends ServiceProvider
23
{
24
    public function boot(): void
25
    {
26
        AboutCommand::add('ShipSaaS/Ready', fn () => ['Version' => '1.0.0']);
27
28
        $this->mergeConfigFrom(__DIR__ . '/Configs/saas-ready.php', 'saas-ready');
29
30
        $this->publishes([
31
            __DIR__ . '/Configs/saas-ready.php',
32
        ], 'saas-ready');
33
34
        $this->loadMigrationsFrom(__DIR__ . '/Database/Migrations');
35
        $this->loadRoutesFrom(__DIR__ . '/Routes/saas-ready-routes.php');
36
        $this->loadArtisanCommands();
37
38
        Event::listen(EventSourcingContract::class, function (EventSourcingContract $event) {
39
            if (!config('saas-ready.event-sourcing.should-queue')) {
40
                EventSourcingListener::dispatchSync($event);
41
42
                return;
43
            }
44
45
            EventSourcingListener::dispatch($event)
46
                ->onQueue(config('saas-ready.event-sourcing.queue-name'))
47
                ->onConnection(config('saas-ready.event-sourcing.queue-connection'));
48
        });
49
50
        Factory::guessFactoryNamesUsing(function (string $modelName) {
51
            return 'SaasReady\\Database\\Factories\\' . class_basename($modelName) . 'Factory';
52
        });
53
54
        Route::model('currency', Currency::class);
55
        Route::model('country', Country::class);
56
        Route::model('event', EventModel::class);
57
        Route::model('translation', Translation::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')) {
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
        ]);
84
    }
85
}
86