diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 72e3ef269..f4e814b53 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -145,11 +145,6 @@ parameters: count: 1 path: src/Components/IntoKeyword.php - - - message: "#^Parameter \\#1 \\$component of static method PhpMyAdmin\\\\SqlParser\\\\Components\\\\OptionsArray\\:\\:build\\(\\) expects PhpMyAdmin\\\\SqlParser\\\\Components\\\\OptionsArray, PhpMyAdmin\\\\SqlParser\\\\Components\\\\OptionsArray\\|null given\\.$#" - count: 2 - path: src/Components/IntoKeyword.php - - message: "#^Parameter \\#3 \\$keyword of method PhpMyAdmin\\\\SqlParser\\\\Components\\\\IntoKeyword\\:\\:parseFileOptions\\(\\) expects string, mixed given\\.$#" count: 2 @@ -481,12 +476,12 @@ parameters: path: src/Statements/AlterStatement.php - - message: "#^Parameter \\#1 \\$component of static method PhpMyAdmin\\\\SqlParser\\\\Components\\\\Expression\\:\\:build\\(\\) expects PhpMyAdmin\\\\SqlParser\\\\Components\\\\Expression, PhpMyAdmin\\\\SqlParser\\\\Components\\\\Expression\\|null given\\.$#" + message: "#^Cannot call method build\\(\\) on PhpMyAdmin\\\\SqlParser\\\\Components\\\\Expression\\|null\\.$#" count: 1 path: src/Statements/AlterStatement.php - - message: "#^Parameter \\#1 \\$component of static method PhpMyAdmin\\\\SqlParser\\\\Components\\\\OptionsArray\\:\\:build\\(\\) expects PhpMyAdmin\\\\SqlParser\\\\Components\\\\OptionsArray, PhpMyAdmin\\\\SqlParser\\\\Components\\\\OptionsArray\\|null given\\.$#" + message: "#^Cannot call method build\\(\\) on PhpMyAdmin\\\\SqlParser\\\\Components\\\\OptionsArray\\|null\\.$#" count: 1 path: src/Statements/AlterStatement.php @@ -511,23 +506,23 @@ parameters: path: src/Statements/CreateStatement.php - - message: "#^Cannot call method has\\(\\) on PhpMyAdmin\\\\SqlParser\\\\Components\\\\OptionsArray\\|null\\.$#" - count: 8 + message: "#^Cannot call method build\\(\\) on PhpMyAdmin\\\\SqlParser\\\\Components\\\\DataType\\|null\\.$#" + count: 1 path: src/Statements/CreateStatement.php - - message: "#^Parameter \\#1 \\$component of static method PhpMyAdmin\\\\SqlParser\\\\Components\\\\DataType\\:\\:build\\(\\) expects PhpMyAdmin\\\\SqlParser\\\\Components\\\\DataType, PhpMyAdmin\\\\SqlParser\\\\Components\\\\DataType\\|null given\\.$#" - count: 1 + message: "#^Cannot call method build\\(\\) on PhpMyAdmin\\\\SqlParser\\\\Components\\\\Expression\\|null\\.$#" + count: 10 path: src/Statements/CreateStatement.php - - message: "#^Parameter \\#1 \\$component of static method PhpMyAdmin\\\\SqlParser\\\\Components\\\\Expression\\:\\:build\\(\\) expects PhpMyAdmin\\\\SqlParser\\\\Components\\\\Expression, PhpMyAdmin\\\\SqlParser\\\\Components\\\\Expression\\|null given\\.$#" - count: 10 + message: "#^Cannot call method build\\(\\) on PhpMyAdmin\\\\SqlParser\\\\Components\\\\OptionsArray\\|null\\.$#" + count: 12 path: src/Statements/CreateStatement.php - - message: "#^Parameter \\#1 \\$component of static method PhpMyAdmin\\\\SqlParser\\\\Components\\\\OptionsArray\\:\\:build\\(\\) expects PhpMyAdmin\\\\SqlParser\\\\Components\\\\OptionsArray, PhpMyAdmin\\\\SqlParser\\\\Components\\\\OptionsArray\\|null given\\.$#" - count: 14 + message: "#^Cannot call method has\\(\\) on PhpMyAdmin\\\\SqlParser\\\\Components\\\\OptionsArray\\|null\\.$#" + count: 8 path: src/Statements/CreateStatement.php - @@ -566,7 +561,7 @@ parameters: path: src/Statements/DeleteStatement.php - - message: "#^Parameter \\#1 \\$component of static method PhpMyAdmin\\\\SqlParser\\\\Components\\\\OptionsArray\\:\\:build\\(\\) expects PhpMyAdmin\\\\SqlParser\\\\Components\\\\OptionsArray, PhpMyAdmin\\\\SqlParser\\\\Components\\\\OptionsArray\\|null given\\.$#" + message: "#^Cannot call method build\\(\\) on PhpMyAdmin\\\\SqlParser\\\\Components\\\\OptionsArray\\|null\\.$#" count: 1 path: src/Statements/DeleteStatement.php @@ -656,8 +651,8 @@ parameters: path: src/Statements/RenameStatement.php - - message: "#^Parameter \\#1 \\$component of static method PhpMyAdmin\\\\SqlParser\\\\Components\\\\OptionsArray\\:\\:build\\(\\) expects PhpMyAdmin\\\\SqlParser\\\\Components\\\\OptionsArray, PhpMyAdmin\\\\SqlParser\\\\Components\\\\OptionsArray\\|null given\\.$#" - count: 2 + message: "#^Cannot call method build\\(\\) on PhpMyAdmin\\\\SqlParser\\\\Components\\\\OptionsArray\\|null\\.$#" + count: 1 path: src/Statements/SetStatement.php - @@ -671,13 +666,13 @@ parameters: path: src/Statements/TransactionStatement.php - - message: "#^Cannot call method has\\(\\) on PhpMyAdmin\\\\SqlParser\\\\Components\\\\OptionsArray\\|null\\.$#" - count: 4 + message: "#^Cannot call method build\\(\\) on PhpMyAdmin\\\\SqlParser\\\\Components\\\\OptionsArray\\|null\\.$#" + count: 1 path: src/Statements/TransactionStatement.php - - message: "#^Parameter \\#1 \\$component of static method PhpMyAdmin\\\\SqlParser\\\\Components\\\\OptionsArray\\:\\:build\\(\\) expects PhpMyAdmin\\\\SqlParser\\\\Components\\\\OptionsArray, PhpMyAdmin\\\\SqlParser\\\\Components\\\\OptionsArray\\|null given\\.$#" - count: 1 + message: "#^Cannot call method has\\(\\) on PhpMyAdmin\\\\SqlParser\\\\Components\\\\OptionsArray\\|null\\.$#" + count: 4 path: src/Statements/TransactionStatement.php - diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 079308ec9..faa8f9085 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -38,9 +38,6 @@ 'DO' => 10, ]]]> - - $component - $arrayKey @@ -55,11 +52,6 @@ )]]> - - - $component - - $ret[] @@ -78,9 +70,6 @@ $ret ArrayObj|Component[] - - $component - $ret $ret @@ -112,17 +101,11 @@ value]]> - - $component - value]]]> - - $component - $isOperator @@ -132,17 +115,11 @@ name]]> name]]> - - $component - - options]]> + options]]> - - $component - raw]]> values]]> @@ -175,9 +152,6 @@ alias]]> subquery]]> - - $component - expr]]> expr]]> @@ -201,9 +175,6 @@ Expression[] - - $component - $expr $expr @@ -217,21 +188,15 @@ value]]> - - $component - ArrayObj::parse($parser, $list) - name]]> - parameters]]> + name]]> + parameters]]> - - $component - $expr Expression::parse($parser, $list) @@ -244,12 +209,9 @@ type]]> - - $component - - indexOrKey]]> - type]]> + indexOrKey]]> + type]]> buildAll @@ -263,20 +225,15 @@ dest]]> - - $component - values]]> - fieldsOptions]]> - linesOptions]]> keyword]]> keyword]]> - dest]]> + dest]]> @@ -291,9 +248,6 @@ keyword]]]> keyword]]]> - - $component - type, static::$joins)]]> @@ -320,13 +274,10 @@ name]]> type]]> - - $component - - options]]> - options]]> expr]]> + options]]> + options]]> true])]]> @@ -342,18 +293,12 @@ offset]]> rowCount]]> - - $component - $table $type - - $component - 'table'])]]> @@ -429,9 +374,6 @@ options]]> options]]> - - $component - empty($lastOption[2]) ? [] : $lastOption[2] @@ -444,9 +386,6 @@ - - $component - $expr Expression::parse($parser, $list) @@ -456,9 +395,6 @@ name]]> - - $component - $inOut $name @@ -485,9 +421,6 @@ name]]> - - $component - - - $component - values]]> @@ -530,9 +460,6 @@ - - $component - $new $old @@ -555,9 +482,6 @@ - - $component - expr]]> @@ -566,18 +490,10 @@ - - $component - buildAll - - - $component - - [] @@ -871,6 +787,12 @@ $tokenValue + + build + + + $field->build()]]> + @@ -896,15 +818,15 @@ $tmp[] - $altered::build($altered) + build - - options]]> - table]]> - altered]]> + + build + build + @@ -936,30 +858,28 @@ $brackets - entityOptions]]> - entityOptions]]> - entityOptions]]> - entityOptions]]> - entityOptions]]> - name]]> - name]]> - name]]> - name]]> - name]]> - name]]> - name]]> - name]]> - name]]> - options]]> parameters]]> - return]]> - table]]> value]]> value]]> + build + build + build + build + build + build + build + build + build + build + build + build + build + build + build has has @@ -992,12 +912,14 @@ table]]> - options]]> keyword]]> from]]> + + build + $partition @@ -1101,10 +1023,11 @@ - endOptions]]> - options]]> set]]> + + build + @@ -1116,13 +1039,11 @@ build()]]> - - options]]> - statements]]> + build has @@ -1312,9 +1233,6 @@ int - - $expr - keyword]]]> keyword]]]> @@ -1327,7 +1245,11 @@ $expr $expressions[] $rename + $ret[] + + build + $expr $expr @@ -1336,6 +1258,10 @@ table]]> old]]> + + $ret + ]]> + $i diff --git a/src/Component.php b/src/Component.php index d3df767a5..d1c44567b 100644 --- a/src/Component.php +++ b/src/Component.php @@ -29,8 +29,6 @@ public static function parse(Parser $parser, TokensList $list, array $options = * Builds the string representation of a component of this type. * * In other words, this function represents the inverse function of {@see Component::parse()}. - * - * @param mixed $component the component to be built */ - public static function build($component): string; + public function build(): string; } diff --git a/src/Components/AlterOperation.php b/src/Components/AlterOperation.php index ab84d6df9..bc2d85fd2 100644 --- a/src/Components/AlterOperation.php +++ b/src/Components/AlterOperation.php @@ -524,29 +524,26 @@ public static function parse(Parser $parser, TokensList $list, array $options = return $ret; } - /** - * @param AlterOperation $component the component to be built - */ - public static function build($component): string + public function build(): string { // Specific case of RENAME COLUMN that insert the field between 2 options. $afterFieldsOptions = new OptionsArray(); - if ($component->options->has('RENAME') && $component->options->has('COLUMN')) { - $afterFieldsOptions = clone $component->options; + if ($this->options->has('RENAME') && $this->options->has('COLUMN')) { + $afterFieldsOptions = clone $this->options; $afterFieldsOptions->remove('RENAME'); $afterFieldsOptions->remove('COLUMN'); - $component->options->remove('TO'); + $this->options->remove('TO'); } - $ret = $component->options . ' '; - if (isset($component->field) && ($component->field !== '')) { - $ret .= $component->field . ' '; + $ret = $this->options . ' '; + if (isset($this->field) && ($this->field !== '')) { + $ret .= $this->field . ' '; } - $ret .= $afterFieldsOptions . TokensList::build($component->unknown); + $ret .= $afterFieldsOptions . TokensList::build($this->unknown); - if (isset($component->partitions)) { - $ret .= PartitionDefinition::buildAll($component->partitions); + if (isset($this->partitions)) { + $ret .= PartitionDefinition::buildAll($this->partitions); } return trim($ret); @@ -589,6 +586,6 @@ private static function checkIfTokenQuotedSymbol($token): bool public function __toString(): string { - return static::build($this); + return $this->build(); } } diff --git a/src/Components/Array2d.php b/src/Components/Array2d.php index 96605a02f..ab18b6dbe 100644 --- a/src/Components/Array2d.php +++ b/src/Components/Array2d.php @@ -113,16 +113,13 @@ public static function parse(Parser $parser, TokensList $list, array $options = return $ret; } - /** - * @param Array2d $component - */ - public static function build($component): string + public function build(): string { throw new RuntimeException(Translator::gettext('Not implemented yet.')); } public function __toString(): string { - return static::build($this); + return $this->build(); } } diff --git a/src/Components/ArrayObj.php b/src/Components/ArrayObj.php index 294fb1b5c..6d890beae 100644 --- a/src/Components/ArrayObj.php +++ b/src/Components/ArrayObj.php @@ -161,16 +161,13 @@ public static function parse(Parser $parser, TokensList $list, array $options = return $ret; } - /** - * @param ArrayObj $component the component to be built - */ - public static function build($component): string + public function build(): string { - if ($component->raw !== []) { - return '(' . implode(', ', $component->raw) . ')'; + if ($this->raw !== []) { + return '(' . implode(', ', $this->raw) . ')'; } - return '(' . implode(', ', $component->values) . ')'; + return '(' . implode(', ', $this->values) . ')'; } /** @@ -183,6 +180,6 @@ public static function buildAll(array $component): string public function __toString(): string { - return static::build($this); + return $this->build(); } } diff --git a/src/Components/CaseExpression.php b/src/Components/CaseExpression.php index 406f9cdee..d880856de 100644 --- a/src/Components/CaseExpression.php +++ b/src/Components/CaseExpression.php @@ -242,7 +242,7 @@ public static function parse(Parser $parser, TokensList $list, array $options = $parser->error('An alias was expected after AS.', $list->tokens[$list->idx - 1]); } - $ret->expr = self::build($ret); + $ret->expr = $ret->build(); } --$list->idx; @@ -250,39 +250,36 @@ public static function parse(Parser $parser, TokensList $list, array $options = return $ret; } - /** - * @param CaseExpression $component the component to be built - */ - public static function build($component): string + public function build(): string { $ret = 'CASE '; - if (isset($component->value)) { + if (isset($this->value)) { // Syntax type 0 - $ret .= $component->value . ' '; - $valuesCount = count($component->compareValues); - $resultsCount = count($component->results); + $ret .= $this->value . ' '; + $valuesCount = count($this->compareValues); + $resultsCount = count($this->results); for ($i = 0; $i < $valuesCount && $i < $resultsCount; ++$i) { - $ret .= 'WHEN ' . $component->compareValues[$i] . ' '; - $ret .= 'THEN ' . $component->results[$i] . ' '; + $ret .= 'WHEN ' . $this->compareValues[$i] . ' '; + $ret .= 'THEN ' . $this->results[$i] . ' '; } } else { // Syntax type 1 - $valuesCount = count($component->conditions); - $resultsCount = count($component->results); + $valuesCount = count($this->conditions); + $resultsCount = count($this->results); for ($i = 0; $i < $valuesCount && $i < $resultsCount; ++$i) { - $ret .= 'WHEN ' . Condition::buildAll($component->conditions[$i]) . ' '; - $ret .= 'THEN ' . $component->results[$i] . ' '; + $ret .= 'WHEN ' . Condition::buildAll($this->conditions[$i]) . ' '; + $ret .= 'THEN ' . $this->results[$i] . ' '; } } - if (isset($component->elseResult)) { - $ret .= 'ELSE ' . $component->elseResult . ' '; + if (isset($this->elseResult)) { + $ret .= 'ELSE ' . $this->elseResult . ' '; } $ret .= 'END'; - if ($component->alias) { - $ret .= ' AS ' . Context::escape($component->alias); + if ($this->alias) { + $ret .= ' AS ' . Context::escape($this->alias); } return $ret; @@ -290,6 +287,6 @@ public static function build($component): string public function __toString(): string { - return static::build($this); + return $this->build(); } } diff --git a/src/Components/Condition.php b/src/Components/Condition.php index 40e3ac677..1b36a7ef4 100644 --- a/src/Components/Condition.php +++ b/src/Components/Condition.php @@ -220,12 +220,9 @@ public static function parse(Parser $parser, TokensList $list, array $options = return $ret; } - /** - * @param Condition $component the component to be built - */ - public static function build($component): string + public function build(): string { - return $component->expr; + return $this->expr; } /** @@ -238,6 +235,6 @@ public static function buildAll(array $component): string public function __toString(): string { - return static::build($this); + return $this->build(); } } diff --git a/src/Components/CreateDefinition.php b/src/Components/CreateDefinition.php index a5e62793f..4d00b9738 100644 --- a/src/Components/CreateDefinition.php +++ b/src/Components/CreateDefinition.php @@ -316,35 +316,32 @@ public static function parse(Parser $parser, TokensList $list, array $options = return $ret; } - /** - * @param CreateDefinition $component the component to be built - */ - public static function build($component): string + public function build(): string { $tmp = ''; - if ($component->isConstraint) { + if ($this->isConstraint) { $tmp .= 'CONSTRAINT '; } - if (isset($component->name) && ($component->name !== '')) { - $tmp .= Context::escape($component->name) . ' '; + if (isset($this->name) && ($this->name !== '')) { + $tmp .= Context::escape($this->name) . ' '; } - if (! empty($component->type)) { - $component->type->lowercase = true; - $tmp .= DataType::build($component->type) . ' '; + if (! empty($this->type)) { + $this->type->lowercase = true; + $tmp .= $this->type->build() . ' '; } - if (! empty($component->key)) { - $tmp .= $component->key . ' '; + if (! empty($this->key)) { + $tmp .= $this->key . ' '; } - if (! empty($component->references)) { - $tmp .= 'REFERENCES ' . $component->references . ' '; + if (! empty($this->references)) { + $tmp .= 'REFERENCES ' . $this->references . ' '; } - $tmp .= $component->options; + $tmp .= $this->options; return trim($tmp); } @@ -359,6 +356,6 @@ public static function buildAll(array $component): string public function __toString(): string { - return static::build($this); + return $this->build(); } } diff --git a/src/Components/DataType.php b/src/Components/DataType.php index 226213c6b..31a5d3cc9 100644 --- a/src/Components/DataType.php +++ b/src/Components/DataType.php @@ -152,23 +152,20 @@ public static function parse(Parser $parser, TokensList $list, array $options = return $ret; } - /** - * @param DataType $component the component to be built - */ - public static function build($component): string + public function build(): string { - $name = $component->lowercase ? strtolower($component->name) : $component->name; + $name = $this->lowercase ? strtolower($this->name) : $this->name; $parameters = ''; - if ($component->parameters !== []) { - $parameters = '(' . implode(',', $component->parameters) . ')'; + if ($this->parameters !== []) { + $parameters = '(' . implode(',', $this->parameters) . ')'; } - return trim($name . $parameters . ' ' . $component->options); + return trim($name . $parameters . ' ' . $this->options); } public function __toString(): string { - return static::build($this); + return $this->build(); } } diff --git a/src/Components/Expression.php b/src/Components/Expression.php index 51485639e..3dce60e3b 100644 --- a/src/Components/Expression.php +++ b/src/Components/Expression.php @@ -262,7 +262,7 @@ public static function parse(Parser $parser, TokensList $list, array $options = // For a use of CASE like // 'SELECT a = CASE .... END, b=1, `id`, ... FROM ...' $tempCaseExpr = CaseExpression::parse($parser, $list); - $ret->expr .= CaseExpression::build($tempCaseExpr); + $ret->expr .= $tempCaseExpr->build(); $isExpr = true; continue; } @@ -444,32 +444,29 @@ public static function parse(Parser $parser, TokensList $list, array $options = return $ret; } - /** - * @param Expression $component the component to be built - */ - public static function build($component): string + public function build(): string { - if ($component->expr !== '' && $component->expr !== null) { - $ret = $component->expr; + if ($this->expr !== '' && $this->expr !== null) { + $ret = $this->expr; } else { $fields = []; - if (isset($component->database) && ($component->database !== '')) { - $fields[] = $component->database; + if (isset($this->database) && ($this->database !== '')) { + $fields[] = $this->database; } - if (isset($component->table) && ($component->table !== '')) { - $fields[] = $component->table; + if (isset($this->table) && ($this->table !== '')) { + $fields[] = $this->table; } - if (isset($component->column) && ($component->column !== '')) { - $fields[] = $component->column; + if (isset($this->column) && ($this->column !== '')) { + $fields[] = $this->column; } $ret = implode('.', Context::escapeAll($fields)); } - if (! empty($component->alias)) { - $ret .= ' AS ' . Context::escape($component->alias); + if (! empty($this->alias)) { + $ret .= ' AS ' . Context::escape($this->alias); } return $ret; @@ -485,6 +482,6 @@ public static function buildAll(array $component): string public function __toString(): string { - return static::build($this); + return $this->build(); } } diff --git a/src/Components/ExpressionArray.php b/src/Components/ExpressionArray.php index 2236c77b5..77814ed40 100644 --- a/src/Components/ExpressionArray.php +++ b/src/Components/ExpressionArray.php @@ -118,10 +118,7 @@ public static function parse(Parser $parser, TokensList $list, array $options = return $ret; } - /** - * @param ExpressionArray $component - */ - public static function build($component): string + public function build(): string { throw new RuntimeException(Translator::gettext('Not implemented yet.')); } @@ -131,16 +128,11 @@ public static function build($component): string */ public static function buildAll(array $component): string { - $ret = []; - foreach ($component as $frag) { - $ret[] = $frag::build($frag); - } - - return implode(', ', $ret); + return implode(', ', $component); } public function __toString(): string { - return static::build($this); + return $this->build(); } } diff --git a/src/Components/FunctionCall.php b/src/Components/FunctionCall.php index 88b269995..f634940fd 100644 --- a/src/Components/FunctionCall.php +++ b/src/Components/FunctionCall.php @@ -100,16 +100,13 @@ public static function parse(Parser $parser, TokensList $list, array $options = return $ret; } - /** - * @param FunctionCall $component the component to be built - */ - public static function build($component): string + public function build(): string { - return $component->name . $component->parameters; + return $this->name . $this->parameters; } public function __toString(): string { - return static::build($this); + return $this->build(); } } diff --git a/src/Components/GroupKeyword.php b/src/Components/GroupKeyword.php index 8c0c2420b..2aa273038 100644 --- a/src/Components/GroupKeyword.php +++ b/src/Components/GroupKeyword.php @@ -110,12 +110,9 @@ public static function parse(Parser $parser, TokensList $list, array $options = return $ret; } - /** - * @param GroupKeyword $component the component to be built - */ - public static function build($component): string + public function build(): string { - return trim((string) $component->expr); + return trim((string) $this->expr); } /** @@ -128,6 +125,6 @@ public static function buildAll(array $component): string public function __toString(): string { - return static::build($this); + return $this->build(); } } diff --git a/src/Components/IndexHint.php b/src/Components/IndexHint.php index 40d041fc6..80674cab9 100644 --- a/src/Components/IndexHint.php +++ b/src/Components/IndexHint.php @@ -176,17 +176,14 @@ public static function parse(Parser $parser, TokensList $list, array $options = return $ret; } - /** - * @param IndexHint $component the component to be built - */ - public static function build($component): string + public function build(): string { - $ret = $component->type . ' ' . $component->indexOrKey . ' '; - if ($component->for !== null) { - $ret .= 'FOR ' . $component->for . ' '; + $ret = $this->type . ' ' . $this->indexOrKey . ' '; + if ($this->for !== null) { + $ret .= 'FOR ' . $this->for . ' '; } - return $ret . Expression::buildAll($component->indexes); + return $ret . Expression::buildAll($this->indexes); } /** @@ -199,6 +196,6 @@ public static function buildAll(array $component): string public function __toString(): string { - return static::build($this); + return $this->build(); } } diff --git a/src/Components/IntoKeyword.php b/src/Components/IntoKeyword.php index 00c7ac89a..bf1aadf48 100644 --- a/src/Components/IntoKeyword.php +++ b/src/Components/IntoKeyword.php @@ -256,30 +256,27 @@ public function parseFileOptions(Parser $parser, TokensList $list, $keyword = 'F } } - /** - * @param IntoKeyword $component the component to be built - */ - public static function build($component): string + public function build(): string { - if ($component->dest instanceof Expression) { - $columns = ! empty($component->columns) ? '(`' . implode('`, `', $component->columns) . '`)' : ''; + if ($this->dest instanceof Expression) { + $columns = ! empty($this->columns) ? '(`' . implode('`, `', $this->columns) . '`)' : ''; - return $component->dest . $columns; + return $this->dest . $columns; } - if (isset($component->values)) { - return Expression::buildAll($component->values); + if (isset($this->values)) { + return Expression::buildAll($this->values); } - $ret = 'OUTFILE "' . $component->dest . '"'; + $ret = 'OUTFILE "' . $this->dest . '"'; - $fieldsOptionsString = OptionsArray::build($component->fieldsOptions); + $fieldsOptionsString = $this->fieldsOptions?->build() ?? ''; if (trim($fieldsOptionsString) !== '') { - $ret .= $component->fieldsKeyword ? ' FIELDS' : ' COLUMNS'; + $ret .= $this->fieldsKeyword ? ' FIELDS' : ' COLUMNS'; $ret .= ' ' . $fieldsOptionsString; } - $linesOptionsString = OptionsArray::build($component->linesOptions); + $linesOptionsString = $this->linesOptions?->build() ?? ''; if (trim($linesOptionsString) !== '') { $ret .= ' LINES ' . $linesOptionsString; } @@ -289,6 +286,6 @@ public static function build($component): string public function __toString(): string { - return static::build($this); + return $this->build(); } } diff --git a/src/Components/JoinKeyword.php b/src/Components/JoinKeyword.php index 1cdc75d7e..b820b8db9 100644 --- a/src/Components/JoinKeyword.php +++ b/src/Components/JoinKeyword.php @@ -199,10 +199,7 @@ public static function parse(Parser $parser, TokensList $list, array $options = return $ret; } - /** - * @param JoinKeyword $component - */ - public static function build($component): string + public function build(): string { throw new RuntimeException(Translator::gettext('Not implemented yet.')); } @@ -218,7 +215,7 @@ public static function buildAll(array $component): string . (! empty($c->on) ? ' ON ' . Condition::buildAll($c->on) : '') . (! empty($c->using) - ? ' USING ' . ArrayObj::build($c->using) : ''); + ? ' USING ' . $c->using->build() : ''); } return implode(' ', $ret); @@ -226,6 +223,6 @@ public static function buildAll(array $component): string public function __toString(): string { - return static::build($this); + return $this->build(); } } diff --git a/src/Components/Key.php b/src/Components/Key.php index daa6469f5..aa356f440 100644 --- a/src/Components/Key.php +++ b/src/Components/Key.php @@ -261,22 +261,19 @@ public static function parse(Parser $parser, TokensList $list, array $options = return $ret; } - /** - * @param Key $component the component to be built - */ - public static function build($component): string + public function build(): string { - $ret = $component->type . ' '; - if (! empty($component->name)) { - $ret .= Context::escape($component->name) . ' '; + $ret = $this->type . ' '; + if (! empty($this->name)) { + $ret .= Context::escape($this->name) . ' '; } - if ($component->expr !== null) { - return $ret . '(' . $component->expr . ') ' . $component->options; + if ($this->expr !== null) { + return $ret . '(' . $this->expr . ') ' . $this->options; } $columns = []; - foreach ($component->columns as $column) { + foreach ($this->columns as $column) { $tmp = ''; if (isset($column['name'])) { $tmp .= Context::escape($column['name']); @@ -293,13 +290,13 @@ public static function build($component): string $columns[] = $tmp; } - $ret .= '(' . implode(',', $columns) . ') ' . $component->options; + $ret .= '(' . implode(',', $columns) . ') ' . $this->options; return trim($ret); } public function __toString(): string { - return static::build($this); + return $this->build(); } } diff --git a/src/Components/Limit.php b/src/Components/Limit.php index 9f46c537a..9adcaf13e 100644 --- a/src/Components/Limit.php +++ b/src/Components/Limit.php @@ -106,16 +106,13 @@ public static function parse(Parser $parser, TokensList $list, array $options = return $ret; } - /** - * @param Limit $component the component to be built - */ - public static function build($component): string + public function build(): string { - return $component->offset . ', ' . $component->rowCount; + return $this->offset . ', ' . $this->rowCount; } public function __toString(): string { - return static::build($this); + return $this->build(); } } diff --git a/src/Components/LockExpression.php b/src/Components/LockExpression.php index 1c9c1beb5..ec2508c0d 100644 --- a/src/Components/LockExpression.php +++ b/src/Components/LockExpression.php @@ -91,12 +91,9 @@ public static function parse(Parser $parser, TokensList $list, array $options = return $ret; } - /** - * @param LockExpression $component the component to be built - */ - public static function build($component): string + public function build(): string { - return $component->table . ' ' . $component->type; + return $this->table . ' ' . $this->type; } /** @@ -199,6 +196,6 @@ private static function parseLockType(Parser $parser, TokensList $list): string public function __toString(): string { - return static::build($this); + return $this->build(); } } diff --git a/src/Components/OptionsArray.php b/src/Components/OptionsArray.php index 17188cfc7..5482120a1 100644 --- a/src/Components/OptionsArray.php +++ b/src/Components/OptionsArray.php @@ -264,17 +264,14 @@ public static function parse(Parser $parser, TokensList $list, array $options = return $ret; } - /** - * @param OptionsArray $component the component to be built - */ - public static function build($component): string + public function build(): string { - if (empty($component->options)) { + if (empty($this->options)) { return ''; } $options = []; - foreach ($component->options as $option) { + foreach ($this->options as $option) { if (! is_array($option)) { $options[] = $option; } else { @@ -354,6 +351,6 @@ public function isEmpty(): bool public function __toString(): string { - return static::build($this); + return $this->build(); } } diff --git a/src/Components/OrderKeyword.php b/src/Components/OrderKeyword.php index 46328acba..dff9eee12 100644 --- a/src/Components/OrderKeyword.php +++ b/src/Components/OrderKeyword.php @@ -115,12 +115,9 @@ public static function parse(Parser $parser, TokensList $list, array $options = return $ret; } - /** - * @param OrderKeyword $component the component to be built - */ - public static function build($component): string + public function build(): string { - return $component->expr . ' ' . $component->type; + return $this->expr . ' ' . $this->type; } /** @@ -133,6 +130,6 @@ public static function buildAll(array $component): string public function __toString(): string { - return static::build($this); + return $this->build(); } } diff --git a/src/Components/ParameterDefinition.php b/src/Components/ParameterDefinition.php index 87e00404a..e781a86b9 100644 --- a/src/Components/ParameterDefinition.php +++ b/src/Components/ParameterDefinition.php @@ -139,18 +139,15 @@ public static function parse(Parser $parser, TokensList $list, array $options = return $ret; } - /** - * @param ParameterDefinition $component the component to be built - */ - public static function build($component): string + public function build(): string { $tmp = ''; - if (! empty($component->inOut)) { - $tmp .= $component->inOut . ' '; + if (! empty($this->inOut)) { + $tmp .= $this->inOut . ' '; } return trim( - $tmp . Context::escape($component->name) . ' ' . $component->type + $tmp . Context::escape($this->name) . ' ' . $this->type ); } @@ -164,6 +161,6 @@ public static function buildAll(array $component): string public function __toString(): string { - return static::build($this); + return $this->build(); } } diff --git a/src/Components/PartitionDefinition.php b/src/Components/PartitionDefinition.php index f7ca0cfaf..68fe2e0f0 100644 --- a/src/Components/PartitionDefinition.php +++ b/src/Components/PartitionDefinition.php @@ -220,22 +220,19 @@ public static function parse(Parser $parser, TokensList $list, array $options = return $ret; } - /** - * @param PartitionDefinition $component the component to be built - */ - public static function build($component): string + public function build(): string { - if ($component->isSubpartition) { - return trim('SUBPARTITION ' . $component->name . ' ' . $component->options); + if ($this->isSubpartition) { + return trim('SUBPARTITION ' . $this->name . ' ' . $this->options); } - $subpartitions = empty($component->subpartitions) ? '' : ' ' . self::buildAll($component->subpartitions); + $subpartitions = empty($this->subpartitions) ? '' : ' ' . self::buildAll($this->subpartitions); return trim( - 'PARTITION ' . $component->name - . (empty($component->type) ? '' : ' VALUES ' . $component->type . ' ' . $component->expr . ' ') - . (! empty($component->options) && ! empty($component->type) ? '' : ' ') - . $component->options . $subpartitions + 'PARTITION ' . $this->name + . (empty($this->type) ? '' : ' VALUES ' . $this->type . ' ' . $this->expr . ' ') + . (! empty($this->options) && ! empty($this->type) ? '' : ' ') + . $this->options . $subpartitions ); } @@ -249,6 +246,6 @@ public static function buildAll(array $component): string public function __toString(): string { - return static::build($this); + return $this->build(); } } diff --git a/src/Components/Reference.php b/src/Components/Reference.php index 659f5941f..17b37bda8 100644 --- a/src/Components/Reference.php +++ b/src/Components/Reference.php @@ -137,20 +137,17 @@ public static function parse(Parser $parser, TokensList $list, array $options = return $ret; } - /** - * @param Reference $component the component to be built - */ - public static function build($component): string + public function build(): string { return trim( - $component->table - . ' (' . implode(', ', Context::escapeAll($component->columns)) . ') ' - . $component->options + $this->table + . ' (' . implode(', ', Context::escapeAll($this->columns)) . ') ' + . $this->options ); } public function __toString(): string { - return static::build($this); + return $this->build(); } } diff --git a/src/Components/RenameOperation.php b/src/Components/RenameOperation.php index 16b70f502..01ff7ad87 100644 --- a/src/Components/RenameOperation.php +++ b/src/Components/RenameOperation.php @@ -147,12 +147,9 @@ public static function parse(Parser $parser, TokensList $list, array $options = return $ret; } - /** - * @param RenameOperation $component the component to be built - */ - public static function build($component): string + public function build(): string { - return $component->old . ' TO ' . $component->new; + return $this->old . ' TO ' . $this->new; } /** @@ -165,6 +162,6 @@ public static function buildAll(array $component): string public function __toString(): string { - return static::build($this); + return $this->build(); } } diff --git a/src/Components/SetOperation.php b/src/Components/SetOperation.php index 65e552f99..a70aa404c 100644 --- a/src/Components/SetOperation.php +++ b/src/Components/SetOperation.php @@ -139,12 +139,9 @@ public static function parse(Parser $parser, TokensList $list, array $options = return $ret; } - /** - * @param SetOperation $component the component to be built - */ - public static function build($component): string + public function build(): string { - return $component->column . ' = ' . $component->value; + return $this->column . ' = ' . $this->value; } /** @@ -157,6 +154,6 @@ public static function buildAll(array $component): string public function __toString(): string { - return static::build($this); + return $this->build(); } } diff --git a/src/Components/UnionKeyword.php b/src/Components/UnionKeyword.php index 427929827..e07192ae3 100644 --- a/src/Components/UnionKeyword.php +++ b/src/Components/UnionKeyword.php @@ -31,10 +31,7 @@ public static function parse(Parser $parser, TokensList $list, array $options = throw new RuntimeException(Translator::gettext('Not implemented yet.')); } - /** - * @param UnionKeyword $component - */ - public static function build($component): string + public function build(): string { throw new RuntimeException(Translator::gettext('Not implemented yet.')); } @@ -54,6 +51,6 @@ public static function buildAll(array $component): string public function __toString(): string { - return static::build($this); + return $this->build(); } } diff --git a/src/Components/WithKeyword.php b/src/Components/WithKeyword.php index cc204b3f8..c98924b61 100644 --- a/src/Components/WithKeyword.php +++ b/src/Components/WithKeyword.php @@ -43,24 +43,21 @@ public static function parse(Parser $parser, TokensList $list, array $options = throw new RuntimeException(Translator::gettext('Not implemented yet.')); } - /** - * @param WithKeyword $component - */ - public static function build($component): string + public function build(): string { - if (! isset($component->statement)) { + if (! isset($this->statement)) { throw new RuntimeException('No statement inside WITH'); } - $str = $component->name; + $str = $this->name; - if ($component->columns) { - $str .= ArrayObj::buildAll($component->columns); + if ($this->columns) { + $str .= ArrayObj::buildAll($this->columns); } $str .= ' AS ('; - foreach ($component->statement->statements as $statement) { + foreach ($this->statement->statements as $statement) { $str .= $statement->build(); } @@ -71,6 +68,6 @@ public static function build($component): string public function __toString(): string { - return static::build($this); + return $this->build(); } } diff --git a/src/Statement.php b/src/Statement.php index cfad96ff6..9f75c60e6 100644 --- a/src/Statement.php +++ b/src/Statement.php @@ -199,7 +199,7 @@ public function build(): string if (is_array($this->$field)) { $query = trim($query) . ' ' . $class::buildAll($this->$field); } else { - $query = trim($query) . ' ' . $class::build($this->$field); + $query = trim($query) . ' ' . $this->$field->build(); } } diff --git a/src/Statements/AlterStatement.php b/src/Statements/AlterStatement.php index c345fe2bd..1a9b6f07a 100644 --- a/src/Statements/AlterStatement.php +++ b/src/Statements/AlterStatement.php @@ -145,12 +145,12 @@ public function build(): string { $tmp = []; foreach ($this->altered as $altered) { - $tmp[] = $altered::build($altered); + $tmp[] = $altered->build(); } return trim( - 'ALTER ' . OptionsArray::build($this->options) - . ' ' . Expression::build($this->table) + 'ALTER ' . $this->options->build() + . ' ' . $this->table->build() . ' ' . implode(', ', $tmp) ); } diff --git a/src/Statements/CreateStatement.php b/src/Statements/CreateStatement.php index c43b48d13..51cf1060e 100644 --- a/src/Statements/CreateStatement.php +++ b/src/Statements/CreateStatement.php @@ -413,36 +413,36 @@ public function build(): string if (is_array($this->fields)) { $fields = CreateDefinition::buildAll($this->fields) . ' '; } elseif ($this->fields instanceof ArrayObj) { - $fields = ArrayObj::build($this->fields); + $fields = $this->fields->build(); } } if ($this->options->has('DATABASE') || $this->options->has('SCHEMA')) { return 'CREATE ' - . OptionsArray::build($this->options) . ' ' - . Expression::build($this->name) . ' ' - . OptionsArray::build($this->entityOptions); + . $this->options->build() . ' ' + . $this->name->build() . ' ' + . $this->entityOptions->build(); } if ($this->options->has('TABLE')) { if ($this->select !== null) { return 'CREATE ' - . OptionsArray::build($this->options) . ' ' - . Expression::build($this->name) . ' ' + . $this->options->build() . ' ' + . $this->name->build() . ' ' . $this->select->build(); } if ($this->like !== null) { return 'CREATE ' - . OptionsArray::build($this->options) . ' ' - . Expression::build($this->name) . ' LIKE ' - . Expression::build($this->like); + . $this->options->build() . ' ' + . $this->name->build() . ' LIKE ' + . $this->like->build(); } if ($this->with !== null) { return 'CREATE ' - . OptionsArray::build($this->options) . ' ' - . Expression::build($this->name) . ' ' + . $this->options->build() . ' ' + . $this->name->build() . ' ' . $this->with->build(); } @@ -469,10 +469,10 @@ public function build(): string } return 'CREATE ' - . OptionsArray::build($this->options) . ' ' - . Expression::build($this->name) . ' ' + . $this->options->build() . ' ' + . $this->name->build() . ' ' . $fields - . OptionsArray::build($this->entityOptions) + . ($this->entityOptions?->build() ?? '') . $partition; } @@ -485,39 +485,39 @@ public function build(): string } return 'CREATE ' - . OptionsArray::build($this->options) . ' ' - . Expression::build($this->name) . ' ' + . $this->options->build() . ' ' + . $this->name->build() . ' ' . $fields . ' AS ' . $builtStatement . (! empty($this->body) ? TokensList::build($this->body) : '') . ' ' - . OptionsArray::build($this->entityOptions); + . ($this->entityOptions?->build() ?? ''); } if ($this->options->has('TRIGGER')) { return 'CREATE ' - . OptionsArray::build($this->options) . ' ' - . Expression::build($this->name) . ' ' - . OptionsArray::build($this->entityOptions) . ' ' - . 'ON ' . Expression::build($this->table) . ' ' + . $this->options->build() . ' ' + . $this->name->build() . ' ' + . $this->entityOptions->build() . ' ' + . 'ON ' . $this->table->build() . ' ' . 'FOR EACH ROW ' . TokensList::build($this->body); } if ($this->options->has('PROCEDURE') || $this->options->has('FUNCTION')) { $tmp = ''; if ($this->options->has('FUNCTION')) { - $tmp = 'RETURNS ' . DataType::build($this->return); + $tmp = 'RETURNS ' . $this->return->build(); } return 'CREATE ' - . OptionsArray::build($this->options) . ' ' - . Expression::build($this->name) . ' ' + . $this->options->build() . ' ' + . $this->name->build() . ' ' . ParameterDefinition::buildAll($this->parameters) . ' ' - . $tmp . ' ' . OptionsArray::build($this->entityOptions) . ' ' + . $tmp . ' ' . $this->entityOptions->build() . ' ' . TokensList::build($this->body); } return 'CREATE ' - . OptionsArray::build($this->options) . ' ' - . Expression::build($this->name) . ' ' + . $this->options->build() . ' ' + . $this->name->build() . ' ' . TokensList::build($this->body); } diff --git a/src/Statements/DeleteStatement.php b/src/Statements/DeleteStatement.php index 43451fbd1..8504af47f 100644 --- a/src/Statements/DeleteStatement.php +++ b/src/Statements/DeleteStatement.php @@ -159,7 +159,7 @@ class DeleteStatement extends Statement public function build(): string { - $ret = 'DELETE ' . OptionsArray::build($this->options); + $ret = 'DELETE ' . $this->options->build(); if ($this->columns !== null && $this->columns !== []) { $ret .= ' ' . Expression::buildAll($this->columns); @@ -186,7 +186,7 @@ public function build(): string } if ($this->limit !== null && strlen((string) $this->limit) > 0) { - $ret .= ' LIMIT ' . Limit::build($this->limit); + $ret .= ' LIMIT ' . $this->limit->build(); } return $ret; diff --git a/src/Statements/ExplainStatement.php b/src/Statements/ExplainStatement.php index 17d700e88..27876af64 100644 --- a/src/Statements/ExplainStatement.php +++ b/src/Statements/ExplainStatement.php @@ -255,7 +255,7 @@ public function build(): string $str .= ' '; } - $str .= OptionsArray::build($this->options) . ' '; + $str .= $this->options->build() . ' '; } if ($this->options === null) { diff --git a/src/Statements/LoadStatement.php b/src/Statements/LoadStatement.php index 202654ab8..88f37d933 100644 --- a/src/Statements/LoadStatement.php +++ b/src/Statements/LoadStatement.php @@ -191,7 +191,7 @@ public function build(): string $ret .= ' INTO TABLE ' . $this->table; if ($this->partition !== null && strlen((string) $this->partition) > 0) { - $ret .= ' PARTITION ' . ArrayObj::build($this->partition); + $ret .= ' PARTITION ' . $this->partition->build(); } if ($this->charsetName !== null) { diff --git a/src/Statements/SetStatement.php b/src/Statements/SetStatement.php index cae25e76b..114f33885 100644 --- a/src/Statements/SetStatement.php +++ b/src/Statements/SetStatement.php @@ -104,9 +104,9 @@ class SetStatement extends Statement public function build(): string { - $ret = 'SET ' . OptionsArray::build($this->options) + $ret = 'SET ' . $this->options->build() . ' ' . SetOperation::buildAll($this->set) - . ' ' . OptionsArray::build($this->endOptions); + . ' ' . ($this->endOptions?->build() ?? ''); return trim($ret); } diff --git a/src/Statements/TransactionStatement.php b/src/Statements/TransactionStatement.php index 94afcc9dd..f69e752cb 100644 --- a/src/Statements/TransactionStatement.php +++ b/src/Statements/TransactionStatement.php @@ -4,7 +4,6 @@ namespace PhpMyAdmin\SqlParser\Statements; -use PhpMyAdmin\SqlParser\Components\OptionsArray; use PhpMyAdmin\SqlParser\Parser; use PhpMyAdmin\SqlParser\Statement; use PhpMyAdmin\SqlParser\TokensList; @@ -82,7 +81,7 @@ public function parse(Parser $parser, TokensList $list): void public function build(): string { - $ret = OptionsArray::build($this->options); + $ret = $this->options->build(); if ($this->type === self::TYPE_BEGIN) { foreach ($this->statements as $statement) { /* diff --git a/src/Statements/WithStatement.php b/src/Statements/WithStatement.php index cd6dc9a75..4b0469d73 100644 --- a/src/Statements/WithStatement.php +++ b/src/Statements/WithStatement.php @@ -278,7 +278,7 @@ public function build(): string foreach ($this->withers as $wither) { $str .= $str === 'WITH ' ? '' : ', '; - $str .= WithKeyword::build($wither); + $str .= $wither->build(); } $str .= ' '; diff --git a/src/Utils/Query.php b/src/Utils/Query.php index 17277bf51..eda62a430 100644 --- a/src/Utils/Query.php +++ b/src/Utils/Query.php @@ -4,7 +4,6 @@ namespace PhpMyAdmin\SqlParser\Utils; -use PhpMyAdmin\SqlParser\Components\Expression; use PhpMyAdmin\SqlParser\Lexer; use PhpMyAdmin\SqlParser\Parser; use PhpMyAdmin\SqlParser\Statement; @@ -591,7 +590,7 @@ public static function getTables($statement): array $expr->expr = null; // Force rebuild. $expr->alias = null; // Aliases are not required. - $ret[] = Expression::build($expr); + $ret[] = $expr->build(); } return $ret; diff --git a/tests/Components/ArrayObjTest.php b/tests/Components/ArrayObjTest.php index a1e12e87f..e2f35a662 100644 --- a/tests/Components/ArrayObjTest.php +++ b/tests/Components/ArrayObjTest.php @@ -15,13 +15,13 @@ class ArrayObjTest extends TestCase public function testBuildRaw(): void { $component = new ArrayObj(['a', 'b'], []); - $this->assertEquals('(a, b)', ArrayObj::build($component)); + $this->assertEquals('(a, b)', $component->build()); } public function testBuildValues(): void { $component = new ArrayObj([], ['a', 'b']); - $this->assertEquals('(a, b)', ArrayObj::build($component)); + $this->assertEquals('(a, b)', $component->build()); } public function testParseType(): void diff --git a/tests/Components/CaseExpressionTest.php b/tests/Components/CaseExpressionTest.php index c5bcbe063..df1dc5b5c 100644 --- a/tests/Components/CaseExpressionTest.php +++ b/tests/Components/CaseExpressionTest.php @@ -18,7 +18,7 @@ public function testParseBuild(): void $this->getTokensList($caseExprQuery) ); $this->assertEquals( - CaseExpression::build($component), + $component->build(), 'CASE 1 WHEN 1 THEN "Some" ELSE "Other" END' ); } @@ -31,7 +31,7 @@ public function testParseBuild2(): void $this->getTokensList($caseExprQuery) ); $this->assertEquals( - CaseExpression::build($component), + $component->build(), 'CASE WHEN 1=1 THEN "India" ELSE "Other" END' ); } @@ -45,7 +45,7 @@ public function testParseBuild3(): void $this->getTokensList($caseExprQuery) ); $this->assertEquals( - CaseExpression::build($component), + $component->build(), 'CASE 1 WHEN 1 THEN "Some" WHEN 2 THEN "SomeOther" ELSE "Other" END' ); } @@ -59,7 +59,7 @@ public function testParseBuild4(): void $this->getTokensList($caseExprQuery) ); $this->assertEquals( - CaseExpression::build($component), + $component->build(), 'CASE 1 WHEN 1 THEN "Some" WHEN 2 THEN "SomeOther" END' ); } @@ -73,7 +73,7 @@ public function testParseBuild5(): void $this->getTokensList($caseExprQuery) ); $this->assertEquals( - CaseExpression::build($component), + $component->build(), 'CASE WHEN 1=1 THEN "Some" WHEN 1=2 THEN "SomeOther" ELSE "Other" END' ); } @@ -87,7 +87,7 @@ public function testParseBuild6(): void $this->getTokensList($caseExprQuery) ); $this->assertEquals( - CaseExpression::build($component), + $component->build(), 'CASE WHEN 1=1 THEN "Some" WHEN 1=2 THEN "SomeOther" END' ); } @@ -101,7 +101,7 @@ public function testParseBuild7(): void $this->getTokensList($caseExprQuery) ); $this->assertEquals( - CaseExpression::build($component), + $component->build(), 'CASE WHEN 1=1 THEN "Some" WHEN 1=2 THEN "SomeOther" END AS `foo`' ); } @@ -115,7 +115,7 @@ public function testParseBuild8(): void $this->getTokensList($caseExprQuery) ); $this->assertEquals( - CaseExpression::build($component), + $component->build(), 'CASE WHEN 1=1 THEN "Some" WHEN 1=2 THEN "SomeOther" END AS `foo`' ); } @@ -123,6 +123,6 @@ public function testParseBuild8(): void public function testBuildWithIncompleteCaseExpression(): void { $incompleteCaseExpressionComponent = new CaseExpression(); - $this->assertEquals('CASE END', CaseExpression::build($incompleteCaseExpressionComponent)); + $this->assertEquals('CASE END', $incompleteCaseExpressionComponent->build()); } } diff --git a/tests/Components/CreateDefinitionTest.php b/tests/Components/CreateDefinitionTest.php index 0425826bb..304541dfb 100644 --- a/tests/Components/CreateDefinitionTest.php +++ b/tests/Components/CreateDefinitionTest.php @@ -79,7 +79,7 @@ public function testBuild(): void $this->assertEquals( 'CONSTRAINT `fk_payment_customer` FOREIGN KEY (`customer_id`) ' . 'REFERENCES `customer` (`customer_id`) ON UPDATE CASCADE', - CreateDefinition::build($parser->statements[0]->fields[1]) + $parser->statements[0]->fields[1]->build() ); } @@ -99,7 +99,7 @@ public function testBuild2(): void $this->assertEquals( 'CONSTRAINT `fk_payment_customer` FOREIGN KEY (`customer_id`) ' . 'REFERENCES `customer` (`customer_id`) ON UPDATE CASCADE', - CreateDefinition::build($parser->statements[0]->fields[2]) + $parser->statements[0]->fields[2]->build() ); } @@ -125,15 +125,15 @@ public function testBuild3(): void $this->assertIsArray($parser->statements[1]->fields); $this->assertEquals( '`public_name` varchar(120) COLLATE utf8_unicode_ci NOT NULL', - CreateDefinition::build($parser->statements[1]->fields[2]) + $parser->statements[1]->fields[2]->build() ); $this->assertEquals( '`show_separators` tinyint(1) NOT NULL DEFAULT \'0\'', - CreateDefinition::build($parser->statements[1]->fields[5]) + $parser->statements[1]->fields[5]->build() ); $this->assertEquals( '`show_separators_two` tinyint(1) NOT NULL DEFAULT FALSE', - CreateDefinition::build($parser->statements[1]->fields[6]) + $parser->statements[1]->fields[6]->build() ); } @@ -152,7 +152,7 @@ public function testBuildWithInvisibleKeyword(): void $this->assertIsArray($parser->statements[0]->fields); $this->assertEquals( '`customer_id` smallint(5) UNSIGNED NOT NULL INVISIBLE', - CreateDefinition::build($parser->statements[0]->fields[0]) + $parser->statements[0]->fields[0]->build() ); } diff --git a/tests/Components/FunctionCallTest.php b/tests/Components/FunctionCallTest.php index 3623412a6..cc1966250 100644 --- a/tests/Components/FunctionCallTest.php +++ b/tests/Components/FunctionCallTest.php @@ -13,12 +13,12 @@ class FunctionCallTest extends TestCase public function testBuildArray(): void { $component = new FunctionCall('func', ['a', 'b']); - $this->assertEquals('func(a, b)', FunctionCall::build($component)); + $this->assertEquals('func(a, b)', $component->build()); } public function testBuildArrayObj(): void { $component = new FunctionCall('func', new ArrayObj(['a', 'b'])); - $this->assertEquals('func(a, b)', FunctionCall::build($component)); + $this->assertEquals('func(a, b)', $component->build()); } } diff --git a/tests/Components/GroupKeywordTest.php b/tests/Components/GroupKeywordTest.php index 370e04c0d..93bf5be7b 100644 --- a/tests/Components/GroupKeywordTest.php +++ b/tests/Components/GroupKeywordTest.php @@ -62,7 +62,7 @@ public function testBuild($component, string $expected): void if (is_array($component)) { $this->assertSame($expected, GroupKeyword::buildAll($component)); } else { - $this->assertSame($expected, GroupKeyword::build($component)); + $this->assertSame($expected, $component->build()); } } diff --git a/tests/Components/IntoKeywordTest.php b/tests/Components/IntoKeywordTest.php index 4dea44cdb..0efe4c3ec 100644 --- a/tests/Components/IntoKeywordTest.php +++ b/tests/Components/IntoKeywordTest.php @@ -20,19 +20,19 @@ public function testParse(): void public function testBuild(): void { $component = IntoKeyword::parse(new Parser(), $this->getTokensList('tbl(`col1`, `col2`)')); - $this->assertEquals('tbl(`col1`, `col2`)', IntoKeyword::build($component)); + $this->assertEquals('tbl(`col1`, `col2`)', $component->build()); } public function testBuildValues(): void { $component = IntoKeyword::parse(new Parser(), $this->getTokensList('@a1, @a2, @a3')); - $this->assertEquals('@a1, @a2, @a3', IntoKeyword::build($component)); + $this->assertEquals('@a1, @a2, @a3', $component->build()); } public function testBuildOutfile(): void { $component = IntoKeyword::parse(new Parser(), $this->getTokensList('OUTFILE "/tmp/outfile.txt"')); - $this->assertEquals('OUTFILE "/tmp/outfile.txt"', IntoKeyword::build($component)); + $this->assertEquals('OUTFILE "/tmp/outfile.txt"', $component->build()); } public function testParseErr1(): void diff --git a/tests/Components/KeyTest.php b/tests/Components/KeyTest.php index 421a05d59..83f67fb8c 100644 --- a/tests/Components/KeyTest.php +++ b/tests/Components/KeyTest.php @@ -27,7 +27,7 @@ public function testParse(): void $this->assertSame([], $component->columns); $this->assertSame( '()', - Key::build($component) + $component->build() ); } @@ -44,7 +44,7 @@ public function testParseKeyWithoutOptions(): void $this->assertSame([['name' => 'alias_type']], $component->columns); $this->assertSame( 'KEY `alias_type_idx` (`alias_type`)', - Key::build($component) + $component->build() ); } @@ -61,7 +61,7 @@ public function testParseKeyWithLengthWithoutOptions(): void $this->assertSame([['name' => 'alias_type', 'length' => 10]], $component->columns); $this->assertSame( 'KEY `alias_type_idx` (`alias_type`(10))', - Key::build($component) + $component->build() ); } @@ -78,7 +78,7 @@ public function testParseKeyWithLengthWithoutOptionsWithOrder(): void $this->assertSame([['name' => 'alias_type', 'length' => 10, 'order' => 'ASC']], $component->columns); $this->assertSame( 'KEY `alias_type_idx` (`alias_type`(10) ASC)', - Key::build($component) + $component->build() ); } @@ -95,7 +95,7 @@ public function testParseKeyWithoutOptionsWithOrderLowercase(): void $this->assertSame([['name' => 'alias_type', 'order' => 'DESC']], $component->columns); $this->assertSame( 'KEY `alias_type_idx` (`alias_type` DESC)', - Key::build($component) + $component->build() ); } @@ -112,7 +112,7 @@ public function testParseKeyWithoutOptionsWithOrder(): void $this->assertSame([['name' => 'alias_type', 'order' => 'DESC']], $component->columns); $this->assertSame( 'KEY `alias_type_idx` (`alias_type` DESC)', - Key::build($component) + $component->build() ); } @@ -138,7 +138,7 @@ public function testParseKeyWithLengthWithOptions(): void $this->assertSame([['name' => 'alias_type', 'length' => 10]], $component->columns); $this->assertSame( 'KEY `alias_type_idx` (`alias_type`(10)) COMMENT \'my comment\'', - Key::build($component) + $component->build() ); } @@ -213,7 +213,7 @@ public function testParseKeyExpressionWithoutOptions(): void $this->assertSame([], $component->columns); $this->assertSame( 'KEY `updated_tz_ind2` ((convert_tz(`cache_updated`,_utf8mb4\'GMT\',_utf8mb4\'GB\'))) ', - Key::build($component) + $component->build() ); } @@ -247,7 +247,7 @@ public function testParseKeyExpressionWithOptions(): void 'KEY `updated_tz_ind2`' . ' ((convert_tz(`cache_updated`,_utf8mb4\'GMT\',_utf8mb4\'GB\')))' . ' COMMENT \'my comment\'', - Key::build($component) + $component->build() ); } @@ -281,7 +281,7 @@ public function testParseKeyExpressionWithOptionsError(): void $this->assertSame([], $component->columns); $this->assertSame( 'KEY `updated_tz_ind2` (()(`cache_updated`,_utf8mb4\'GMT\',_utf8mb4\'GB\')) ', - Key::build($component) + $component->build() ); } @@ -323,7 +323,7 @@ public function testParseKeyOneExpressionWithOptions(): void 'KEY `updated_tz_ind2` ((convert_tz(`cache_updated`,_utf8mb4\'GMT\',_utf8mb4\'GB\')),' . ' (convert_tz(`cache_updated`,_utf8mb4\'GMT\',_utf8mb4\'FR\'))' . ') COMMENT \'my comment\'', - Key::build($component) + $component->build() ); } @@ -368,7 +368,7 @@ public function testParseKeyMultipleExpressionsWithOptions(): void . ' (convert_tz(`cache_updated`,_utf8mb4\'GMT\',_utf8mb4\'FR\')),' . ' (convert_tz(`cache_updated`,_utf8mb4\'GMT\',_utf8mb4\'RU\'))' . ') COMMENT \'my comment\'', - Key::build($component) + $component->build() ); } } diff --git a/tests/Components/LimitTest.php b/tests/Components/LimitTest.php index 5f35c7710..2f6baa252 100644 --- a/tests/Components/LimitTest.php +++ b/tests/Components/LimitTest.php @@ -13,13 +13,13 @@ class LimitTest extends TestCase public function testBuildWithoutOffset(): void { $component = new Limit(1); - $this->assertEquals(Limit::build($component), '0, 1'); + $this->assertEquals($component->build(), '0, 1'); } public function testBuildWithOffset(): void { $component = new Limit(1, 2); - $this->assertEquals(Limit::build($component), '2, 1'); + $this->assertEquals($component->build(), '2, 1'); } #[DataProvider('parseProvider')] diff --git a/tests/Components/OptionsArrayTest.php b/tests/Components/OptionsArrayTest.php index b10eb5711..daed0ac23 100644 --- a/tests/Components/OptionsArrayTest.php +++ b/tests/Components/OptionsArrayTest.php @@ -127,7 +127,7 @@ public function testBuild(): void ] ); $this->assertEquals( - OptionsArray::build($component), + $component->build(), 'ALL SQL_CALC_FOUND_ROWS MAX_STATEMENT_TIME=42' ); } diff --git a/tests/Components/ReferenceTest.php b/tests/Components/ReferenceTest.php index fd8fb58dd..8cc455f3c 100644 --- a/tests/Components/ReferenceTest.php +++ b/tests/Components/ReferenceTest.php @@ -21,6 +21,6 @@ public function testParse(): void public function testBuild(): void { $component = new Reference(new Expression('`tbl`'), ['id']); - $this->assertEquals('`tbl` (`id`)', Reference::build($component)); + $this->assertEquals('`tbl` (`id`)', $component->build()); } } diff --git a/tests/Parser/WithStatementTest.php b/tests/Parser/WithStatementTest.php index 1c0c788ad..c4404737f 100644 --- a/tests/Parser/WithStatementTest.php +++ b/tests/Parser/WithStatementTest.php @@ -135,6 +135,6 @@ public function testWithHasUnclosedParenthesis(): void public function testBuildBadWithKeyword(): void { $this->expectExceptionMessage('No statement inside WITH'); - WithKeyword::build(new WithKeyword('test')); + (new WithKeyword('test'))->build(); } }