Completed
Push — master ( b13bbf...5b16af )
by Denis
04:07
created

InstallCommand   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
c 1
b 0
f 0
dl 0
loc 53
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 5 1
A registerServiceLayerServiceProvider() 0 20 2
1
<?php
2
3
namespace Zendaemon\Services\Console;
4
5
use Illuminate\Console\Command;
6
use Illuminate\Support\Str;
7
8
class InstallCommand extends Command
9
{
10
    /**
11
     * The name and signature of the console command.
12
     *
13
     * @var string
14
     */
15
    protected $signature = 'services:install';
16
17
    /**
18
     * The console command description.
19
     *
20
     * @var string
21
     */
22
    protected $description = 'Install all of the service layer resources';
23
24
    /**
25
     * Execute the console command.
26
     *
27
     * @return void
28
     */
29
    public function handle()
30
    {
31
        $this->registerServiceLayerServiceProvider();
32
33
        $this->info('Service Layer scaffolding installed successfully.');
34
    }
35
36
    /**
37
     * Register the ServiceLayer service provider in the application configuration file.
38
     *
39
     * @return void
40
     */
41
    protected function registerServiceLayerServiceProvider()
42
    {
43
        $namespace = Str::replaceLast('\\', '', $this->laravel->getNamespace());
44
45
        $appConfig = file_get_contents(config_path('app.php'));
46
47
        if (Str::contains($appConfig, $namespace.'\\Providers\\ServiceLayerServiceProvider::class')) {
48
            return;
49
        }
50
51
        file_put_contents(config_path('app.php'), str_replace(
52
            "{$namespace}\\Providers\EventServiceProvider::class,".PHP_EOL,
53
            "{$namespace}\\Providers\EventServiceProvider::class,".PHP_EOL."        {$namespace}\Providers\ServiceLayerServiceProvider::class,".PHP_EOL,
54
            $appConfig
55
        ));
56
57
        file_put_contents(app_path('Providers/ServiceLayerServiceProvider.php'), str_replace(
58
            "namespace App\Providers;",
59
            "namespace {$namespace}\Providers;",
60
            file_get_contents(app_path('Providers/ServiceLayerServiceProvider.php'))
61
        ));
62
    }
63
}
64