Skip to content

Commit

Permalink
Merge pull request #482 from kamil-tekiela/Drop-$options
Browse files Browse the repository at this point in the history
Drop $options param from Component::build
  • Loading branch information
MauricioFauth committed Jun 17, 2023
2 parents 875ce2b + 1ae45d6 commit da08ab2
Show file tree
Hide file tree
Showing 27 changed files with 50 additions and 78 deletions.
5 changes: 2 additions & 3 deletions src/Component.php
Expand Up @@ -32,8 +32,7 @@ public static function parse(Parser $parser, TokensList $list, array $options =
*
* In other words, this function represents the inverse function of {@see Component::parse()}.
*
* @param mixed $component the component to be built
* @param array<string, mixed> $options parameters for building
* @param mixed $component the component to be built
*/
public static function build($component, array $options = []): string;
public static function build($component): string;
}
5 changes: 2 additions & 3 deletions src/Components/AlterOperation.php
Expand Up @@ -520,10 +520,9 @@ public static function parse(Parser $parser, TokensList $list, array $options =
}

/**
* @param AlterOperation $component the component to be built
* @param array<string, mixed> $options parameters for building
* @param AlterOperation $component the component to be built
*/
public static function build($component, array $options = []): string
public static function build($component): string
{
// Specific case of RENAME COLUMN that insert the field between 2 options.
$afterFieldsOptions = new OptionsArray();
Expand Down
5 changes: 2 additions & 3 deletions src/Components/Array2d.php
Expand Up @@ -112,10 +112,9 @@ public static function parse(Parser $parser, TokensList $list, array $options =
}

/**
* @param ArrayObj[] $component the component to be built
* @param array<string, mixed> $options parameters for building
* @param ArrayObj[] $component the component to be built
*/
public static function build($component, array $options = []): string
public static function build($component): string
{
return ArrayObj::build($component);
}
Expand Down
5 changes: 2 additions & 3 deletions src/Components/ArrayObj.php
Expand Up @@ -159,10 +159,9 @@ public static function parse(Parser $parser, TokensList $list, array $options =
}

/**
* @param ArrayObj|ArrayObj[] $component the component to be built
* @param array<string, mixed> $options parameters for building
* @param ArrayObj|ArrayObj[] $component the component to be built
*/
public static function build($component, array $options = []): string
public static function build($component): string
{
if (is_array($component)) {
return implode(', ', $component);
Expand Down
5 changes: 2 additions & 3 deletions src/Components/CaseExpression.php
Expand Up @@ -253,10 +253,9 @@ public static function parse(Parser $parser, TokensList $list, array $options =
}

/**
* @param CaseExpression $component the component to be built
* @param array<string, mixed> $options parameters for building
* @param CaseExpression $component the component to be built
*/
public static function build($component, array $options = []): string
public static function build($component): string
{
$ret = 'CASE ';
if (isset($component->value)) {
Expand Down
5 changes: 2 additions & 3 deletions src/Components/Condition.php
Expand Up @@ -221,10 +221,9 @@ public static function parse(Parser $parser, TokensList $list, array $options =
}

/**
* @param Condition[] $component the component to be built
* @param array<string, mixed> $options parameters for building
* @param Condition[] $component the component to be built
*/
public static function build($component, array $options = []): string
public static function build($component): string
{
if (is_array($component)) {
return implode(' ', $component);
Expand Down
9 changes: 3 additions & 6 deletions src/Components/CreateDefinition.php
Expand Up @@ -319,9 +319,8 @@ public static function parse(Parser $parser, TokensList $list, array $options =

/**
* @param CreateDefinition|CreateDefinition[] $component the component to be built
* @param array<string, mixed> $options parameters for building
*/
public static function build($component, array $options = []): string
public static function build($component): string
{
if (is_array($component)) {
return "(\n " . implode(",\n ", $component) . "\n)";
Expand All @@ -338,10 +337,8 @@ public static function build($component, array $options = []): string
}

if (! empty($component->type)) {
$tmp .= DataType::build(
$component->type,
['lowercase' => true]
) . ' ';
$component->type->lowercase = true;
$tmp .= DataType::build($component->type) . ' ';
}

if (! empty($component->key)) {
Expand Down
10 changes: 5 additions & 5 deletions src/Components/DataType.php
Expand Up @@ -72,6 +72,8 @@ final class DataType implements Component
*/
public $options;

public bool $lowercase = false;

/**
* @param string $name the name of this data type
* @param int[]|string[] $parameters the parameters (size or possible values)
Expand Down Expand Up @@ -153,13 +155,11 @@ public static function parse(Parser $parser, TokensList $list, array $options =
}

/**
* @param DataType $component the component to be built
* @param array<string, mixed> $options parameters for building
* @param DataType $component the component to be built
*/
public static function build($component, array $options = []): string
public static function build($component): string
{
$name = empty($options['lowercase']) ?
$component->name : strtolower($component->name);
$name = $component->lowercase ? strtolower($component->name) : $component->name;

$parameters = '';
if ($component->parameters !== []) {
Expand Down
3 changes: 1 addition & 2 deletions src/Components/Expression.php
Expand Up @@ -448,9 +448,8 @@ public static function parse(Parser $parser, TokensList $list, array $options =

/**
* @param Expression|Expression[] $component the component to be built
* @param array<string, mixed> $options parameters for building
*/
public static function build($component, array $options = []): string
public static function build($component): string
{
if (is_array($component)) {
return implode(', ', $component);
Expand Down
5 changes: 2 additions & 3 deletions src/Components/ExpressionArray.php
Expand Up @@ -117,10 +117,9 @@ public static function parse(Parser $parser, TokensList $list, array $options =
}

/**
* @param Expression[] $component the component to be built
* @param array<string, mixed> $options parameters for building
* @param Expression[] $component the component to be built
*/
public static function build($component, array $options = []): string
public static function build($component): string
{
$ret = [];
foreach ($component as $frag) {
Expand Down
5 changes: 2 additions & 3 deletions src/Components/FunctionCall.php
Expand Up @@ -103,10 +103,9 @@ public static function parse(Parser $parser, TokensList $list, array $options =
}

/**
* @param FunctionCall $component the component to be built
* @param array<string, mixed> $options parameters for building
* @param FunctionCall $component the component to be built
*/
public static function build($component, array $options = []): string
public static function build($component): string
{
return $component->name . $component->parameters;
}
Expand Down
3 changes: 1 addition & 2 deletions src/Components/GroupKeyword.php
Expand Up @@ -113,9 +113,8 @@ public static function parse(Parser $parser, TokensList $list, array $options =

/**
* @param GroupKeyword|GroupKeyword[] $component the component to be built
* @param array<string, mixed> $options parameters for building
*/
public static function build($component, array $options = []): string
public static function build($component): string
{
if (is_array($component)) {
return implode(', ', $component);
Expand Down
3 changes: 1 addition & 2 deletions src/Components/IndexHint.php
Expand Up @@ -179,9 +179,8 @@ public static function parse(Parser $parser, TokensList $list, array $options =

/**
* @param IndexHint|IndexHint[] $component the component to be built
* @param array<string, mixed> $options parameters for building
*/
public static function build($component, array $options = []): string
public static function build($component): string
{
if (is_array($component)) {
return implode(' ', $component);
Expand Down
7 changes: 3 additions & 4 deletions src/Components/IntoKeyword.php
Expand Up @@ -259,10 +259,9 @@ public function parseFileOptions(Parser $parser, TokensList $list, $keyword = 'F
}

/**
* @param IntoKeyword $component the component to be built
* @param array<string, mixed> $options parameters for building
* @param IntoKeyword $component the component to be built
*/
public static function build($component, array $options = []): string
public static function build($component): string
{
if ($component->dest instanceof Expression) {
$columns = ! empty($component->columns) ? '(`' . implode('`, `', $component->columns) . '`)' : '';
Expand All @@ -282,7 +281,7 @@ public static function build($component, array $options = []): string
$ret .= ' ' . $fieldsOptionsString;
}

$linesOptionsString = OptionsArray::build($component->linesOptions, ['expr' => true]);
$linesOptionsString = OptionsArray::build($component->linesOptions);
if (trim($linesOptionsString) !== '') {
$ret .= ' LINES ' . $linesOptionsString;
}
Expand Down
5 changes: 2 additions & 3 deletions src/Components/JoinKeyword.php
Expand Up @@ -198,10 +198,9 @@ public static function parse(Parser $parser, TokensList $list, array $options =
}

/**
* @param JoinKeyword[] $component the component to be built
* @param array<string, mixed> $options parameters for building
* @param JoinKeyword[] $component the component to be built
*/
public static function build($component, array $options = []): string
public static function build($component): string
{
$ret = [];
foreach ($component as $c) {
Expand Down
5 changes: 2 additions & 3 deletions src/Components/Key.php
Expand Up @@ -264,10 +264,9 @@ public static function parse(Parser $parser, TokensList $list, array $options =
}

/**
* @param Key $component the component to be built
* @param array<string, mixed> $options parameters for building
* @param Key $component the component to be built
*/
public static function build($component, array $options = []): string
public static function build($component): string
{
$ret = $component->type . ' ';
if (! empty($component->name)) {
Expand Down
5 changes: 2 additions & 3 deletions src/Components/Limit.php
Expand Up @@ -109,10 +109,9 @@ public static function parse(Parser $parser, TokensList $list, array $options =
}

/**
* @param Limit $component the component to be built
* @param array<string, mixed> $options parameters for building
* @param Limit $component the component to be built
*/
public static function build($component, array $options = []): string
public static function build($component): string
{
return $component->offset . ', ' . $component->rowCount;
}
Expand Down
3 changes: 1 addition & 2 deletions src/Components/LockExpression.php
Expand Up @@ -96,9 +96,8 @@ public static function parse(Parser $parser, TokensList $list, array $options =

/**
* @param LockExpression|LockExpression[] $component the component to be built
* @param array<string, mixed> $options parameters for building
*/
public static function build($component, array $options = []): string
public static function build($component): string
{
if (is_array($component)) {
return implode(', ', $component);
Expand Down
5 changes: 2 additions & 3 deletions src/Components/OptionsArray.php
Expand Up @@ -275,10 +275,9 @@ public static function parse(Parser $parser, TokensList $list, array $options =
}

/**
* @param OptionsArray $component the component to be built
* @param array<string, mixed> $options parameters for building
* @param OptionsArray $component the component to be built
*/
public static function build($component, array $options = []): string
public static function build($component): string
{
if (empty($component->options)) {
return '';
Expand Down
3 changes: 1 addition & 2 deletions src/Components/OrderKeyword.php
Expand Up @@ -118,9 +118,8 @@ public static function parse(Parser $parser, TokensList $list, array $options =

/**
* @param OrderKeyword|OrderKeyword[] $component the component to be built
* @param array<string, mixed> $options parameters for building
*/
public static function build($component, array $options = []): string
public static function build($component): string
{
if (is_array($component)) {
return implode(', ', $component);
Expand Down
3 changes: 1 addition & 2 deletions src/Components/ParameterDefinition.php
Expand Up @@ -142,9 +142,8 @@ public static function parse(Parser $parser, TokensList $list, array $options =

/**
* @param ParameterDefinition[] $component the component to be built
* @param array<string, mixed> $options parameters for building
*/
public static function build($component, array $options = []): string
public static function build($component): string
{
if (is_array($component)) {
return '(' . implode(', ', $component) . ')';
Expand Down
3 changes: 1 addition & 2 deletions src/Components/PartitionDefinition.php
Expand Up @@ -225,9 +225,8 @@ public static function parse(Parser $parser, TokensList $list, array $options =

/**
* @param PartitionDefinition|PartitionDefinition[] $component the component to be built
* @param array<string, mixed> $options parameters for building
*/
public static function build($component, array $options = []): string
public static function build($component): string
{
if (is_array($component)) {
return "(\n" . implode(",\n", $component) . "\n)";
Expand Down
5 changes: 2 additions & 3 deletions src/Components/Reference.php
Expand Up @@ -140,10 +140,9 @@ public static function parse(Parser $parser, TokensList $list, array $options =
}

/**
* @param Reference $component the component to be built
* @param array<string, mixed> $options parameters for building
* @param Reference $component the component to be built
*/
public static function build($component, array $options = []): string
public static function build($component): string
{
return trim(
$component->table
Expand Down
5 changes: 2 additions & 3 deletions src/Components/RenameOperation.php
Expand Up @@ -149,10 +149,9 @@ public static function parse(Parser $parser, TokensList $list, array $options =
}

/**
* @param RenameOperation $component the component to be built
* @param array<string, mixed> $options parameters for building
* @param RenameOperation $component the component to be built
*/
public static function build($component, array $options = []): string
public static function build($component): string
{
if (is_array($component)) {
return implode(', ', $component);
Expand Down
3 changes: 1 addition & 2 deletions src/Components/SetOperation.php
Expand Up @@ -141,9 +141,8 @@ public static function parse(Parser $parser, TokensList $list, array $options =

/**
* @param SetOperation|SetOperation[] $component the component to be built
* @param array<string, mixed> $options parameters for building
*/
public static function build($component, array $options = []): string
public static function build($component): string
{
if (is_array($component)) {
return implode(', ', $component);
Expand Down
3 changes: 1 addition & 2 deletions src/Components/UnionKeyword.php
Expand Up @@ -35,9 +35,8 @@ public static function parse(Parser $parser, TokensList $list, array $options =

/**
* @param array<UnionKeyword[]> $component the component to be built
* @param array<string, mixed> $options parameters for building
*/
public static function build($component, array $options = []): string
public static function build($component): string
{
$tmp = [];
foreach ($component as $componentPart) {
Expand Down
5 changes: 2 additions & 3 deletions src/Components/WithKeyword.php
Expand Up @@ -46,10 +46,9 @@ public static function parse(Parser $parser, TokensList $list, array $options =
}

/**
* @param WithKeyword $component
* @param array<string, mixed> $options
* @param WithKeyword $component
*/
public static function build($component, array $options = []): string
public static function build($component): string
{
if (! $component instanceof WithKeyword) {
throw new RuntimeException('Can not build a component that is not a WithKeyword');
Expand Down

0 comments on commit da08ab2

Please sign in to comment.