Test Failed
Push — master ( d53899...a1c82c )
by Php Easy Api
08:28
created

Pushing::handle()   B

Complexity

Conditions 7
Paths 8

Size

Total Lines 39
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
cc 7
eloc 17
nc 8
nop 0
dl 0
loc 39
rs 8.8333
c 2
b 1
f 0
1
<?php
2
3
namespace Migratio\Resource\PushManager;
4
5
use Migratio\SchemaCapsule;
6
use Migratio\Resource\BaseManager;
7
8
class Pushing extends BaseManager
9
{
10
    //get pushing
11
    use PushingProcess;
12
13
    /**
14
     * @var array
15
     */
16
    protected $list = array();
17
18
    /**
19
     * pushing handle
20
     *
21
     * @return void|mixed
22
     */
23
    public function handle()
24
    {
25
        foreach ($this->tableFilters() as $table=>$files){
26
27
            $table = strtolower($table);
28
29
            foreach ($files as $file) {
30
31
                $checkMigrationMain = $this->schema->getConnection()->checkMigrationMain();
32
                
33
                if($checkMigrationMain===false && isset($this->tableFilters()['Migrations'][0])){
34
                    $this->apply($this->tableFilters()['Migrations'][0],'migrations');
35
                }
36
                
37
                $checkMigration = $this->schema->getConnection()->checkMigration($table,$file);
38
                
39
                if(!$checkMigration){
40
41
                    $getClassName = preg_replace('@(\d+)_@is','',$file);
42
                    $className = $this->getClassName($getClassName);
43
44
                    require_once ($file);
45
46
                    $capsule = new SchemaCapsule($this->config,$file,$table);
47
48
                    $this->list[$table][] = (new $className)->up($capsule);
49
50
                    if(app()->has('arguments')){
51
                        app()->terminate('arguments');
52
                    }
53
54
                    app()->register('arguments','table',$table);
55
                }
56
57
                
58
            }
59
        }
60
61
        return $this->processHandler();
62
    }
63
64
    /**
65
     * @param $file
66
     * @param $table
67
     * @return mixed|string
68
     */
69
    public function apply($file,$table)
70
    {
71
        $getClassName = preg_replace('@(\d+)_@is','',$file);
72
        $className = $this->getClassName($getClassName);
73
74
        require_once ($file);
75
76
        $capsule = new SchemaCapsule($this->config,$file,$table);
77
78
        $this->list[$table][] = (new $className)->up($capsule);
79
80
        return $this->processHandler();
81
    }
82
83
84
}