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

Pushing::handle()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 20
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 9
c 1
b 0
f 0
nc 3
nop 0
dl 0
loc 20
rs 9.9666
1
<?php
2
3
namespace Migratio\Resource\PushManager;
4
5
use Migratio\Schema;
6
use Migratio\SchemaCapsule;
7
use Migratio\Resource\BaseManager;
8
use Migratio\Contract\QueryBaseContract;
9
use Migratio\Resource\Request\BaseRequestProcess;
10
11
class Pushing extends BaseManager
12
{
13
    use PushingProcess;
14
15
    /**
16
     * @var $list array
0 ignored issues
show
Documentation Bug introduced by
The doc comment $list at position 0 could not be parsed: Unknown type name '$list' at position 0 in $list.
Loading history...
17
     */
18
    protected $list = array();
19
20
    /**
21
     * @return array
22
     */
23
    protected function getAllFiles()
24
    {
25
        BaseRequestProcess::$paths=$this->config['paths'];
26
27
        return BaseRequestProcess::getAllFiles();
28
    }
29
30
    /**
31
     * @return mixed
32
     */
33
    public function handle()
34
    {
35
        foreach ($this->tableFilters() as $table=>$files){
36
37
            $table = strtolower($table);
38
39
            foreach ($files as $file) {
40
41
                $getClassName = preg_replace('@(\d+)_@is','',$file);
42
                $className = $this->getClassName($getClassName);
43
44
                $require = require_once ($file);
0 ignored issues
show
Unused Code introduced by
The assignment to $require is dead and can be removed.
Loading history...
45
46
                $capsule = new SchemaCapsule($this->config,$file,$table);
47
48
                $this->list[$table][]=(new $className)->up($capsule);
49
            }
50
        }
51
52
        return $this->processHandler();
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->processHandler() targeting Migratio\Resource\PushMa...shing::processHandler() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
53
    }
54
55
    protected function tableFilters()
56
    {
57
        $tables = $this->schema->params['tables'];
58
59
        $list = [];
60
61
        foreach ($this->getAllFiles() as $table=>$allFile) {
62
63
            if(count($tables)){
64
65
                if(in_array($table,$tables)){
66
                    $list[$table]=$allFile;
67
                }
68
            }
69
        }
70
71
        return (count($list)) ? $list : $this->getAllFiles();
72
    }
73
74
    /**
75
     * @param $file
76
     * @return mixed|string
77
     */
78
    protected function getClassName($file)
79
    {
80
        $className = str_replace(".php","",BaseRequestProcess::getFileName($file));
81
82
        return $className;
83
    }
84
}