MakeAdminUserSeeder   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 5
dl 0
loc 78
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A handle() 0 18 2
A getStubPath() 0 4 1
1
<?php
2
3
namespace Acacha\AdminLTETemplateLaravel\Console;
4
5
use Acacha\Filesystem\Compiler\StubFileCompiler;
6
use Acacha\Filesystem\Filesystem;
7
use Illuminate\Console\Command;
8
9
/**
10
 * Class MakeAdminUserSeeder.
11
 *
12
 * @package Acacha\AdminLTETemplateLaravel\Console
13
 */
14
class MakeAdminUserSeeder extends Command
15
{
16
    use HasUsername, HasEmail;
17
18
    /**
19
     * The name and signature of the console command.
20
     *
21
     * @var string
22
     */
23
    protected $signature = 'make:adminUserSeeder';
24
25
    /**
26
     * The console command description.
27
     *
28
     * @var string
29
     */
30
    protected $description = 'Create a new seed to add admin user to database';
31
32
    /**
33
     * Filesystem.
34
     *
35
     * @var Filesystem
36
     */
37
    protected $filesystem;
38
39
    /**
40
     * Compiler for stub file.
41
     *
42
     * @var StubFileCompiler
43
     */
44
    protected $compiler;
45
46
    /**
47
     * Create a new command instance.
48
     *
49
     * @param Filesystem $filesystem
50
     * @param StubFileCompiler $compiler
51
     */
52
    public function __construct(Filesystem $filesystem, StubFileCompiler $compiler)
53
    {
54
        parent::__construct();
55
        $this->filesystem = $filesystem;
56
        $this->compiler = $compiler;
57
    }
58
59
    /**
60
     * Execute the console command.
61
     *
62
     */
63
    public function handle()
64
    {
65
        try {
66
            $this->filesystem->overwrite(
67
                $path = database_path('seeds/' . config('AdminUserSeeder', 'AdminUserSeeder.php')),
68
                $this->compiler->compile(
69
                    $this->filesystem->get($this->getStubPath()),
70
                    [
71
                        "USER_NAME" => $this->username(),
72
                        "USER_EMAIL" => $this->email(),
73
                    ]
74
                )
75
            );
76
            $this->info('File ' . $path . ' created');
77
        } catch (\Exception $e) {
78
            print_r($e->getMessage());
79
        }
80
    }
81
82
    /**
83
     * Get path to stub.
84
     *
85
     * @return string
86
     */
87
    protected function getStubPath()
88
    {
89
        return __DIR__ . '/stubs/AdminUserSeeder.php';
90
    }
91
}
92