Skip to content

Commit 1b2988f

Browse files
committed
Fixed minor style issues in generated queries.
Introduced options for builders. Data types are lower case in CREATE TABLE statements, but in any other case they continue to be upper case. Formatter uses 2 spaces instead of 4 for indentation as specified in the MySQL Coding Guidelines. https://dev.mysql.com/doc/internals/en/indentation-spacing.html.
1 parent 14c54da commit 1b2988f

24 files changed

+62
-34
lines changed

src/Component.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,13 @@ public static function parse(
7070
* `static::parse`.
7171
*
7272
* @param mixed $component The component to be built.
73+
* @param array $options Parameters for building.
7374
*
7475
* @throws \Exception Not implemented yet.
7576
*
7677
* @return string
7778
*/
78-
public static function build($component)
79+
public static function build($component, array $options = array())
7980
{
8081
// This method should be abstract, but it can't be both static and
8182
// abstract.

src/Components/AlterOperation.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,11 @@ public static function parse(Parser $parser, TokensList $list, array $options =
210210

211211
/**
212212
* @param AlterOperation $component The component to be built.
213+
* @param array $options Parameters for building.
213214
*
214215
* @return string
215216
*/
216-
public static function build($component)
217+
public static function build($component, array $options = array())
217218
{
218219
$ret = $component->options . ' ';
219220
if ((isset($component->field)) && ($component->field !== '')) {

src/Components/Array2d.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,11 @@ public static function parse(Parser $parser, TokensList $list, array $options =
124124

125125
/**
126126
* @param ArrayObj[] $component The component to be built.
127+
* @param array $options Parameters for building.
127128
*
128129
* @return string
129130
*/
130-
public static function build($component)
131+
public static function build($component, array $options = array())
131132
{
132133
return ArrayObj::build($component);
133134
}

src/Components/ArrayObj.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,11 @@ public static function parse(Parser $parser, TokensList $list, array $options =
143143

144144
/**
145145
* @param ArrayObj|ArrayObj[] $component The component to be built.
146+
* @param array $options Parameters for building.
146147
*
147148
* @return string
148149
*/
149-
public static function build($component)
150+
public static function build($component, array $options = array())
150151
{
151152
if (is_array($component)) {
152153
return implode(', ', $component);

src/Components/Condition.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,11 @@ public static function parse(Parser $parser, TokensList $list, array $options =
197197

198198
/**
199199
* @param Condition[] $component The component to be built.
200+
* @param array $options Parameters for building.
200201
*
201202
* @return string
202203
*/
203-
public static function build($component)
204+
public static function build($component, array $options = array())
204205
{
205206
if (is_array($component)) {
206207
return implode(' ', $component);

src/Components/CreateDefinition.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,13 +272,14 @@ public static function parse(Parser $parser, TokensList $list, array $options =
272272

273273
/**
274274
* @param CreateDefinition|CreateDefinition[] $component The component to be built.
275+
* @param array $options Parameters for building.
275276
*
276277
* @return string
277278
*/
278-
public static function build($component)
279+
public static function build($component, array $options = array())
279280
{
280281
if (is_array($component)) {
281-
return "(\n" . implode(",\n", $component) . "\n)";
282+
return "(\n " . implode(",\n ", $component) . "\n)";
282283
} else {
283284
$tmp = '';
284285

@@ -291,7 +292,10 @@ public static function build($component)
291292
}
292293

293294
if (!empty($component->type)) {
294-
$tmp .= $component->type . ' ';
295+
$tmp .= DataType::build(
296+
$component->type,
297+
array('lowercase' => true)
298+
) . ' ';
295299
}
296300

297301
if (!empty($component->key)) {

src/Components/DataType.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,16 +151,20 @@ public static function parse(Parser $parser, TokensList $list, array $options =
151151

152152
/**
153153
* @param DataType $component The component to be built.
154+
* @param array $options Parameters for building.
154155
*
155156
* @return string
156157
*/
157-
public static function build($component)
158+
public static function build($component, array $options = array())
158159
{
159-
$tmp = '';
160+
$name = (empty($options['lowercase'])) ?
161+
$component->name : strtolower($component->name);
162+
163+
$parameters = '';
160164
if (!empty($component->parameters)) {
161-
$tmp = '(' . implode(', ', $component->parameters) . ')';
165+
$parameters = '(' . implode(',', $component->parameters) . ')';
162166
}
163167

164-
return trim($component->name . $tmp . ' ' . $component->options);
168+
return trim($name . $parameters . ' ' . $component->options);
165169
}
166170
}

src/Components/Expression.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,10 +351,11 @@ public static function parse(Parser $parser, TokensList $list, array $options =
351351

352352
/**
353353
* @param Expression|Expression[] $component The component to be built.
354+
* @param array $options Parameters for building.
354355
*
355356
* @return string
356357
*/
357-
public static function build($component)
358+
public static function build($component, array $options = array())
358359
{
359360
if (is_array($component)) {
360361
return implode($component, ', ');

src/Components/ExpressionArray.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,11 @@ public static function parse(Parser $parser, TokensList $list, array $options =
106106

107107
/**
108108
* @param Expression[] $component The component to be built.
109+
* @param array $options Parameters for building.
109110
*
110111
* @return string
111112
*/
112-
public static function build($component)
113+
public static function build($component, array $options = array())
113114
{
114115
$ret = array();
115116
foreach ($component as $frag) {

src/Components/FunctionCall.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,11 @@ public static function parse(Parser $parser, TokensList $list, array $options =
115115

116116
/**
117117
* @param FunctionCall $component The component to be built.
118+
* @param array $options Parameters for building.
118119
*
119120
* @return string
120121
*/
121-
public static function build($component)
122+
public static function build($component, array $options = array())
122123
{
123124
return $component->name . $component->parameters;
124125
}

0 commit comments

Comments
 (0)