AppServiceProvider   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 103
Duplicated Lines 0 %

Importance

Changes 3
Bugs 2 Features 0
Metric Value
eloc 52
c 3
b 2
f 0
dl 0
loc 103
rs 10
wmc 12

2 Methods

Rating   Name   Duplication   Size   Complexity  
B boot() 0 36 6
B register() 0 52 6
1
<?php
2
3
namespace App\Providers;
4
5
use App\Interfaces\CertificatesInterface;
6
use App\Interfaces\EnrollmentSheetInterface;
7
use App\Interfaces\InvoicingInterface;
8
use App\Interfaces\LMSInterface;
9
use App\Interfaces\MailingSystemInterface;
10
use App\Models\Book;
11
use App\Models\Config;
12
use App\Models\ContactRelationship;
13
use App\Models\EnrollmentStatusType;
14
use App\Models\Period;
15
use App\Models\Room;
16
use App\Models\Teacher;
17
use Illuminate\Support\Facades\Schema;
18
use Illuminate\Support\Facades\View;
19
use Illuminate\Support\ServiceProvider;
20
21
class AppServiceProvider extends ServiceProvider
22
{
23
    /**
24
     * Bootstrap any application services.
25
     *
26
     * @return void
27
     */
28
    public function boot()
29
    {
30
        Schema::defaultStringLength(191);
31
32
        if (\Schema::hasTable('periods') && \Schema::hasTable('config')) {
33
            $firstPeriod = Period::find(Config::where('name', 'first_period')->first()->value);
34
35
            if ($firstPeriod) {
36
                $periods = Period::where('id', '>=', $firstPeriod->id)->get();
37
            } else {
38
                $periods = Period::all();
39
            }
40
41
            $current_period = Period::get_default_period();
42
            View::share('periods', $periods);
43
            View::share('current_period', $current_period);
44
        }
45
46
        if (\Schema::hasTable('teachers')) {
47
            View::share('teachers', Teacher::all());
48
        }
49
50
        if (\Schema::hasTable('rooms')) {
51
            View::share('rooms', Room::all());
52
        }
53
54
        View::composer(
55
            ['partials.create_new_contact', 'students.edit-contact'],
56
            function ($view) {
57
                $view->with('contact_types', ContactRelationship::all());
58
            }
59
        );
60
61
        View::composer('partials.add_book_to_student', function ($view) {
62
            $view->with('books', Book::all());
63
            $view->with('statuses', EnrollmentStatusType::all());
64
        });
65
    }
66
67
    /**
68
     * Register any application services.
69
     *
70
     * @return void
71
     */
72
    public function register()
73
    {
74
        $syncTo = config('lms.sync_to');
75
76
        if ($syncTo) {
77
            $lms = config("lms.{$syncTo}.class");
78
79
            $this->app->bind(
80
                LMSInterface::class,
81
                $lms
82
            );
83
        }
84
85
        $invoicingSystem = config('invoicing.invoicing_system');
86
87
        if ($invoicingSystem) {
88
            $invoicingService = config("invoicing.{$invoicingSystem}.class");
89
90
            $this->app->bind(
91
                InvoicingInterface::class,
92
                $invoicingService
93
            );
94
        }
95
96
        $enrollmentSheetsStyle = config('certificates-generation.style');
97
98
        if ($enrollmentSheetsStyle) {
99
            $enrollmentSheetService = config("certificates-generation.{$enrollmentSheetsStyle}.class");
100
            $this->app->bind(
101
                CertificatesInterface::class,
102
                $enrollmentSheetService
103
            );
104
        }
105
106
        $enrollmentSheetsStyle = config('enrollment-sheet.style');
107
108
        if ($enrollmentSheetsStyle) {
109
            $enrollmentSheetService = config("enrollment-sheet.{$enrollmentSheetsStyle}.class");
110
            $this->app->bind(
111
                EnrollmentSheetInterface::class,
112
                $enrollmentSheetService
113
            );
114
        }
115
116
        $mailingSystem = config('mailing-system.mailing_system');
117
118
        if ($mailingSystem) {
119
            $mailingService = config("mailing-system.{$mailingSystem}.class");
120
121
            $this->app->bind(
122
                MailingSystemInterface::class,
123
                $mailingService
124
            );
125
        }
126
    }
127
}
128