Passed
Push — develop ( 53798b...20a922 )
by Enea
02:15
created

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

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
62
63
        $this->files->copy($source, $destination);
64
    }
65
}
66