Test Failed
Push — stable ( 977f63...62e79c )
by Nuno
02:59
created

Installer::getComponentName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace LaravelZero\Framework\Commands\Component\Illuminate\Database;
4
5
use LaravelZero\Framework\Commands\Component\Installer as BaseInstaller;
6
use LaravelZero\Framework\Contracts\Commands\Component\Installer as InstallerContract;
7
8
/**
9
 * This is the Laravel Zero Framework illuminate/database install class.
10
 *
11
 * @author Nuno Maduro <[email protected]>
12
 */
13
class Installer extends BaseInstaller implements InstallerContract
14
{
15
    /**
16
     * {@inheritdoc}
17
     */
18
    protected $name = 'install:database';
19
20
    /**
21
     * {@inheritdoc}
22
     */
23
    protected $description = 'Installs illuminate/database - Eloquent';
24
25
    /**
26
     * The config file path.
27
     */
28
    const CONFIG_FILE = __DIR__.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'database.php';
29
30
    /**
31
     * {@inheritdoc}
32
     */
33
    public function getComponentName(): string
34
    {
35
        return 'database';
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function install(): bool
42
    {
43
        $this->require('illuminate/database "5.5.*"');
44
        $this->task(
45
            'Creating directories and files under database folder',
46
            function () {
47
                $this->files->makeDirectory(database_path('migrations'), 0755, true, true);
48
                if (! $this->files->exists(database_path('database.sqlite'))) {
49
                    $this->files->put(database_path('database.sqlite'), '');
50
                }
51
                $this->files->makeDirectory(database_path('seeds'), 0755, false, true);
52
                if (! $this->files->exists(database_path('seeds').DIRECTORY_SEPARATOR.'DatabaseSeeder.php')) {
53
                    $this->files->copy(
54
                        __DIR__.DIRECTORY_SEPARATOR.'files'.DIRECTORY_SEPARATOR.'DatabaseSeeder.php',
55
                        database_path('seeds').DIRECTORY_SEPARATOR.'DatabaseSeeder.php'
56
                    );
57
                }
58
59
                return true;
60
            }
61
        );
62
63
        $this->task(
64
            'Creating default config',
65
            function () {
66
                if (! $this->files->exists(static::CONFIG_FILE)) {
67
                    $this->files->copy(
68
                        static::CONFIG_FILE,
69
                        config_path('database.php')
70
                    );
71
                }
72
73
                return true;
74
            }
75
        );
76
77
        $this->info('Usage:');
78
        $this->comment(
79
            '
80
81
$ php <your-application-name> make:migration create_users_table
82
$ php <your-application-name> migrate
83
84
use Illuminate\Support\Facades\DB;
85
86
DB::table(\'users\')->insert(
87
    [\'email\' => \'[email protected]\']
88
);
89
90
$users = DB::table(\'users\')->get();
91
92
dd($users);
93
94
        '
95
        );
96
97
        return true;
98
    }
99
}
100