Test Setup Failed
Push — master ( d6fde7...1e848b )
by Php Easy Api
04:20
created

PushingProcess::processHandler()   A

Complexity

Conditions 4
Paths 1

Size

Total Lines 28
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 15
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 28
rs 9.7666
1
<?php
2
3
namespace Migratio\Resource\PushManager;
4
5
use Migratio\GrammarStructure\Mysql\QueryBuilder;
6
7
trait PushingProcess
8
{
9
    /**
10
     * @return void
11
     */
12
    public function processHandler()
13
    {
14
        $results = [];
0 ignored issues
show
Unused Code introduced by
The assignment to $results is dead and can be removed.
Loading history...
15
16
        return $this->errorHandler(function(){
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->errorHandl...ion(...) { /* ... */ }) also could return the type string which is incompatible with the documented return type void.
Loading history...
17
            
18
            foreach ($this->list as $table =>$datas){
19
20
                foreach ($datas as $data){
21
22
                    $queryBuilder = $this->schema->getGrammarPath().'\QueryBuilder';
23
24
                    $query = (new $queryBuilder($this->schema,$table,$data))->handle();
25
26
                    $status =($query['result']!==false) ? true : false;
27
28
                    $results[]= [
29
                        'success'=>$status,
30
                        'file'=>$data->getFile(),
31
                        'table'=>$table,
32
                        'type'=>$query['type'],
33
                        'syntax'=>$query['syntax'],
34
                        'message'=>$query['message']
35
                    ];
36
                }
37
            }
38
39
            return $results;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $results does not seem to be defined for all execution paths leading up to this point.
Loading history...
40
        });
41
    }
42
43
    /**
44
     * @param callable $callback
45
     */
46
    public function errorHandler(callable $callback)
47
    {
48
        foreach ($this->list as $table => $objects)
49
        {
50
            foreach ($objects as $object)
51
            {
52
                if(count($object->getError())){
53
                    return 'error : '.$object->getFile().' -> '.$object->getError()[0].'';
54
                }
55
            }
56
        }
57
58
        return call_user_func($callback);
59
    }
60
}