DbExportHandler::migrateAndSeed()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 1
eloc 4
nc 1
nop 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
}