Completed
Push — stable ( d6da9c...063f28 )
by Nuno
03:13
created

Installer   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 116
Duplicated Lines 23.28 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 78%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 27
loc 116
ccs 39
cts 50
cp 0.78
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B install() 27 90 6

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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