Passed
Push — master ( 423021...c8976e )
by guilherme
01:27
created

Read::all()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 9
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
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
The private property $db is not used, and could be removed.
Loading history...
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
     * @var
37
     */
38
    private $result;
39
40
    /**
41
     * @var \PDOStatement
42
     */
43
    private $select;
44
45
    private $query;
46
47
48
    /**
49
     * Read constructor.
50
     */
51
    public function __construct()
52
    {
53
54
    }
55
56
    /**
57
     * @return mixed
58
     */
59
    public function getResult()
60
    {
61
        return $this->result;
62
    }
63
64
    /**
65
     * @param $table
66
     * @param null $parse
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $parse is correct as it would always require null to be passed?
Loading history...
67
     * @return array
68
     */
69
70
    public function query(string $query, string $parse = null)
71
    {
72
        if ($parse){
73
            parse_str($parse, $this->statement);
74
75
        }
76
77
        $this->query = $query;
78
        $this->read = DB::connect()->prepare($this->query);
79
        $this->read->execute($this->statement);
80
        $this->result = $this->read->fetchAll(\PDO::FETCH_OBJ);
81
82
83
84
    }
85
86
    public function all($table)
87
    {
88
        $this->table = (string)$table;
89
90
91
92
        $this->read = DB::connect()->prepare("SELECT * FROM {$this->table}");
93
        $this->read->execute();
94
        return $this->result = $this->read->fetchAll(\PDO::FETCH_OBJ);
95
96
97
    }
98
99
    /**
100
     * @param string $table
101
     * @param string $terms
102
     * @param string $parse
103
     * @return mixed
104
     */
105
    public function find(string $table, string $terms, string $parse)
106
    {
107
        $this->table = $table;
108
        $this->terms = $terms;
109
110
        if ($parse) {
111
            parse_str($parse, $this->statement);
112
        }
113
114
        try {
115
            $this->read = DB::connect()->prepare("SELECT * FROM {$this->table} {$this->terms}");
116
            $this->read->execute($this->statement);
117
            return $this->result = $this->read->fetchAll(\PDO::FETCH_OBJ);
118
        } catch (\PDOException $e) {
119
            echo $e->getMessage() . " in " . $e->getFile();
120
        }
121
    }
122
123
    public function getRowCount()
124
    {
125
        return $this->select->rowCount();
126
    }
127
128
129
}