Completed
Push — master ( ba1ead...569a7a )
by Antonio Carlos
18:11 queued 13:25
created

Tables   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 90
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 2
dl 0
loc 90
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 4 1
A fire() 0 18 4
A getPackageMigrationsPath() 0 6 1
A getBaseMigrationsPath() 0 10 2
A makeMigrationPath() 0 4 1
1
<?php
2
3
namespace PragmaRX\Tracker\Vendor\Laravel\Artisan;
4
5
class Tables extends Base
6
{
7
    /**
8
     * Command name.
9
     *
10
     * @var string
11
     */
12
    protected $name = 'tracker:tables';
13
14
    /**
15
     * Command description.
16
     *
17
     * @var string
18
     */
19
    protected $description = 'Create the migrations for Tracker database tables and columns';
20
21
    /**
22
     * Execute the command (Compatibility with Laravel 5.5).
23
     *
24
     * @return void
25
     */
26
    public function handle()
27
    {
28
        $this->fire();
29
    }
30
    
31
    /**
32
     * Execute the command.
33
     *
34
     * @return void
35
     */
36
    public function fire()
37
    {
38
        $files = $this->laravel->make('files');
39
40
        foreach ($files->files($this->getPackageMigrationsPath()) as $file) {
41
            if (!file_exists($destination = $this->makeMigrationPath($file))) {
42
                $files->copy($file, $destination);
43
44
                $this->info("Migration created: $destination");
45
            }
46
        }
47
48
        if (isLaravel5()) {
49
            $this->call('optimize');
50
        } else {
51
            $this->call('dump-autoload');
52
        }
53
    }
54
55
    /**
56
     * Get the package migrations folder.
57
     *
58
     * @return string
59
     */
60
    protected function getPackageMigrationsPath()
61
    {
62
        $ds = DIRECTORY_SEPARATOR;
63
64
        return __DIR__."{$ds}..{$ds}..{$ds}..{$ds}migrations";
65
    }
66
67
    /**
68
     * Get the system migrations folder.
69
     *
70
     * @return string
71
     */
72
    protected function getBaseMigrationsPath()
73
    {
74
        $path = 'database'.DIRECTORY_SEPARATOR.'migrations';
75
76
        if (isLaravel5()) {
77
            return base_path($path);
78
        }
79
80
        return app_path($path);
81
    }
82
83
    /**
84
     * Make a full path migration name.
85
     *
86
     * @param $file
87
     *
88
     * @return string
89
     */
90
    private function makeMigrationPath($file)
91
    {
92
        return $this->getBaseMigrationsPath().DIRECTORY_SEPARATOR.basename($file);
93
    }
94
}
95