Completed
Push — stable ( 86ecc3...3a45ea )
by Nuno
07:34
created

Installer::install()   B

Complexity

Conditions 6
Paths 1

Size

Total Lines 91
Code Lines 45

Duplication

Lines 27
Ratio 29.67 %

Code Coverage

Tests 42
CRAP Score 6.1474

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 27
loc 91
ccs 42
cts 50
cp 0.84
rs 8.2585
cc 6
eloc 45
nc 1
nop 0
crap 6.1474

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/**
4
 * This file is part of Laravel Zero.
5
 *
6
 * (c) Nuno Maduro <[email protected]>
7
 *
8
 *  For the full copyright and license information, please view the LICENSE
9
 *  file that was distributed with this source code.
10
 */
11
12
namespace LaravelZero\Framework\Components\Database;
13
14
use Illuminate\Support\Str;
15
use Illuminate\Support\Facades\File;
16
use LaravelZero\Framework\Components\AbstractInstaller;
17
18
/**
19
 * This is the Laravel Zero Framework Component Database Installer Implementation.
20
 */
21
class Installer extends AbstractInstaller
22
{
23
    /**
24
     * {@inheritdoc}
25
     */
26
    protected $name = 'install:database';
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    protected $description = 'Installs illuminate/database - Eloquent';
32
33
    /**
34
     * The config file path.
35
     */
36
    const CONFIG_FILE = __DIR__ . DIRECTORY_SEPARATOR . 'stubs' . DIRECTORY_SEPARATOR . 'database.php';
37
38
    /**
39
     * The seeder file.
40
     */
41
    const SEEDER_FILE = __DIR__ . DIRECTORY_SEPARATOR . 'stubs' . DIRECTORY_SEPARATOR . 'DatabaseSeeder.php';
42
43
    /**
44
     * {@inheritdoc}
45
     */
46 2
    public function install(): void
47
    {
48 2
        $this->require('illuminate/database "5.6.*"');
49
50 2
        $this->task(
0 ignored issues
show
Documentation Bug introduced by
The method task does not exist on object<LaravelZero\Frame...nts\Database\Installer>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
51 2
            'Creating a default SQLite database',
52 2
            function () {
53 2
                if (! File::exists(database_path('database.sqlite'))) {
54 2
                    File::makeDirectory(database_path('migrations'), 0755, true, true);
55
56 2
                    File::put(
57 2
                        database_path('database.sqlite'),
58 2
                        ''
59
                    );
60
61 2
                    return true;
62
                }
63
64
                return false;
65 2
            }
66
        );
67
68 2
        $this->task(
0 ignored issues
show
Documentation Bug introduced by
The method task does not exist on object<LaravelZero\Frame...nts\Database\Installer>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
69 2
            'Creating seeds folders and files',
70 2
            function () {
71 2
                if (! File::exists(database_path('seeds' . DIRECTORY_SEPARATOR . 'DatabaseSeeder.php'))) {
72 2
                    File::makeDirectory(database_path('seeds'), 0755, false, true);
73
74 2
                    File::copy(
75 2
                        static::SEEDER_FILE,
76 2
                        database_path('seeds' . DIRECTORY_SEPARATOR . 'DatabaseSeeder.php')
77
                    );
78
79 2
                    return true;
80
                }
81
82
                return false;
83 2
            }
84
        );
85
86 2
        $this->task(
0 ignored issues
show
Documentation Bug introduced by
The method task does not exist on object<LaravelZero\Frame...nts\Database\Installer>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
87 2
            'Creating default database configuration',
88 2 View Code Duplication
            function () {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
89 2
                if (! File::exists(config_path('database.php'))) {
90 2
                    File::copy(
91 2
                        static::CONFIG_FILE,
92 2
                        config_path('database.php')
93
                    );
94
95 2
                    return true;
96
                }
97
98
                return false;
99 2
            }
100
        );
101
102 2
        $this->task(
0 ignored issues
show
Documentation Bug introduced by
The method task does not exist on object<LaravelZero\Frame...nts\Database\Installer>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
103 2
            'Updating .gitignore',
104 2 View Code Duplication
            function () {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
105
106 2
                $gitignorePath = base_path('.gitignore');
107 2
                if (File::exists($gitignorePath)) {
108
                    $contents = File::get($gitignorePath);
109
                    $neededLine = '/database/database.sqlite';
110
                    if (! Str::contains($contents, $neededLine)) {
111
                        File::append($gitignorePath, $neededLine . PHP_EOL);
112
113
                        return true;
114
                    }
115
                }
116
117 2
                return false;
118 2
            }
119
        );
120
121 2
        $this->info('Usage:');
122 2
        $this->comment(
123 2
            '
124
$ php <your-application-name> make:migration create_users_table
125
$ php <your-application-name> migrate
126
127
use Illuminate\Support\Facades\DB;
128
129
DB::table(\'users\')->insert(
130
    [\'email\' => \'[email protected]\']
131
);
132
133
$users = DB::table(\'users\')->get();
134
        '
135
        );
136 2
    }
137
}
138