Completed
Push — develop ( 4e8497...df799e )
by Enea
02:52
created

InstallCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 81.82%

Importance

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

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 2
    public function __construct(Filesystem $files, Composer $composer)
34
    {
35 2
        parent::__construct();
36 2
        $this->files = $files;
37 2
        $this->composer = $composer;
38 2
    }
39
40 1
    public function handle(): void
41
    {
42 1
        $this->publishConfig();
43 1
        $this->publishMigration();
44
45
        $this->info('Successfully installed laravel-authorization!');
46
        $this->composer->dumpAutoloads();
47
    }
48
49 1
    private function publishConfig(): void
50
    {
51 1
        $this->info('Publishing the config file');
52
53 1
        Artisan::call('vendor:publish', [
54 1
            '--provider' => AuthorizationServiceProvider::class,
55
        ]);
56 1
    }
57
58 1
    private function publishMigration(): void
59
    {
60 1
        $migration = 'create_laravel_authorization_tables';
61 1
        $this->info('Publishing the migration file');
62 1
        $source = __DIR__ . "/../../database/migrations/{$migration}.stub";
63 1
        $destination = $this->laravel->make('migration.creator')->create($migration, database_path('migrations'));
64
65
        $this->files->copy($source, $destination);
66
    }
67
}
68