@@ -266,7 +266,7 @@ class WP_SQLite_Translator {
266
266
/**
267
267
* Variable to keep track of nested transactions level.
268
268
*
269
- * @var number
269
+ * @var int
270
270
*/
271
271
private $ transaction_level = 0 ;
272
272
@@ -335,6 +335,13 @@ class WP_SQLite_Translator {
335
335
*/
336
336
private $ sqlite_system_tables = array ();
337
337
338
+ /**
339
+ * The last error message from SQLite.
340
+ *
341
+ * @var string
342
+ */
343
+ private $ last_sqlite_error ;
344
+
338
345
/**
339
346
* Constructor.
340
347
*
@@ -408,7 +415,8 @@ public function __construct( $pdo = null ) {
408
415
409
416
// WordPress happens to use no foreign keys.
410
417
$ 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 ' ) {
412
420
$ this ->pdo ->query ( 'PRAGMA foreign_keys = ON ' );
413
421
}
414
422
$ this ->pdo ->query ( 'PRAGMA encoding="UTF-8"; ' );
@@ -422,7 +430,7 @@ public function __construct( $pdo = null ) {
422
430
*
423
431
* This definition is changed since version 1.7.
424
432
*/
425
- function __destruct () {
433
+ public function __destruct () {
426
434
if ( defined ( 'SQLITE_MEM_DEBUG ' ) && SQLITE_MEM_DEBUG ) {
427
435
$ max = ini_get ( 'memory_limit ' );
428
436
if ( is_null ( $ max ) ) {
@@ -756,9 +764,9 @@ public function get_return_value() {
756
764
* @throws Exception If the query is not supported.
757
765
*/
758
766
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 ;
762
770
763
771
switch ( $ this ->query_type ) {
764
772
case 'ALTER ' :
@@ -1392,7 +1400,8 @@ private function execute_select() {
1392
1400
$ this ->remember_last_reserved_keyword ( $ token );
1393
1401
1394
1402
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 );
1396
1405
}
1397
1406
1398
1407
if ( $ this ->skip_sql_calc_found_rows ( $ token ) ) {
@@ -1484,7 +1493,7 @@ private function execute_truncate() {
1484
1493
private function execute_describe () {
1485
1494
$ this ->rewriter ->skip ();
1486
1495
$ this ->table_name = $ this ->rewriter ->consume ()->value ;
1487
- $ stmt = $ this ->execute_sqlite_query (
1496
+ $ stmt = $ this ->execute_sqlite_query (
1488
1497
"SELECT
1489
1498
`name` as `Field`,
1490
1499
(
@@ -1541,10 +1550,10 @@ private function execute_update() {
1541
1550
break ;
1542
1551
}
1543
1552
1544
- // Record the table name
1553
+ // Record the table name.
1545
1554
if (
1546
- !$ this ->table_name &&
1547
- !$ token ->matches (
1555
+ ! $ this ->table_name &&
1556
+ ! $ token ->matches (
1548
1557
WP_SQLite_Token::TYPE_KEYWORD ,
1549
1558
WP_SQLite_Token::FLAG_KEYWORD_RESERVED
1550
1559
)
@@ -1664,7 +1673,7 @@ private function execute_insert_or_replace() {
1664
1673
if ( is_numeric ( $ this ->last_insert_id ) ) {
1665
1674
$ this ->last_insert_id = (int ) $ this ->last_insert_id ;
1666
1675
}
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 );
1668
1677
}
1669
1678
1670
1679
/**
@@ -1753,7 +1762,7 @@ private function preprocess_like_expr( &$token ) {
1753
1762
/* Remove the quotes around the name. */
1754
1763
$ unescaped_value = mb_substr ( $ token ->token , 1 , -1 , 'UTF-8 ' );
1755
1764
if ( str_contains ( $ unescaped_value , '\_ ' ) || str_contains ( $ unescaped_value , '\% ' ) ) {
1756
- $ this ->like_escape_count ++ ;
1765
+ ++ $ this ->like_escape_count ;
1757
1766
return str_replace (
1758
1767
array ( '\_ ' , '\% ' ),
1759
1768
array ( self ::LIKE_ESCAPE_CHAR . '_ ' , self ::LIKE_ESCAPE_CHAR . '% ' ),
@@ -2379,14 +2388,14 @@ private function translate_like_escape( $token ) {
2379
2388
} else {
2380
2389
/* open parenthesis during LIKE parameter, count it. */
2381
2390
if ( $ token ->matches ( WP_SQLite_Token::TYPE_OPERATOR , null , array ( '( ' ) ) ) {
2382
- $ this ->like_expression_nesting ++ ;
2391
+ ++ $ this ->like_expression_nesting ;
2383
2392
2384
2393
return false ;
2385
2394
}
2386
2395
2387
2396
/* close parenthesis matching open parenthesis during LIKE parameter, count it. */
2388
2397
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 ;
2390
2399
2391
2400
return false ;
2392
2401
}
@@ -2664,7 +2673,7 @@ private function execute_alter() {
2664
2673
$ op_type = strtoupper ( $ this ->rewriter ->consume ()->token );
2665
2674
$ op_subject = strtoupper ( $ this ->rewriter ->consume ()->token );
2666
2675
$ 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 ;
2668
2677
2669
2678
if ( 'ADD ' === $ op_type && 'COLUMN ' === $ op_subject ) {
2670
2679
$ column_name = $ this ->rewriter ->consume ()->value ;
@@ -3436,16 +3445,16 @@ private function handle_error( Exception $err ) {
3436
3445
* When $wpdb::suppress_errors is set to true or $wpdb::show_errors is set to false,
3437
3446
* the error messages are ignored.
3438
3447
*
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.
3442
3451
*
3443
3452
* @return boolean|void
3444
3453
*/
3445
- private function set_error ( $ line , $ function , $ message ) {
3454
+ private function set_error ( $ line , $ function_name , $ message ) {
3446
3455
$ this ->errors [] = array (
3447
3456
'line ' => $ line ,
3448
- 'function ' => $ function ,
3457
+ 'function ' => $ function_name ,
3449
3458
);
3450
3459
$ this ->error_messages [] = $ message ;
3451
3460
$ this ->is_error = true ;
@@ -3640,7 +3649,7 @@ public function begin_transaction() {
3640
3649
*
3641
3650
* @since 0.1.0
3642
3651
*/
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 );
3644
3653
}
3645
3654
}
3646
3655
return $ success ;
@@ -3663,7 +3672,7 @@ public function commit() {
3663
3672
$ this ->execute_sqlite_query ( 'RELEASE SAVEPOINT LEVEL ' . $ this ->transaction_level );
3664
3673
}
3665
3674
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 );
3667
3676
return $ this ->last_exec_returned ;
3668
3677
}
3669
3678
@@ -3683,7 +3692,7 @@ public function rollback() {
3683
3692
} else {
3684
3693
$ this ->execute_sqlite_query ( 'ROLLBACK TO SAVEPOINT LEVEL ' . $ this ->transaction_level );
3685
3694
}
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 );
3687
3696
return $ this ->last_exec_returned ;
3688
3697
}
3689
3698
}
0 commit comments