Query::select()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 2
cts 2
cp 1
rs 9.9332
c 0
b 0
f 0
cc 1
nc 1
nop 6
crap 1
1
<?php
2
/*
3
 * The MIT License
4
 *
5
 * Copyright 2017 David Schoenbauer <[email protected]>.
6
 *
7
 * Permission is hereby granted, free of charge, to any person obtaining a copy
8
 * of this software and associated documentation files (the "Software"), to deal
9
 * in the Software without restriction, including without limitation the rights
10
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
 * copies of the Software, and to permit persons to whom the Software is
12
 * furnished to do so, subject to the following conditions:
13
 *
14
 * The above copyright notice and this permission notice shall be included in
15
 * all copies or substantial portions of the Software.
16
 *
17
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
 * THE SOFTWARE.
24
 */
25
namespace DSchoenbauer\Sql;
26
27
use DSchoenbauer\Sql\Command\Create;
28
use DSchoenbauer\Sql\Command\Delete;
29
use DSchoenbauer\Sql\Command\Select;
30
use DSchoenbauer\Sql\Command\Update;
31
use DSchoenbauer\Sql\Where\WhereStatementInterface;
32
use PDO;
33
34
/**
35
 * a facade object that allows easier implementation of the SQL library
36
 *
37
 * @author David Schoenbauer <[email protected]>
38
 *
39
 */
40
class Query
41
{
42
43
    /**
44
     * provides a means for functional access to the objects of this library
45
     * @return Query a new instance of this object
46
     * @since v1.0.0
47
     */
48 1
    public static function with()
49
    {
50 1
        return new static();
51
    }
52
53
    /**
54
     * adds new data into a PDO connected resource
55
     * @param string $table table with which you wish to append to
56
     * @param array $data  a single level associative array containing keys that
57
     * represent the fields and values that represent new values to be added
58
     * into the table
59
     * @return Create a create object that manages the addition of new records
60
     * @since v1.0.0
61
     */
62 1
    public function create($table, array $data)
63
    {
64 1
        return new Create($table, $data);
65
    }
66
67
    /**
68
     * retrieves data from a PDO connected resource
69
     * @param string $table name of the table that houses the data
70
     * @param array $fields optional default value: empty array - defines which
71
     * fields are returned if no fields defined a star will be used
72
     * @param null|WhereStatementInterface $where optional default value: null -
73
     * object used to limit the returned results
74
     * @param integer $fetchStyle optional default value: PDO::FETCH_ASSOC -
75
     * sets how the PDO statement will return records
76
     * @param boolean $fetchFlat optional default value: false - true will
77
     * return one record, false will return all records
78
     * @param mixed $defaultValue optional default value: empty array -
79
     * value to be returned on query failure
80
     * @return Select the select object responsible for retrieving records
81
     * @since v1.0.0
82
     */
83 1
    public function select(
84
        $table,
85
        $fields = [],
86
        WhereStatementInterface $where = null,
87
        $fetchStyle = PDO::FETCH_ASSOC,
88
        $fetchFlat = false,
89
        $defaultValue = []
90
    ) {
91 1
        return new Select($table, $fields, $where, $fetchStyle, $fetchFlat, $defaultValue);
92
    }
93
94
    /**
95
     * changes values of existing data in a PDO connected resource
96
     * @param string $table table with which you wish to update
97
     * @param array $data a single level associative array containing keys that
98
     * represent the fields and values that represent new values to be updated
99
     * into the table
100
     * @param null|WhereStatementInterface $where an object that is designed to
101
     * return a where statement to limit the data that is affected by the update
102
     * @return Update the update object responsible to handling the update of
103
     * persistent records.
104
     * @since v1.0.0
105
     */
106 1
    public function update($table, array $data, WhereStatementInterface $where = null)
107
    {
108 1
        return new Update($table, $data, $where);
109
    }
110
111
    /**
112
     * removes records from a PDO connected resource
113
     * @param string $table table with which you wish to remove records from
114
     * @param null|WhereStatementInterface $where  an object that is designed to
115
     * return a where statement to limit the data that is affected by the delete
116
     * @return Delete the delete object responsible for handling removal of
117
     * persistent records
118
     * @since v1.0.0
119
     */
120 1
    public function delete($table, WhereStatementInterface $where = null)
121
    {
122 1
        return new Delete($table, $where);
123
    }
124
}
125