Skip to content

Commit 856349d

Browse files
committed
Up the packages & fix CS issues
1 parent 8500a9c commit 856349d

16 files changed

+55
-58
lines changed

activate.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
function sqlite_plugin_activation_redirect( $plugin ) {
1717
if ( plugin_basename( SQLITE_MAIN_FILE ) === $plugin ) {
18-
if( wp_safe_redirect( admin_url( 'options-general.php?page=sqlite-integration' ) ) ) {
18+
if ( wp_safe_redirect( admin_url( 'options-general.php?page=sqlite-integration' ) ) ) {
1919
exit;
2020
}
2121
}

composer.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
},
1313
"require-dev": {
1414
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.0",
15-
"squizlabs/php_codesniffer": "3.7.0",
16-
"wp-coding-standards/wpcs": "~2.3.0",
17-
"phpcompatibility/phpcompatibility-wp": "~2.1.3",
15+
"squizlabs/php_codesniffer": "^3.7",
16+
"wp-coding-standards/wpcs": "^3.0",
17+
"phpcompatibility/phpcompatibility-wp": "^2.1",
1818
"yoast/phpunit-polyfills": "^1.0.1"
1919
},
2020
"config": {

deactivate.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function sqlite_plugin_remove_db_file() {
3333
// Run an action on `shutdown`, to deactivate the option in the MySQL database.
3434
add_action(
3535
'shutdown',
36-
function() {
36+
function () {
3737
global $table_prefix;
3838

3939
// Get credentials for the MySQL database.

phpcs.xml.dist

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424

2525
<rule ref="WordPress-Core"/>
2626
<rule ref="WordPress-Docs"/>
27-
<rule ref="WordPress.CodeAnalysis.EmptyStatement"/>
2827

2928
<!-- Directories and third party library exclusions. -->
3029
<exclude-pattern>/vendor/*</exclude-pattern>
30+
<exclude-pattern>/tests/*</exclude-pattern>
3131

3232
<!-- Allow the WP DB Class and related tests for usage of direct database access functions. -->
3333
<rule ref="WordPress.DB.RestrictedClasses.mysql__PDO">

tests/WP_SQLite_Metadata_Tests.php

-1
Original file line numberDiff line numberDiff line change
@@ -318,5 +318,4 @@ public function testBogusQuery() {
318318
$actual
319319
);
320320
}
321-
322321
}

tests/WP_SQLite_PDO_User_Defined_Functions_Tests.php

-1
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,4 @@ function dataProviderForTestFieldFunction() {
2424
array( 2, array( 'User 0000019', 'User 0000018', 'User 0000019', 'User 0000020' ) ),
2525
);
2626
}
27-
2827
}

tests/WP_SQLite_Query_RewriterTests.php

-1
Original file line numberDiff line numberDiff line change
@@ -78,5 +78,4 @@ public function skip_over() {
7878
$this->assertEquals( ' ', $buffer[1]->value );
7979
$this->assertEquals( 'UPDATE', $buffer[2]->value );
8080
}
81-
8281
}

tests/WP_SQLite_Query_Tests.php

+3-4
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function setUp(): void {
7373
}
7474

7575
/* Mock up some metadata rows. When meta_key starts with _, the custom field isn't visible to the editor. */
76-
for ( $i = 1; $i <= 40; $i ++ ) {
76+
for ( $i = 1; $i <= 40; $i++ ) {
7777
$k1 = 'visible_meta_key_' . str_pad( $i, 2, '0', STR_PAD_LEFT );
7878
$k2 = '_invisible_meta_key_%_percent' . str_pad( $i, 2, '0', STR_PAD_LEFT );
7979
$this->assertQuery(
@@ -413,7 +413,7 @@ public function testDeleteExpiredNonSiteTransients() {
413413
$count_unexpired = 0;
414414
foreach ( $actual as $row ) {
415415
if ( str_starts_with( $row->option_name, '_transient' ) ) {
416-
$count_unexpired ++;
416+
++$count_unexpired;
417417
$this->assertGreaterThan( $now, $row->option_timeout );
418418
}
419419
}
@@ -478,7 +478,7 @@ public function testRecoverSerialized() {
478478
$unserialized = unserialize( $retrieved_string );
479479
$this->assertEquals( $obj, $unserialized );
480480

481-
$obj ['two'] ++;
481+
++$obj ['two'];
482482
$obj ['pi'] *= 2;
483483
$option_value = serialize( $obj );
484484
$option_value_escaped = $this->engine->get_pdo()->quote( $option_value );
@@ -533,5 +533,4 @@ private function assertQuery( $sql ) {
533533

534534
return $retval;
535535
}
536-
537536
}

tests/WP_SQLite_Translator_Tests.php

-6
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,6 @@ public function testAlterTableModifyColumnComplexChange() {
672672
$result = $this->engine->query( "INSERT INTO _tmp_table (ID, firstname, lastname, datetime) VALUES (6, 'Sophie', 'Bar', '2010-01-01 12:53:13');" );
673673
$this->assertEquals( '', $this->engine->get_error_message() );
674674
$this->assertEquals( 1, $result );
675-
676675
}
677676

678677
public function testCaseInsensitiveUniqueIndex() {
@@ -727,7 +726,6 @@ public function testCaseInsensitiveUniqueIndex() {
727726

728727
$result1 = $this->engine->query( 'SELECT COUNT(*) num FROM _tmp_table;' );
729728
$this->assertEquals( 2, $result1[0]->num );
730-
731729
}
732730

733731
public function testOnDuplicateUpdate() {
@@ -966,7 +964,6 @@ public function testNestedTransactionWorkComplexModify() {
966964
),
967965
)
968966
);
969-
970967
}
971968

972969
public function testCount() {
@@ -1462,7 +1459,6 @@ public function testStringToFloatComparison() {
14621459
$this->assertQuery( "SELECT (0+'00.42' = 0.4200) as cmp;" );
14631460
$results = $this->engine->get_query_results();
14641461
$this->assertEquals( '1', $results[0]->cmp );
1465-
14661462
}
14671463

14681464
public function testZeroPlusStringToFloatComparison() {
@@ -1474,7 +1470,6 @@ public function testZeroPlusStringToFloatComparison() {
14741470
$this->assertQuery( "SELECT 0+'1234abcd' = 1234 as cmp;" );
14751471
$results = $this->engine->get_query_results();
14761472
$this->assertEquals( '1', $results[0]->cmp );
1477-
14781473
}
14791474

14801475
public function testCalcFoundRows() {
@@ -1789,5 +1784,4 @@ public function testTranslatesUtf8SELECT() {
17891784

17901785
$this->assertQuery( 'DELETE FROM _options' );
17911786
}
1792-
17931787
}

tests/wp-sqlite-schema.php

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<?php
2-
32
/**
43
* WordPress schema for unit tests for the SQLite database integration project.
54
*

wp-includes/sqlite/class-wp-sqlite-crosscheck-db.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php
1+
<?php // phpcs:ignoreFile
22

33
class WP_SQLite_Crosscheck_DB_ extends WP_SQLite_DB {
44

@@ -117,13 +117,11 @@ private function crosscheck( $query, $sqlite_retval ) {
117117
break;
118118
}
119119
}
120-
121120
}
122121

123122
private function report_factor( $factor, $mysql, $sqlite ) {
124123
echo "$factor: \n";
125124
echo ' MySQL: ' . var_export( $mysql, true ) . "\n";
126125
echo ' SQLite: ' . var_export( $sqlite, true ) . "\n\n";
127126
}
128-
129127
}

wp-includes/sqlite/class-wp-sqlite-db.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public function select( $db, $dbh = null ) {
103103
*
104104
* @return string escaped
105105
*/
106-
function _real_escape( $str ) {
106+
public function _real_escape( $str ) {
107107
return addslashes( $str );
108108
}
109109

@@ -278,7 +278,7 @@ public function query( $query ) {
278278
}
279279

280280
$this->result = $this->dbh->query( $query );
281-
$this->num_queries++;
281+
++$this->num_queries;
282282

283283
if ( defined( 'SAVEQUERIES' ) && SAVEQUERIES ) {
284284
$this->queries[] = array( $query, $this->timer_stop(), $this->get_caller() );

wp-includes/sqlite/class-wp-sqlite-pdo-user-defined-functions.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ public function month( $field ) {
221221
* From https://www.php.net/manual/en/datetime.format.php:
222222
*
223223
* n - Numeric representation of a month, without leading zeros.
224-
* 1 through 12
224+
* 1 through 12
225225
*/
226226
return intval( gmdate( 'n', strtotime( $field ) ) );
227227
}
@@ -446,14 +446,14 @@ public function isnull( $field ) {
446446
*
447447
* As 'IF' is a reserved word for PHP, function name must be changed.
448448
*
449-
* @param mixed $expression the statement to be evaluated as true or false.
450-
* @param mixed $true statement or value returned if $expression is true.
451-
* @param mixed $false statement or value returned if $expression is false.
449+
* @param mixed $expression The statement to be evaluated as true or false.
450+
* @param mixed $truthy Statement or value returned if $expression is true.
451+
* @param mixed $falsy Statement or value returned if $expression is false.
452452
*
453453
* @return mixed
454454
*/
455-
public function _if( $expression, $true, $false ) {
456-
return ( true === $expression ) ? $true : $false;
455+
public function _if( $expression, $truthy, $falsy ) {
456+
return ( true === $expression ) ? $truthy : $falsy;
457457
}
458458

459459
/**

wp-includes/sqlite/class-wp-sqlite-translator.php

+33-24
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ class WP_SQLite_Translator {
266266
/**
267267
* Variable to keep track of nested transactions level.
268268
*
269-
* @var number
269+
* @var int
270270
*/
271271
private $transaction_level = 0;
272272

@@ -335,6 +335,13 @@ class WP_SQLite_Translator {
335335
*/
336336
private $sqlite_system_tables = array();
337337

338+
/**
339+
* The last error message from SQLite.
340+
*
341+
* @var string
342+
*/
343+
private $last_sqlite_error;
344+
338345
/**
339346
* Constructor.
340347
*
@@ -408,7 +415,8 @@ public function __construct( $pdo = null ) {
408415

409416
// WordPress happens to use no foreign keys.
410417
$statement = $this->pdo->query( 'PRAGMA foreign_keys' );
411-
if ( $statement->fetchColumn( 0 ) == '0' ) { // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
418+
// phpcs:ignore Universal.Operators.StrictComparisons.LooseEqual
419+
if ( $statement->fetchColumn( 0 ) == '0' ) {
412420
$this->pdo->query( 'PRAGMA foreign_keys = ON' );
413421
}
414422
$this->pdo->query( 'PRAGMA encoding="UTF-8";' );
@@ -422,7 +430,7 @@ public function __construct( $pdo = null ) {
422430
*
423431
* This definition is changed since version 1.7.
424432
*/
425-
function __destruct() {
433+
public function __destruct() {
426434
if ( defined( 'SQLITE_MEM_DEBUG' ) && SQLITE_MEM_DEBUG ) {
427435
$max = ini_get( 'memory_limit' );
428436
if ( is_null( $max ) ) {
@@ -756,9 +764,9 @@ public function get_return_value() {
756764
* @throws Exception If the query is not supported.
757765
*/
758766
private function execute_mysql_query( $query ) {
759-
$tokens = ( new WP_SQLite_Lexer( $query ) )->tokens;
760-
$this->rewriter = new WP_SQLite_Query_Rewriter( $tokens );
761-
$this->query_type = $this->rewriter->peek()->value;
767+
$tokens = ( new WP_SQLite_Lexer( $query ) )->tokens;
768+
$this->rewriter = new WP_SQLite_Query_Rewriter( $tokens );
769+
$this->query_type = $this->rewriter->peek()->value;
762770

763771
switch ( $this->query_type ) {
764772
case 'ALTER':
@@ -1392,7 +1400,8 @@ private function execute_select() {
13921400
$this->remember_last_reserved_keyword( $token );
13931401

13941402
if ( ! $table_name ) {
1395-
$this->table_name = $table_name = $this->peek_table_name( $token );
1403+
$this->table_name = $this->peek_table_name( $token );
1404+
$table_name = $this->peek_table_name( $token );
13961405
}
13971406

13981407
if ( $this->skip_sql_calc_found_rows( $token ) ) {
@@ -1484,7 +1493,7 @@ private function execute_truncate() {
14841493
private function execute_describe() {
14851494
$this->rewriter->skip();
14861495
$this->table_name = $this->rewriter->consume()->value;
1487-
$stmt = $this->execute_sqlite_query(
1496+
$stmt = $this->execute_sqlite_query(
14881497
"SELECT
14891498
`name` as `Field`,
14901499
(
@@ -1541,10 +1550,10 @@ private function execute_update() {
15411550
break;
15421551
}
15431552

1544-
// Record the table name
1553+
// Record the table name.
15451554
if (
1546-
!$this->table_name &&
1547-
!$token->matches(
1555+
! $this->table_name &&
1556+
! $token->matches(
15481557
WP_SQLite_Token::TYPE_KEYWORD,
15491558
WP_SQLite_Token::FLAG_KEYWORD_RESERVED
15501559
)
@@ -1664,7 +1673,7 @@ private function execute_insert_or_replace() {
16641673
if ( is_numeric( $this->last_insert_id ) ) {
16651674
$this->last_insert_id = (int) $this->last_insert_id;
16661675
}
1667-
$this->last_insert_id = apply_filters('sqlite_last_insert_id', $this->last_insert_id, $this->table_name);
1676+
$this->last_insert_id = apply_filters( 'sqlite_last_insert_id', $this->last_insert_id, $this->table_name );
16681677
}
16691678

16701679
/**
@@ -1753,7 +1762,7 @@ private function preprocess_like_expr( &$token ) {
17531762
/* Remove the quotes around the name. */
17541763
$unescaped_value = mb_substr( $token->token, 1, -1, 'UTF-8' );
17551764
if ( str_contains( $unescaped_value, '\_' ) || str_contains( $unescaped_value, '\%' ) ) {
1756-
$this->like_escape_count ++;
1765+
++$this->like_escape_count;
17571766
return str_replace(
17581767
array( '\_', '\%' ),
17591768
array( self::LIKE_ESCAPE_CHAR . '_', self::LIKE_ESCAPE_CHAR . '%' ),
@@ -2379,14 +2388,14 @@ private function translate_like_escape( $token ) {
23792388
} else {
23802389
/* open parenthesis during LIKE parameter, count it. */
23812390
if ( $token->matches( WP_SQLite_Token::TYPE_OPERATOR, null, array( '(' ) ) ) {
2382-
$this->like_expression_nesting ++;
2391+
++$this->like_expression_nesting;
23832392

23842393
return false;
23852394
}
23862395

23872396
/* close parenthesis matching open parenthesis during LIKE parameter, count it. */
23882397
if ( $this->like_expression_nesting > 1 && $token->matches( WP_SQLite_Token::TYPE_OPERATOR, null, array( ')' ) ) ) {
2389-
$this->like_expression_nesting --;
2398+
--$this->like_expression_nesting;
23902399

23912400
return false;
23922401
}
@@ -2664,7 +2673,7 @@ private function execute_alter() {
26642673
$op_type = strtoupper( $this->rewriter->consume()->token );
26652674
$op_subject = strtoupper( $this->rewriter->consume()->token );
26662675
$mysql_index_type = $this->normalize_mysql_index_type( $op_subject );
2667-
$is_index_op = ! ! $mysql_index_type;
2676+
$is_index_op = (bool) $mysql_index_type;
26682677

26692678
if ( 'ADD' === $op_type && 'COLUMN' === $op_subject ) {
26702679
$column_name = $this->rewriter->consume()->value;
@@ -3436,16 +3445,16 @@ private function handle_error( Exception $err ) {
34363445
* When $wpdb::suppress_errors is set to true or $wpdb::show_errors is set to false,
34373446
* the error messages are ignored.
34383447
*
3439-
* @param string $line Where the error occurred.
3440-
* @param string $function Indicate the function name where the error occurred.
3441-
* @param string $message The message.
3448+
* @param string $line Where the error occurred.
3449+
* @param string $function_name Indicate the function name where the error occurred.
3450+
* @param string $message The message.
34423451
*
34433452
* @return boolean|void
34443453
*/
3445-
private function set_error( $line, $function, $message ) {
3454+
private function set_error( $line, $function_name, $message ) {
34463455
$this->errors[] = array(
34473456
'line' => $line,
3448-
'function' => $function,
3457+
'function' => $function_name,
34493458
);
34503459
$this->error_messages[] = $message;
34513460
$this->is_error = true;
@@ -3640,7 +3649,7 @@ public function begin_transaction() {
36403649
*
36413650
* @since 0.1.0
36423651
*/
3643-
do_action( 'sqlite_transaction_query_executed', 'START TRANSACTION', !!$this->last_exec_returned, $this->transaction_level - 1 );
3652+
do_action( 'sqlite_transaction_query_executed', 'START TRANSACTION', (bool) $this->last_exec_returned, $this->transaction_level - 1 );
36443653
}
36453654
}
36463655
return $success;
@@ -3663,7 +3672,7 @@ public function commit() {
36633672
$this->execute_sqlite_query( 'RELEASE SAVEPOINT LEVEL' . $this->transaction_level );
36643673
}
36653674

3666-
do_action( 'sqlite_transaction_query_executed', 'COMMIT', !!$this->last_exec_returned, $this->transaction_level );
3675+
do_action( 'sqlite_transaction_query_executed', 'COMMIT', (bool) $this->last_exec_returned, $this->transaction_level );
36673676
return $this->last_exec_returned;
36683677
}
36693678

@@ -3683,7 +3692,7 @@ public function rollback() {
36833692
} else {
36843693
$this->execute_sqlite_query( 'ROLLBACK TO SAVEPOINT LEVEL' . $this->transaction_level );
36853694
}
3686-
do_action( 'sqlite_transaction_query_executed', 'ROLLBACK', !!$this->last_exec_returned, $this->transaction_level );
3695+
do_action( 'sqlite_transaction_query_executed', 'ROLLBACK', (bool) $this->last_exec_returned, $this->transaction_level );
36873696
return $this->last_exec_returned;
36883697
}
36893698
}

0 commit comments

Comments
 (0)