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 4, 2024
1 parent 2c54702 commit 7450a3f
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 15 deletions.
40 changes: 39 additions & 1 deletion phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

<!-- Directories and third party library exclusions. -->
<exclude-pattern>/vendor/*</exclude-pattern>
<exclude-pattern>/tests/*</exclude-pattern>
<!-- <exclude-pattern>/tests/*</exclude-pattern> -->

<!-- Allow the WP DB Class and related tests for usage of direct database access functions. -->
<rule ref="WordPress.DB.RestrictedClasses.mysql__PDO">
Expand All @@ -36,4 +36,42 @@
<rule ref="WordPress.DB.RestrictedFunctions">
<exclude-pattern>/wp-includes/*.php</exclude-pattern>
</rule>

<!-- Disable some more checks. -->
<rule ref="Generic.Commenting.Todo.CommentFound">
<severity>0</severity>
</rule>
<rule ref="Squiz.Commenting.LongConditionClosingComment.Missing">
<severity>0</severity>
</rule>
<rule ref="Squiz.Commenting.PostStatementComment.Found">
<severity>0</severity>
</rule>

<!-- Disable some tests for the tests/ files. -->
<rule ref="Squiz.Commenting">
<exclude-pattern>/tests/*</exclude-pattern>
<exclude-pattern>/wp-includes/sqlite/class-wp-sqlite-crosscheck-db.php</exclude-pattern>
</rule>
<rule ref="WordPress.DB.RestrictedClasses.mysql__PDO">
<exclude-pattern>/tests/*</exclude-pattern>
<exclude-pattern>/wp-includes/sqlite/class-wp-sqlite-crosscheck-db.php</exclude-pattern>
</rule>
<rule ref="Generic.Commenting">
<exclude-pattern>/tests/*</exclude-pattern>
<exclude-pattern>/wp-includes/sqlite/class-wp-sqlite-crosscheck-db.php</exclude-pattern>
</rule>
<rule ref="WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase">
<exclude-pattern>/tests/*</exclude-pattern>
<exclude-pattern>/wp-includes/sqlite/class-wp-sqlite-crosscheck-db.php</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>
4 changes: 2 additions & 2 deletions tests/WP_SQLite_Metadata_Tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,14 +269,14 @@ function ( $row ) {
$this->assertEquals( 4, $rows[0]->Rows );
}

private function assertTableEmpty( $table_name, $empty ) {
private function assertTableEmpty( $table_name, $empty_var ) {

$this->assertQuery(
"SELECT COUNT(*) num FROM $table_name"
);

$actual = $this->engine->get_query_results();
if ( $empty ) {
if ( $empty_var ) {
$this->assertEquals( 0, $actual[0]->num, "$table_name is not empty" );
} else {
$this->assertGreaterThan( 0, $actual[0]->num, "$table_name is empty" );
Expand Down
2 changes: 1 addition & 1 deletion tests/WP_SQLite_PDO_User_Defined_Functions_Tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function testFieldFunction( $expected, $args ) {
);
}

function dataProviderForTestFieldFunction() {
public function dataProviderForTestFieldFunction() {
return array(
array( 1, array( 'a', 'a' ) ),
array( 2, array( 'User 0000019', 'User 0000018', 'User 0000019', 'User 0000020' ) ),
Expand Down
14 changes: 7 additions & 7 deletions tests/WP_SQLite_Translator_Tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public function regexpOperators() {
'ID' => '1',
'option_name' => 'rss_123',
);
$uppercase_RSS = (object) array(
$uppercase_rss = (object) array(
'ID' => '2',
'option_name' => 'RSS_123',
);
Expand All @@ -108,8 +108,8 @@ public function regexpOperators() {
return array(
array( 'REGEXP', '^RSS_.+$', $lowercase_rss ),
array( 'RLIKE', '^RSS_.+$', $lowercase_rss ),
array( 'REGEXP BINARY', '^RSS_.+$', $uppercase_RSS ),
array( 'RLIKE BINARY', '^RSS_.+$', $uppercase_RSS ),
array( 'REGEXP BINARY', '^RSS_.+$', $uppercase_rss ),
array( 'RLIKE BINARY', '^RSS_.+$', $uppercase_rss ),
array( 'NOT REGEXP', '^RSS_.+$', $lowercase_transient ),
array( 'NOT RLIKE', '^RSS_.+$', $lowercase_transient ),
array( 'NOT REGEXP BINARY', '^RSS_.+$', $lowercase_rss ),
Expand All @@ -126,7 +126,7 @@ public function testInsertDateNow() {

$results = $this->engine->get_query_results();
$this->assertCount( 1, $results );
$this->assertEquals( date( 'Y' ), $results[0]->y );
$this->assertEquals( gmdate( 'Y' ), $results[0]->y );
}

public function testCastAsBinary() {
Expand Down Expand Up @@ -879,7 +879,7 @@ public function testCorrectlyInsertsDatesAndStrings() {
$results = $this->engine->get_query_results();
$this->assertCount( 1, $results );
$this->assertEquals( '2016-01-15 00:00:00', $results[0]->option_value );
if ( $results[0]->option_name !== '2016-01-15T00:00:00Z' ) {
if ( '2016-01-15T00:00:00Z' !== $results[0]->option_name ) {
$this->markTestSkipped( 'A datetime-like string was rewritten to an SQLite format even though it was used as a text and not as a datetime.' );
}
$this->assertEquals( '2016-01-15T00:00:00Z', $results[0]->option_name );
Expand Down Expand Up @@ -1491,7 +1491,7 @@ public function testInsertOnDuplicateKeyCompositePk() {
public function testStringToFloatComparison() {
$this->assertQuery( "SELECT ('00.42' = 0.4200) as cmp;" );
$results = $this->engine->get_query_results();
if ( $results[0]->cmp !== 1 ) {
if ( 1 !== $results[0]->cmp ) {
$this->markTestSkipped( 'Comparing a string and a float returns true in MySQL. In SQLite, they\'re different. Skipping. ' );
}
$this->assertEquals( '1', $results[0]->cmp );
Expand Down Expand Up @@ -1566,7 +1566,7 @@ public function testUpdateReturnValue() {
$return = $this->assertQuery(
"UPDATE _dates SET option_value = '2001-05-27 10:08:48'"
);
if ( $return === 1 ) {
if ( 1 === $return ) {
$this->markTestIncomplete(
'SQLite UPDATE query returned 1 when no rows were changed. ' .
'This is a database compatibility issue – MySQL would return 0 ' .
Expand Down
8 changes: 4 additions & 4 deletions wp-includes/sqlite/class-wp-sqlite-crosscheck-db.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php // phpcs:ignoreFile
<?php

class WP_SQLite_Crosscheck_DB_ extends WP_SQLite_DB {

Expand Down Expand Up @@ -74,18 +74,18 @@ private function crosscheck( $query, $sqlite_retval ) {
foreach ( $tests as $test ) {
list($factor, $mysql, $sqlite) = $test;
if ( $mysql !== $sqlite ) {
if ( $factor === 'insert_id' ) {
if ( 'insert_id' === $factor ) {
// On multi-inserts MySQL returns the first inserted ID
// while SQLite returns the last one. The cached insert_id
// value stays the same for a number of subsequent queries.
// Let's forgive this for now.
continue;
}
if ( $factor === 'rows_affected' && $mysql_retval === $mysql ) {
if ( 'rows_affected' === $factor && $mysql_retval === $mysql ) {
// SQLite doesn't provide the rowcount() functionality
continue;
}
if ( $factor === 'retval' && $GLOBALS['mysql']->rows_affected === $mysql ) {
if ( 'retval' === $factor && $GLOBALS['mysql']->rows_affected === $mysql ) {
// SQLite doesn't provide the rowcount() functionality
continue;
}
Expand Down

0 comments on commit 7450a3f

Please sign in to comment.