Test Setup Failed
Push — master ( 4c0917...56b13c )
by Php Easy Api
04:17
created

BaseManager::getClassName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Migratio\Resource;
4
5
use Migratio\Schema;
6
use Migratio\Contract\QueryBaseContract;
7
use Migratio\Contract\ColumnsProcessContract;
8
use Migratio\Resource\Request\BaseRequestProcess;
9
10
class BaseManager
11
{
12
    /**
13
     * @var $connection QueryBaseContract
0 ignored issues
show
Documentation Bug introduced by
The doc comment $connection at position 0 could not be parsed: Unknown type name '$connection' at position 0 in $connection.
Loading history...
14
     */
15
    protected $connection;
16
17
    /**
18
     * @var $schema Schema
0 ignored issues
show
Documentation Bug introduced by
The doc comment $schema at position 0 could not be parsed: Unknown type name '$schema' at position 0 in $schema.
Loading history...
19
     */
20
    protected $schema;
21
22
    /**
23
     * @var $config
0 ignored issues
show
Documentation Bug introduced by
The doc comment $config at position 0 could not be parsed: Unknown type name '$config' at position 0 in $config.
Loading history...
24
     */
25
    protected $config;
26
27
    /**
28
     * @var null|object
29
     */
30
    protected $queryBuilder;
31
32
    /**
33
     * Pulling constructor.
34
     * @param $schema Schema
35
     */
36
    public function __construct($schema)
37
    {
38
        $this->schema       = $schema;
39
        $this->config       = $this->schema->getConfig();
40
        $this->connection   = $this->schema->getConnection();
41
42
        $this->queryBuilder = $this->schema->getGrammarPath().'\QueryBuilder';
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->schema->getGrammarPath() . '\QueryBuilder' of type string is incompatible with the declared type null|object of property $queryBuilder.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
43
    }
44
45
    /**
46
     * get all files
47
     *
48
     * @return array
49
     */
50
    public function getAllFiles()
51
    {
52
        BaseRequestProcess::$paths = $this->config['paths'];
53
54
        return BaseRequestProcess::getAllFiles();
55
    }
56
57
    /**
58
     * @param $file
59
     * @return mixed|string
60
     */
61
    protected function getClassName($file)
62
    {
63
        $className = str_replace(".php","",BaseRequestProcess::getFileName($file));
64
65
        return $className;
66
    }
67
68
    /**
69
     * @return ColumnsProcessContract
70
     */
71
    public function getColumns()
72
    {
73
        $tables = $this->schema->params['tables'];
74
75
        return $this->connection->getColumns($tables);
76
    }
77
78
    /**
79
     * get stub path
80
     *
81
     * @return string
82
     */
83
    public function getStubPath()
84
    {
85
        return __DIR__.''.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'Stub';
86
    }
87
88
    /**
89
     * @return mixed
90
     */
91
    public function getTables()
92
    {
93
        return $this->connection->getTables();
94
    }
95
96
    /**
97
     * get query builder
98
     *
99
     * @param null|string $table
100
     * @param null|string $data
101
     * @return mixed
102
     */
103
    public function queryBuilder($table=null,$data=null)
104
    {
105
        $queryBuilder = $this->queryBuilder;
106
107
        return new $queryBuilder($this->schema,$table,$data);
108
    }
109
110
    /**
111
     * get table filters
112
     *
113
     * @return array
114
     */
115
    public function tableFilters()
116
    {
117
        $tables = $this->schema->params['tables'];
118
119
        $list = [];
120
121
        foreach ($this->getAllFiles() as $table=>$allFile) {
122
123
            if(count($tables)){
124
125
                if(in_array($table,$tables)){
126
                    $list[$table]=$allFile;
127
                }
128
            }
129
        }
130
131
        return (count($list)) ? $list : $this->getAllFiles();
132
    }
133
134
    /**
135
     * @param null|string $path
136
     * @param array $params
137
     * @return mixed
138
     */
139
    public function getContentFile($path,$params=array())
140
    {
141
        $dt = fopen($path, "r");
142
        $content = fread($dt, filesize($path));
0 ignored issues
show
Bug introduced by
It seems like $dt can also be of type false; however, parameter $handle of fread() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

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

142
        $content = fread(/** @scrutinizer ignore-type */ $dt, filesize($path));
Loading history...
143
        fclose($dt);
0 ignored issues
show
Bug introduced by
It seems like $dt can also be of type false; however, parameter $handle of fclose() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

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

143
        fclose(/** @scrutinizer ignore-type */ $dt);
Loading history...
144
145
        foreach ($params as $key=>$value){
146
147
            $content=str_replace("__".$key."__",$value,$content);
148
        }
149
150
        return $content;
151
    }
152
153
}
154