Completed
Push — master ( 001ea7...a8b2a6 )
by ANTERIO
03:42
created

InstallCommand::handle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 11
ccs 0
cts 7
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace OwenIt\Auditing\Console;
4
5
use Illuminate\Support\Str;
6
use Illuminate\Console\Command;
7
use Illuminate\Console\DetectsApplicationNamespace;
8
9
class InstallCommand extends Command
10
{
11
    use DetectsApplicationNamespace;
12
13
    /**
14
     * {@inheritdoc}
15
     */
16
    protected $signature = 'auditing:install';
17
18
    /**
19
     * {@inheritdoc}
20
     */
21
    protected $description = 'Install all of the Auditing resources';
22
23
    /**
24
     * {@inheritdoc}
25
     */
26
    public function handle()
27
    {
28
        $this->comment('Publishing Auditing Configuration...');
29
        $this->callSilent('vendor:publish', ['--tag' => 'config']);
30
31
        $this->comment('Publishing Auditing Migrations...');
32
        $this->callSilent('vendor:publish', ['--tag' => 'migrations']);
33
34
        $this->registerAuditingServiceProvider();
35
36
        $this->info('Auditing installed successfully.');
37
    }
38
39
    /**
40
     * Register the Auditing service provider in the application configuration file.
41
     *
42
     * @return void
43
     */
44
    protected function registerAuditingServiceProvider()
45
    {
46
        $namespace = str_replace_last('\\', '', $this->getAppNamespace());
0 ignored issues
show
Deprecated Code introduced by
The function str_replace_last() has been deprecated: Str::replaceLast() should be used directly instead. Will be removed in Laravel 5.9. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

46
        $namespace = /** @scrutinizer ignore-deprecated */ str_replace_last('\\', '', $this->getAppNamespace());

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
47
48
        $appConfig = file_get_contents(config_path('app.php'));
49
50
        if (Str::contains($appConfig, 'OwenIt\\Auditing\\AuditingServiceProvider::class')) {
51
            return;
52
        }
53
54
        file_put_contents(config_path('app.php'), str_replace(
55
            "{$namespace}\\Providers\EventServiceProvider::class,".PHP_EOL,
56
            "{$namespace}\\Providers\EventServiceProvider::class,".PHP_EOL."        OwenIt\Auditing\AuditingServiceProvider::class,".PHP_EOL,
57
            $appConfig
58
        ));
59
    }
60
}
61