InstallCommand::handle()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace DigitalEquation\Teamwork\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 = 'teamwork:install';
16
17
    /**
18
     * The console command description.
19
     *
20
     * @var string
21
     */
22
    protected $description = 'Install all of the Teamwork resources';
23
24
    /**
25
     * Execute the console command.
26
     *
27
     * @return void
28
     */
29
    public function handle()
30
    {
31
        $this->comment('Publishing Teamwork Service Provider...');
32
        $this->callSilent('vendor:publish', ['--tag' => 'provider']);
33
34
        $this->comment('Publishing Teamwork Configuration...');
35
        $this->callSilent('vendor:publish', ['--tag' => 'config']);
36
37
        $this->registerTeamworkServiceProvider();
38
39
        $this->info('Teamwork scaffolding installed successfully.');
40
    }
41
42
    /**
43
     * Register the Teamwork service provider in the application configuration file.
44
     *
45
     * @return void
46
     */
47
    protected function registerTeamworkServiceProvider()
48
    {
49
        $namespace = Str::replaceLast('\\', '', $this->getAppNamespace());
0 ignored issues
show
Documentation Bug introduced by
The method getAppNamespace does not exist on object<DigitalEquation\T...Console\InstallCommand>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
50
51
        $appConfig = file_get_contents(config_path('app.php'));
52
53
        if (Str::contains($appConfig, $namespace.'\\DigitalEquation\Teamwork\TeamworkServiceProvider::class')) {
54
            return;
55
        }
56
57
        file_put_contents(config_path('app.php'), str_replace(
58
            '/*
59
         * Package Service Providers...
60
         */'.PHP_EOL,
61
            '/*
62
         * Package Service Providers...
63
         */'.PHP_EOL."        DigitalEquation\Teamwork\TeamworkServiceProvider::class,".PHP_EOL,
64
            $appConfig
65
        ));
66
    }
67
}
68