Skip to content

Commit 0fe70cd

Browse files
Update BaseBuilder.php
1 parent 9d0de0e commit 0fe70cd

File tree

1 file changed

+89
-6
lines changed

1 file changed

+89
-6
lines changed

src/Config/BaseBuilder.php

Lines changed: 89 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use DatabaseFactory\Contracts;
77

88
/**
9-
* SQL Module DB
9+
* SQL BaseBuilder
1010
*
1111
* @package DatabaseFactory\Modules
1212
* @author Jason Napolitano
@@ -17,6 +17,7 @@
1717
*/
1818
class BaseBuilder implements Contracts\BaseBuilderInterface
1919
{
20+
// @todo - reimplement as non-constants (props as an array, perhaps?)
2021
protected const COUNT = 'COUNT';
2122
protected const WHERE = ' WHERE ';
2223
protected const LIKE = ' LIKE ';
@@ -84,7 +85,7 @@ protected static function strip(string $string): string
8485
*/
8586
protected static function doubleQuote(string $string): string
8687
{
87-
return self::DBLQT . Helpers\Str::stripQuotes($string) . self::DBLQT;
88+
return self::DBLQT . self::strip($string) . self::DBLQT;
8889
}
8990

9091
/**
@@ -96,7 +97,7 @@ protected static function doubleQuote(string $string): string
9697
*/
9798
protected static function singleQuote(string $string): string
9899
{
99-
return self::SGLQT . Helpers\Str::stripQuotes($string) . self::SGLQT;
100+
return self::SGLQT . self::strip($string) . self::SGLQT;
100101
}
101102

102103
/**
@@ -122,43 +123,103 @@ protected static function decrement(int $value = 0): int
122123
{
123124
return $value - self::ONE;
124125
}
126+
127+
/**
128+
* Implement FIND_IN_SET(...)
129+
*
130+
* @param string $field
131+
* @param mixed $value
132+
*
133+
* @return string
134+
*/
125135
public static function contains(string $field, $value): string
126136
{
127137
return self::WHERE . 'find_in_set' . self::OPPAR . self::SGLQT . $value . self::SGLQT . self::SEPARATOR . $field . self::CLPAR > 0;
128138
}
129139

140+
/**
141+
* Implement WHERE
142+
*
143+
* @param string $columns
144+
*
145+
* @return string
146+
*/
130147
public static function where(string $columns): string
131148
{
132149
return static::WHERE . $columns;
133150
}
134151

152+
/**
153+
* Implement LIKE
154+
*
155+
* @param string $pattern
156+
* @param bool $not
157+
*
158+
* @return string
159+
*/
135160
public static function like(string $pattern, bool $not = false): string
136161
{
137162
$notStr = $not ? self::NOT : self::EMPTY;
138163
return $notStr . self::LIKE . static::SGLQT . self::PERC . $pattern . self::PERC . static::SGLQT;
139164
}
140165

166+
/**
167+
* Implement SELECT
168+
*
169+
* @param string $columns
170+
* @param bool $space
171+
*
172+
* @return string
173+
*/
141174
public static function select(string $columns, bool $space = false): string
142175
{
143176
$select = $space ? self::SPC : self::EMPTY;
144177
return self::SELECT . self::SPC . $columns . $select;
145178
}
146179

180+
/**
181+
* Implement LIMIT
182+
*
183+
* @param int $rows
184+
*
185+
* @return string
186+
*/
147187
public static function limit(int $rows): string
148188
{
149189
return self::LIMIT . self::SPC . $rows;
150190
}
151191

152-
public static function offset(int $count): string
192+
/**
193+
* Implement OFFSET
194+
*
195+
* @param int $rows
196+
*
197+
* @return string
198+
*/
199+
public static function offset(int $rows): string
153200
{
154-
return self::OFFSET . self::SPC . $count;
201+
return self::OFFSET . self::SPC . $rows;
155202
}
156203

157-
public static function count($values = self::ALL): string
204+
/**
205+
* Implement COUNT
206+
*
207+
* @param string $values
208+
*
209+
* @return string
210+
*/
211+
public static function count(string $values = self::ALL): string
158212
{
159213
return self::COUNT . self::OPPAR . $values . self::CLPAR;
160214
}
161215

216+
/**
217+
* Determine values for a query
218+
*
219+
* @param array $values
220+
*
221+
* @return string
222+
*/
162223
public static function values(array $values): string
163224
{
164225
$string = self::OPPAR;
@@ -169,16 +230,38 @@ public static function values(array $values): string
169230
return str_replace($string, '?`, )', '?`)');
170231
}
171232

233+
/**
234+
* Determine columns of a query
235+
*
236+
* @param array $columns
237+
*
238+
* @return string
239+
*/
172240
public static function columns(array $columns): string
173241
{
174242
return rtrim($columns[0], self::SEPARATOR);
175243
}
176244

245+
/**
246+
* Implement FROM
247+
*
248+
* @param string $table
249+
*
250+
* @return string
251+
*/
177252
public static function from(string $table = null): string
178253
{
179254
return self::FROM . $table ? : '';
180255
}
181256

257+
/**
258+
* Implement JOIN
259+
*
260+
* @param string $params
261+
* @param array $on
262+
*
263+
* @return string
264+
*/
182265
public static function join(string $params, array $on): string
183266
{
184267
return static::SPC . static::JOIN . $params . self::ON . rtrim(implode(self::EQUALS, $on), self::EQUALS);

0 commit comments

Comments
 (0)