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

InstallCommand::publishMigration()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1.0046

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 8
ccs 5
cts 6
cp 0.8333
crap 1.0046
rs 9.4285
c 0
b 0
f 0
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