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

InstallCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
dl 0
loc 49
ccs 0
cts 22
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 7 1
A publishMigration() 0 8 1
A __construct() 0 5 1
A publishConfig() 0 6 1
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