InstallCommand::fire()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php namespace FreedomCore\TrinityCore\Character\Commands;
2
3
use FreedomCore\TrinityCore\Character\CharacterServiceProvider;
4
use FreedomCore\TrinityCore\Character\Traits\Seedable;
5
use Illuminate\Console\Command;
6
use Symfony\Component\Process\Process;
7
8
/**
9
 * Class InstallCommand
10
 * @package FreedomCore\TrinityCore\Character\Commands
11
 */
12
class InstallCommand extends Command
13
{
14
    use Seedable;
15
16
    /**
17
     * Path containing database seeds
18
     * @var string
19
     */
20
    protected $seedersPath = __DIR__ . '/../../publishable/database/seeds';
21
22
    /**
23
     * The console command name.
24
     * @var string
25
     */
26
    protected $name = 'character:install';
27
28
    /**
29
     * The console command description.
30
     * @var string
31
     */
32
    protected $description = 'Install Laravel Character Package.';
33
34
    /**
35
     * Fire Installation
36
     * @return mixed
37
     */
38
    public function fire()
39
    {
40
        return $this->handle();
41
    }
42
43
    /**
44
     * Handle Installation
45
     */
46
    public function handle()
47
    {
48
        $this->info('Publishing package assets, database and configuration files...');
49
        $this->call('vendor:publish', ['--provider' => CharacterServiceProvider::class]);
50
        $this->info('Dumping the autoloaded files and reloading all new files');
51
        (new Process($this->findComposer() . ' dump-autoload -o'))->setWorkingDirectory(base_path())->run();
52
    }
53
54
    /**
55
     * Find suitable composer executable.
56
     * @return string
57
     */
58
    protected function findComposer() : string
59
    {
60
        if (file_exists(getcwd() . '/composer.phar')) {
61
            return '"' . PHP_BINARY . '" ' . getcwd() . '/composer.phar';
62
        }
63
        return 'composer';
64
    }
65
}
66