Issues (35)

src/Console/InstallCommand.php (1 issue)

Severity
1
<?php
2
3
namespace OwenIt\Auditing\Console;
4
5
use Illuminate\Console\Command;
6
use Illuminate\Container\Container;
7
use Illuminate\Support\Str;
8
9
class InstallCommand extends Command
10
{
11
    /**
12
     * {@inheritdoc}
13
     */
14
    protected $signature = 'auditing:install';
15
16
    /**
17
     * {@inheritdoc}
18
     */
19
    protected $description = 'Install all of the Auditing resources';
20
21
    /**
22
     * {@inheritdoc}
23
     */
24
    public function handle()
25
    {
26
        $this->comment('Publishing Auditing Configuration...');
27
        $this->callSilent('vendor:publish', ['--tag' => 'config']);
28
29
        $this->comment('Publishing Auditing Migrations...');
30
        $this->callSilent('vendor:publish', ['--tag' => 'migrations']);
31
32
        $this->registerAuditingServiceProvider();
33
34
        $this->info('Auditing installed successfully.');
35
    }
36
37
    /**
38
     * Register the Auditing service provider in the application configuration file.
39
     *
40
     * @return void
41
     */
42
    protected function registerAuditingServiceProvider()
43
    {
44
        $namespace = Str::replaceLast('\\', '', Container::getInstance()->getNamespace());
0 ignored issues
show
The method getNamespace() does not exist on Illuminate\Container\Container. Are you sure you never get this type here, but always one of the subclasses? ( Ignorable by Annotation )

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

44
        $namespace = Str::replaceLast('\\', '', Container::getInstance()->/** @scrutinizer ignore-call */ getNamespace());
Loading history...
45
46
        $appConfig = file_get_contents(config_path('app.php'));
47
48
        if (Str::contains($appConfig, 'OwenIt\\Auditing\\AuditingServiceProvider::class')) {
49
            return;
50
        }
51
52
        file_put_contents(config_path('app.php'), str_replace(
53
            "{$namespace}\\Providers\EventServiceProvider::class,".PHP_EOL,
54
            "{$namespace}\\Providers\EventServiceProvider::class,".PHP_EOL."        OwenIt\Auditing\AuditingServiceProvider::class,".PHP_EOL,
55
            $appConfig
56
        ));
57
    }
58
}
59