Test Setup Failed
Push — master ( 7e4be1...55ee1d )
by Php Easy Api
04:25
created

PushingProcess::processHandler()   B

Complexity

Conditions 6
Paths 1

Size

Total Lines 38
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 1 Features 0
Metric Value
cc 6
eloc 20
c 3
b 1
f 0
nc 1
nop 0
dl 0
loc 38
rs 8.9777
1
<?php
2
3
namespace Migratio\Resource\PushManager;
4
5
use Resta\Support\Generator\Generator;
6
use Resta\Support\Utils;
7
8
trait PushingProcess
9
{
10
    /**
11
     * process handler
12
     *
13
     * @return mixed|string
14
     */
15
    public function processHandler()
16
    {
17
        return $this->errorHandler(function(){
18
            
19
            $results = [];
20
            
21
            foreach ($this->list as $table =>$datas){
22
23
                foreach ($datas as $data){
24
                    
25
                    $query = $this->queryBuilder($table,$data);
0 ignored issues
show
Bug introduced by
It seems like queryBuilder() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

25
                    /** @scrutinizer ignore-call */ 
26
                    $query = $this->queryBuilder($table,$data);
Loading history...
26
27
                    $query = $query->handle();
28
                    
29
                    
30
                    if($query===false){
31
                        $results[] = [];
32
                    }
33
                    else{
34
                        $status =($query['result']!==false) ? true : false;
35
                        
36
                        if($status){
37
                            $this->schema->getConnection()->generateEntity($table);
38
                        }
39
40
                        $results[]= [
41
                            'success'=>$status,
42
                            'file'=>$data->getFile(),
43
                            'table'=>$table,
44
                            'type'=>$query['type'],
45
                            'syntax'=>$query['syntax'],
46
                            'message'=>$query['message']
47
                        ];
48
                    }
49
                }
50
            }
51
52
            return $results;
53
        });
54
    }
55
56
    /**
57
     * error handler
58
     *
59
     * @param callable $callback
60
     * @return mixed|string
61
     */
62
    public function errorHandler(callable $callback)
63
    {
64
        foreach ($this->list as $table => $objects)
65
        {
66
            foreach ($objects as $object)
67
            {
68
                $alterBinds = $object->getAlterBinds();
69
                
70
                if(!is_null($alterBinds) && count($alterBinds)>1){
71
                    exception()->runtime('Only one command can be applied to alter groups');
72
                }
73
                
74
                if(count($object->getError())){
75
                    exception()->runtime(''.$object->getFile().' -> '.$object->getError()[0].'');
76
                }
77
                
78
            }
79
        }
80
81
        return call_user_func($callback);
82
    }
83
}