Passed
Push — develop ( 97f65e...d0561f )
by Enea
03:00
created

InstallCommand::handle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 0
cts 5
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * Created on 22/03/18 by enea dhack.
7
 */
8
9
namespace Enea\Authorization\Commands;
10
11
use Enea\Authorization\AuthorizationServiceProvider;
12
use Illuminate\Console\Command;
13
use Illuminate\Filesystem\Filesystem;
14
use Illuminate\Support\Composer;
15
use Illuminate\Support\Facades\Artisan;
16
17
class InstallCommand extends Command
18
{
19
    /**
20
     * {@inheritdoc}
21
     */
22
    protected $name = 'authorization:install';
23
24
    /**
25
     * {@inheritdoc}
26
     */
27
    protected $description = 'Install the migration and configuration files for laravel-authorization';
28
29
    private $files;
30
31
    private $composer;
32
33
    public function __construct(Filesystem $files, Composer $composer)
34
    {
35
        parent::__construct();
36
        $this->files = $files;
37
        $this->composer = $composer;
38
    }
39
40
    public function handle(): void
41
    {
42
        $this->publishConfig();
43
        $this->publishMigration();
44
45
        $this->info('Successfully installed laravel-authorization!');
46
        $this->composer->dumpAutoloads();
47
    }
48
49
    private function publishConfig(): void
50
    {
51
        $this->info('Publishing the config file');
52
53
        Artisan::call('vendor:publish', [
54
            '--provider' => AuthorizationServiceProvider::class,
55
        ]);
56
    }
57
58
    private function publishMigration(): void
59
    {
60
        $migration = 'create_laravel_authorization_tables';
61
        $this->info('Publishing the migration file');
62
        $source = __DIR__ . "/../../database/migrations/{$migration}.stub";
63
        $destination = $this->laravel->make('migration.creator')->create($migration, database_path('migrations'));
64
65
        $this->files->copy($source, $destination);
66
    }
67
}
68