Skip to content

Commit

Permalink
More CS fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
aristath committed Apr 22, 2024
1 parent a02e9c8 commit 51288ba
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 19 deletions.
22 changes: 19 additions & 3 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,25 @@
<rule ref="WordPress.Files.FileName">
<exclude-pattern>/tests/*</exclude-pattern>
</rule>

<rule ref="WordPress.NamingConventions">
<rule ref="WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase">
<exclude-pattern>/wp-includes/sqlite/class-wp-sqlite-crosscheck-db.php</exclude-pattern>
</rule>
<rule ref="WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid">
<exclude-pattern>/tests/*</exclude-pattern>
</rule>

<rule ref="WordPress.Files.FileName.NotHyphenatedLowercase">
<exclude-pattern>/tests/*</exclude-pattern>
</rule>
<rule ref="WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase">
<exclude-pattern>/tests/*</exclude-pattern>
</rule>
<rule ref="WordPress.Files.FileName.InvalidClassFileName">
<exclude-pattern>/wp-includes/sqlite/class-wp-sqlite-crosscheck-db.php</exclude-pattern>
</rule>
<rule ref="Universal.Operators.DisallowShortTernary.Found">
<exclude-pattern>/wp-includes/sqlite/class-wp-sqlite-crosscheck-db.php</exclude-pattern>
</rule>
<rule ref="PEAR.NamingConventions.ValidClassName.Invalid">
<exclude-pattern>/wp-includes/sqlite/class-wp-sqlite-crosscheck-db.php</exclude-pattern>
</rule>
</ruleset>
18 changes: 9 additions & 9 deletions tests/WP_SQLite_Translator_Tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,8 @@ public function testShowCreateTable1() {
public function testShowCreateTableSimpleTable() {
$this->assertQuery(
'CREATE TABLE _tmp_table (
ID BIGINT NOT NULL
);'
ID BIGINT NOT NULL
);'
);

$this->assertQuery(
Expand All @@ -292,8 +292,8 @@ public function testShowCreateTableSimpleTable() {
$results = $this->engine->get_query_results();
$this->assertEquals(
'CREATE TABLE _tmp_table (
`ID` bigint NOT NULL
);',
`ID` bigint NOT NULL
);',
$results[0]->{'Create Table'}
);
}
Expand Down Expand Up @@ -321,11 +321,11 @@ public function testShowCreateTableWithAlterAndCreateIndex() {
$results = $this->engine->get_query_results();
$this->assertEquals(
'CREATE TABLE _tmp_table (
`ID` bigint PRIMARY KEY AUTO_INCREMENT NOT NULL,
`option_name` smallint NOT NULL DEFAULT 14,
`option_value` text NOT NULL,
KEY _tmp_table__option_name (option_name)
);',
`ID` bigint PRIMARY KEY AUTO_INCREMENT NOT NULL,
`option_name` smallint NOT NULL DEFAULT 14,
`option_value` text NOT NULL,
KEY _tmp_table__option_name (option_name)
);',
$results[0]->{'Create Table'}
);
}
Expand Down
28 changes: 21 additions & 7 deletions wp-includes/sqlite/class-wp-sqlite-translator.php
Original file line number Diff line number Diff line change
Expand Up @@ -1524,26 +1524,26 @@ private function skip_index_hint() {
return false;
}

$this->rewriter->skip(); // USE, FORCE, IGNORE
$this->rewriter->skip(); // INDEX, KEY
$this->rewriter->skip(); // USE, FORCE, IGNORE.
$this->rewriter->skip(); // INDEX, KEY.

$maybe_for = $this->rewriter->peek();
if ( $maybe_for && $maybe_for->matches(
WP_SQLite_Token::TYPE_KEYWORD,
WP_SQLite_Token::FLAG_KEYWORD_RESERVED,
array( 'FOR' )
) ) {
$this->rewriter->skip(); // FOR
$this->rewriter->skip(); // FOR.

$token = $this->rewriter->peek();
if ( $token && $token->matches(
WP_SQLite_Token::TYPE_KEYWORD,
WP_SQLite_Token::FLAG_KEYWORD_RESERVED,
array( 'JOIN', 'ORDER', 'GROUP' )
) ) {
$this->rewriter->skip(); // JOIN, ORDER, GROUP
$this->rewriter->skip(); // JOIN, ORDER, GROUP.
if ( 'BY' === strtoupper( $this->rewriter->peek()->value ) ) {
$this->rewriter->skip(); // BY
$this->rewriter->skip(); // BY.
}
}
}
Expand Down Expand Up @@ -1592,6 +1592,13 @@ private function execute_describe() {
}
}

/**
* Executes a SELECT statement.
*
* @param string $table_name The table name.
*
* @return array
*/
private function describe( $table_name ) {
return $this->execute_sqlite_query(
"SELECT
Expand Down Expand Up @@ -1709,7 +1716,7 @@ private function execute_update() {
$this->rewriter->consume();
}

// Wrap up the WHERE clause with the nested SELECT statement
// Wrap up the WHERE clause with the nested SELECT statement.
if ( $needs_closing_parenthesis ) {
$this->rewriter->add( new WP_SQLite_Token( ')', WP_SQLite_Token::TYPE_OPERATOR ) );
}
Expand Down Expand Up @@ -3374,7 +3381,7 @@ private function execute_show() {
return;

case 'TABLE STATUS': // FROM `database`.
// Match the optional [{FROM | IN} db_name]
// Match the optional [{FROM | IN} db_name].
$database_expression = $this->rewriter->consume();
if ( 'FROM' === $database_expression->token || 'IN' === $database_expression->token ) {
$this->rewriter->consume();
Expand Down Expand Up @@ -3470,6 +3477,13 @@ private function execute_show() {
}
}

/**
* Gets the columns from a table.
*
* @param string $table_name The table name.
*
* @return array The columns.
*/
private function get_columns_from( $table_name ) {
$stmt = $this->execute_sqlite_query(
"PRAGMA table_info(\"$table_name\");"
Expand Down

0 comments on commit 51288ba

Please sign in to comment.