SchemalessServiceProvider::boot()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 22
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 13
c 1
b 0
f 0
nc 4
nop 0
dl 0
loc 22
rs 9.8333
1
<?php
2
3
namespace PrismX\Schemaless;
4
5
use Illuminate\Support\ServiceProvider;
6
use Illuminate\Support\Str;
7
use PrismX\Schemaless\Commands\MakeDocument;
8
use PrismX\Schemaless\Commands\MakeDocumentResource;
9
10
class SchemalessServiceProvider extends ServiceProvider
11
{
12
    public function boot()
13
    {
14
        if ($this->app->runningInConsole()) {
15
            $this->commands([
16
                MakeDocument::class,
17
                MakeDocumentResource::class,
18
            ]);
19
        }
20
21
        if (! class_exists('CreateDocumentsTable')) {
22
            $this->publishes([
23
                __DIR__.'/../database/migrations/create__documents_table.php' => database_path('migrations/'.date('Y_m_d_His', time()).'_create__documents_table.php'),
24
            ], 'migrations');
25
        }
26
27
        Str::macro('normalize', function ($str) {
28
            /** @var \Illuminate\Support\Str $this */
29
            $str = preg_replace('/(?<!^)[A-Z]/', ' $0', $str);
30
            $str = Str::slug($str);
31
            $str = str_replace('-', ' ', $str);
32
33
            return Str::title($str);
34
        });
35
    }
36
37
    public function register()
38
    {
39
    }
40
}
41