1 | <?php |
||
2 | |||
3 | |||
4 | namespace database; |
||
5 | |||
6 | use database\DB; |
||
7 | |||
8 | /** |
||
9 | * Class Read |
||
10 | * @package src |
||
11 | */ |
||
12 | class Read |
||
13 | { |
||
14 | |||
15 | /** |
||
16 | * @var |
||
17 | */ |
||
18 | private $db; |
||
0 ignored issues
–
show
introduced
by
![]() |
|||
19 | /** |
||
20 | * @var |
||
21 | */ |
||
22 | private $table; |
||
23 | /** |
||
24 | * @var |
||
25 | */ |
||
26 | private $read; |
||
27 | /** |
||
28 | * @var |
||
29 | */ |
||
30 | private $statement; |
||
31 | /** |
||
32 | * @var |
||
33 | */ |
||
34 | private $terms; |
||
35 | |||
36 | |||
37 | /** |
||
38 | * @var |
||
39 | */ |
||
40 | private $query; |
||
41 | |||
42 | /** |
||
43 | * @var |
||
44 | */ |
||
45 | private $limit; |
||
0 ignored issues
–
show
|
|||
46 | |||
47 | /** |
||
48 | * @var |
||
49 | */ |
||
50 | private $offset; |
||
0 ignored issues
–
show
|
|||
51 | |||
52 | /** |
||
53 | * @var |
||
54 | */ |
||
55 | private $page; |
||
0 ignored issues
–
show
|
|||
56 | /** |
||
57 | * @var |
||
58 | */ |
||
59 | private $link; |
||
0 ignored issues
–
show
|
|||
60 | /** |
||
61 | * @var |
||
62 | */ |
||
63 | private $rows; |
||
64 | /** |
||
65 | * @var |
||
66 | */ |
||
67 | private $maxLinks; |
||
0 ignored issues
–
show
|
|||
68 | /** |
||
69 | * @var |
||
70 | */ |
||
71 | private $first; |
||
0 ignored issues
–
show
|
|||
72 | /** |
||
73 | * @var |
||
74 | */ |
||
75 | private $last; |
||
0 ignored issues
–
show
|
|||
76 | |||
77 | private $paginator; |
||
0 ignored issues
–
show
|
|||
78 | |||
79 | /** |
||
80 | * @var |
||
81 | */ |
||
82 | private $result; |
||
83 | |||
84 | |||
85 | /** |
||
86 | * Read constructor. |
||
87 | */ |
||
88 | public function __construct() |
||
89 | { |
||
90 | |||
91 | } |
||
92 | |||
93 | /** |
||
94 | * @return mixed |
||
95 | */ |
||
96 | public function getResult() |
||
97 | { |
||
98 | return $this->result; |
||
99 | } |
||
100 | |||
101 | /** |
||
102 | * @param $table |
||
103 | * @param null $parse |
||
0 ignored issues
–
show
|
|||
104 | * @return array |
||
105 | */ |
||
106 | |||
107 | public function query(string $query, string $parse = null) |
||
108 | { |
||
109 | if ($parse) { |
||
110 | parse_str($parse, $this->statement); |
||
111 | |||
112 | } |
||
113 | |||
114 | $this->query = $query; |
||
115 | $this->read = DB::connect()->prepare($this->query); |
||
116 | $this->read->execute($this->statement); |
||
117 | $this->rows = $this->read->rowCount(); |
||
118 | $this->result = $this->read->fetchAll(\PDO::FETCH_OBJ); |
||
119 | return $this; |
||
0 ignored issues
–
show
|
|||
120 | |||
121 | |||
122 | } |
||
123 | |||
124 | /** |
||
125 | * @param $table |
||
126 | * @return $this |
||
127 | */ |
||
128 | public function all($table) |
||
129 | { |
||
130 | $this->table = (string)$table; |
||
131 | |||
132 | |||
133 | $this->read = DB::connect()->prepare("SELECT * FROM {$this->table}"); |
||
134 | $this->read->execute(); |
||
135 | $this->rows = $this->read->rowCount(); |
||
136 | return $this->result = $this->read->fetchAll(\PDO::FETCH_OBJ); |
||
0 ignored issues
–
show
|
|||
137 | |||
138 | return $this; |
||
0 ignored issues
–
show
return $this is not reachable.
This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed. Unreachable code is most often the result of function fx() {
try {
doSomething();
return true;
}
catch (\Exception $e) {
return false;
}
return false;
}
In the above example, the last ![]() |
|||
139 | |||
140 | } |
||
141 | |||
142 | /** |
||
143 | * @param string $table |
||
144 | * @param string $terms |
||
145 | * @param string $parse |
||
146 | * @return mixed |
||
147 | */ |
||
148 | public function find(string $table, string $terms, string $parse) |
||
149 | { |
||
150 | $this->table = $table; |
||
151 | $this->terms = $terms; |
||
152 | |||
153 | if ($parse) { |
||
154 | parse_str($parse, $this->statement); |
||
155 | } |
||
156 | |||
157 | try { |
||
158 | $this->read = DB::connect()->prepare("SELECT * FROM {$this->table} {$this->terms}"); |
||
159 | $this->read->execute($this->statement); |
||
160 | $this->rows = $this->read->rowCount(); |
||
161 | return $this->result = $this->read->fetchAll(\PDO::FETCH_OBJ); |
||
162 | } catch (\PDOException $e) { |
||
163 | echo $e->getMessage() . " in " . $e->getFile(); |
||
164 | } |
||
165 | |||
166 | return $this; |
||
167 | } |
||
168 | |||
169 | /** |
||
170 | * @return int |
||
171 | */ |
||
172 | public function getRowCount() |
||
173 | { |
||
174 | return $this->rows; |
||
175 | |||
176 | } |
||
177 | |||
178 | |||
179 | |||
180 | } |