DbExportHandler   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 90
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 7
Bugs 0 Features 0
Metric Value
wmc 7
c 7
b 0
f 0
lcom 1
cbo 3
dl 0
loc 90
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getMigrationsFilePath() 0 4 1
A __construct() 0 5 1
A migrate() 0 6 1
A seed() 0 6 1
A migrateAndSeed() 0 10 1
A ignore() 0 6 1
A uploadTo() 0 6 1
1
<?php namespace Nwidart\DbExporter;
2
3
class DbExportHandler
4
{
5
    /**
6
     * @var DbMigrations
7
     */
8
    protected $migrator;
9
10
    /**
11
     * @var DbSeeding
12
     */
13
    protected $seeder;
14
15
    /**
16
     * Inject the DbMigrations class
17
     * @param DbMigrations $DbMigrations
18
     * @param DbSeeding $DbSeeding
19
     */
20
    function __construct(DbMigrations $DbMigrations, DbSeeding $DbSeeding)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
21
    {
22
        $this->migrator = $DbMigrations;
23
        $this->seeder = $DbSeeding;
24
    }
25
26
    /**
27
     * Create migrations from the given DB
28
     * @param String null $database
29
     * @return $this
30
     */
31
    public function migrate($database = null)
32
    {
33
        $this->migrator->convert($database)->write();
34
35
        return $this;
36
    }
37
38
    /**
39
     * @param null $database
40
     * @return $this
41
     */
42
    public function seed($database = null)
43
    {
44
        $this->seeder->convert($database)->write();
45
46
        return $this;
47
    }
48
49
    /**
50
     * Helper function to generate the migration and the seed in one command
51
     * @param null $database
52
     * @return $this
53
     */
54
    public function migrateAndSeed($database = null)
55
    {
56
        // Run the migrator generator
57
        $this->migrator->convert($database)->write();
58
59
        // Run the seeder generator
60
        $this->seeder->convert($database)->write();
61
62
        return $this;
63
    }
64
65
    /**
66
     * Add tables to the ignore array
67
     * @param $tables
68
     * @return $this
69
     */
70
    public function ignore($tables)
71
    {
72
        DbExporter::$ignore = array_merge(DbExporter::$ignore, (array)$tables);
73
74
        return $this;
75
    }
76
77
    /**
78
     * @return mixed
79
     */
80
    public function getMigrationsFilePath()
81
    {
82
        return DbMigrations::$filePath;
83
    }
84
85
    public function uploadTo($remote)
86
    {
87
        DbExporter::$remote = $remote;
88
89
        return $this;
90
    }
91
92
}