ProjectsServiceProvider::handleMigrations()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
nc 4
nop 0
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
1
<?php
2
3
namespace Chriscreates\Projects;
4
5
use Chriscreates\Projects\Commands\CreateTaskCommand;
6
use Chriscreates\Projects\Commands\ProjectsConfigCommand;
7
use Chriscreates\Projects\Commands\ProjectsSeederCommand;
8
use Illuminate\Database\Eloquent\Factory;
9
use Illuminate\Support\ServiceProvider;
10
11
class ProjectsServiceProvider extends ServiceProvider
12
{
13
    /**
14
     * Bootstrap the application services.
15
     */
16
    public function boot()
17
    {
18
        $this->bootFactories(projects_base_path('/database/factories'));
19
20
        $this->handleMigrations();
21
    }
22
23
    protected function bootFactories($path)
24
    {
25
        $this->app->make(Factory::class)->load($path);
26
    }
27
28
    /**
29
     * Register bindings in the container.
30
     *
31
     * @return void
32
     */
33
    public function register()
34
    {
35
        $this->registerCommands();
36
37
        foreach (glob(__DIR__.'/Helpers/*.php') as $file) {
38
            require_once($file);
39
        }
40
    }
41
42
    /**
43
     * Register the package's migrations.
44
     *
45
     * @return void
46
     */
47
    private function handleMigrations()
48
    {
49
        if ($this->app->runningUnitTests()) {
50
            $this->loadMigrationsFrom(projects_base_path('/database/test_migrations'));
51
        }
52
53
        if ($this->app->runningInConsole()) {
54
            $this->loadMigrationsFrom(projects_base_path('/database/migrations'));
55
        }
56
    }
57
58
    /**
59
     * @return void
60
     */
61
    private function registerCommands()
62
    {
63
        $this->commands([
64
            ProjectsConfigCommand::class,
65
            ProjectsSeederCommand::class,
66
            CreateTaskCommand::class,
67
        ]);
68
    }
69
}
70