update PHPCS ruleset and re-enable warnings

This commit is contained in:
Stefan Kalscheuer 2019-10-06 17:57:55 +02:00
parent 84cf79fd04
commit 3f5990f1f3
7 changed files with 60 additions and 65 deletions

View File

@ -134,10 +134,12 @@ class RoboFile extends Tasks {
*/ */
private function bundle() { private function bundle() {
$this->say( 'Bundling resources...' ); $this->say( 'Bundling resources...' );
$this->taskCopyDir( [ $this->taskCopyDir(
[
'inc' => $this->target_dir . '/' . $this->final_name . '/inc', 'inc' => $this->target_dir . '/' . $this->final_name . '/inc',
'views' => $this->target_dir . '/' . $this->final_name . '/views', 'views' => $this->target_dir . '/' . $this->final_name . '/views',
] )->run(); ]
)->run();
$this->_copy( 'statify-blacklist.php', $this->target_dir . '/' . $this->final_name . '/statify-blacklist.php' ); $this->_copy( 'statify-blacklist.php', $this->target_dir . '/' . $this->final_name . '/statify-blacklist.php' );
$this->_copy( 'LICENSE.md', $this->target_dir . '/' . $this->final_name . '/LICENSE.md' ); $this->_copy( 'LICENSE.md', $this->target_dir . '/' . $this->final_name . '/LICENSE.md' );
$this->_copy( 'README.md', $this->target_dir . '/' . $this->final_name . '/README.md' ); $this->_copy( 'README.md', $this->target_dir . '/' . $this->final_name . '/README.md' );

View File

@ -19,7 +19,7 @@
"type": "wordpress-plugin", "type": "wordpress-plugin",
"require": { "require": {
"php": ">=5.5", "php": ">=5.5",
"composer/installers": "~1.0" "composer/installers": "~1.7"
}, },
"require-dev": { "require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "^0.5", "dealerdirect/phpcodesniffer-composer-installer": "^0.5",
@ -27,8 +27,8 @@
"phpunit/phpunit": "*", "phpunit/phpunit": "*",
"phpunit/php-code-coverage": "*", "phpunit/php-code-coverage": "*",
"slowprog/composer-copy-file": "~0.2", "slowprog/composer-copy-file": "~0.2",
"squizlabs/php_codesniffer": "^3.4", "squizlabs/php_codesniffer": "^3.5",
"phpcompatibility/php-compatibility": "^9.2", "phpcompatibility/php-compatibility": "^9.3",
"wp-coding-standards/wpcs": "^2.1" "wp-coding-standards/wpcs": "^2.1"
}, },
"scripts": { "scripts": {

View File

@ -354,6 +354,8 @@ class StatifyBlacklist_Admin extends StatifyBlacklist {
array_flip( $expressions ), array_flip( $expressions ),
function ( $re ) { function ( $re ) {
// Check of preg_match() fails (warnings suppressed). // Check of preg_match() fails (warnings suppressed).
// phpcs:disable WordPress.PHP.NoSilencedErrors.Discouraged
return false === @preg_match( StatifyBlacklist::regex( $re, false ), null ); return false === @preg_match( StatifyBlacklist::regex( $re, false ), null );
} }
); );

View File

@ -2,7 +2,7 @@
<ruleset name="StatifyBlacklist"> <ruleset name="StatifyBlacklist">
<description>Derived from WordPress Coding Standard</description> <description>Derived from WordPress Coding Standard</description>
<arg value="psvn"/> <arg value="psv"/>
<arg name="colors"/> <arg name="colors"/>
<!-- Files to sniff --> <!-- Files to sniff -->
@ -13,13 +13,9 @@
<!-- Compliance with WordPress Coding Standard --> <!-- Compliance with WordPress Coding Standard -->
<config name="minimum_supported_wp_version" value="4.7"/> <config name="minimum_supported_wp_version" value="4.7"/>
<rule ref="WordPress"> <rule ref="WordPress">
<!-- The plugin uses switch_to_blog for multisite handling. -->
<exclude name="WordPress.VIP.RestrictedFunctions.switch_to_blog"/>
<exclude name="WordPress.VIP.RestrictedFunctions.switch_to_blog_switch_to_blog"/>
<!-- Direct queries used to clean up statify table. --> <!-- Direct queries used to clean up statify table. -->
<exclude name="WordPress.VIP.DirectDatabaseQuery.DirectQuery"/> <exclude name="WordPress.DB.DirectDatabaseQuery.DirectQuery"/>
<exclude name="WordPress.VIP.DirectDatabaseQuery.NoCaching"/> <exclude name="WordPress.DB.DirectDatabaseQuery.NoCaching"/>
</rule> </rule>
<!-- PHP compatibility level --> <!-- PHP compatibility level -->

View File

@ -105,9 +105,11 @@ function statify_blacklist_disable() {
if ( is_plugin_active( STATIFYBLACKLIST_BASE ) ) { if ( is_plugin_active( STATIFYBLACKLIST_BASE ) ) {
deactivate_plugins( STATIFYBLACKLIST_BASE ); deactivate_plugins( STATIFYBLACKLIST_BASE );
add_action( 'admin_notices', 'statify_blacklist_disabled_notice' ); add_action( 'admin_notices', 'statify_blacklist_disabled_notice' );
// phpcs:disable WordPress.Security.NonceVerification.Recommended
if ( isset( $_GET['activate'] ) ) { if ( isset( $_GET['activate'] ) ) {
unset( $_GET['activate'] ); unset( $_GET['activate'] );
} }
// phpcs:enable
} }
} }

View File

@ -275,59 +275,52 @@ class StatifyBlacklist_Test extends PHPUnit\Framework\TestCase {
$this->assertTrue( invoke_static( StatifyBlacklist::class, 'cidr_match', array( '127.0.0.1', '127.0.0.1/32' ) ) ); $this->assertTrue( invoke_static( StatifyBlacklist::class, 'cidr_match', array( '127.0.0.1', '127.0.0.1/32' ) ) );
$this->assertFalse( $this->assertFalse(
invoke_static( invoke_static(
StatifyBlacklist::class, 'cidr_match', array( StatifyBlacklist::class,
'127.0.0.1', 'cidr_match',
'127.0.0.1/33', array( '127.0.0.1', '127.0.0.1/33' )
)
) )
); );
$this->assertFalse( $this->assertFalse(
invoke_static( invoke_static(
StatifyBlacklist::class, 'cidr_match', array( StatifyBlacklist::class,
'127.0.0.1', 'cidr_match',
'127.0.0.1/-1', array( '127.0.0.1', '127.0.0.1/-1' )
)
) )
); );
$this->assertTrue( $this->assertTrue(
invoke_static( invoke_static(
StatifyBlacklist::class, 'cidr_match', array( StatifyBlacklist::class,
'192.0.2.123', 'cidr_match',
'192.0.2.0/24', array( '192.0.2.123', '192.0.2.0/24' )
)
) )
); );
$this->assertFalse( $this->assertFalse(
invoke_static( invoke_static(
StatifyBlacklist::class, 'cidr_match', array( StatifyBlacklist::class,
'192.0.3.123', 'cidr_match',
'192.0.2.0/24', array( '192.0.3.123', '192.0.2.0/24' )
)
) )
); );
$this->assertTrue( $this->assertTrue(
invoke_static( invoke_static(
StatifyBlacklist::class, 'cidr_match', array( StatifyBlacklist::class,
'192.0.2.123', 'cidr_match',
'192.0.2.120/29', array( '192.0.2.123', '192.0.2.120/29' )
)
) )
); );
$this->assertFalse( $this->assertFalse(
invoke_static( invoke_static(
StatifyBlacklist::class, 'cidr_match', array( StatifyBlacklist::class,
'192.0.2.128', 'cidr_match',
'192.0.2.120/29', array( '192.0.2.128', '192.0.2.120/29' )
)
) )
); );
$this->assertTrue( invoke_static( StatifyBlacklist::class, 'cidr_match', array( '10.11.12.13', '10.0.0.0/8' ) ) ); $this->assertTrue( invoke_static( StatifyBlacklist::class, 'cidr_match', array( '10.11.12.13', '10.0.0.0/8' ) ) );
$this->assertFalse( $this->assertFalse(
invoke_static( invoke_static(
StatifyBlacklist::class, 'cidr_match', array( StatifyBlacklist::class,
'10.11.12.345', 'cidr_match',
'10.0.0.0/8', array( '10.11.12.345', '10.0.0.0/8' )
)
) )
); );
@ -338,26 +331,23 @@ class StatifyBlacklist_Test extends PHPUnit\Framework\TestCase {
$this->assertFalse( invoke_static( StatifyBlacklist::class, 'cidr_match', array( '::1', '::1/-1' ) ) ); $this->assertFalse( invoke_static( StatifyBlacklist::class, 'cidr_match', array( '::1', '::1/-1' ) ) );
$this->assertTrue( $this->assertTrue(
invoke_static( invoke_static(
StatifyBlacklist::class, 'cidr_match', array( StatifyBlacklist::class,
'2001:db8:a0b:12f0:1:2:3:4', 'cidr_match',
'2001:db8:a0b:12f0::1/64 ', array( '2001:db8:a0b:12f0:1:2:3:4', '2001:db8:a0b:12f0::1/64 ' )
)
) )
); );
$this->assertTrue( $this->assertTrue(
invoke_static( invoke_static(
StatifyBlacklist::class, 'cidr_match', array( StatifyBlacklist::class,
'2001:db8:a0b:12f0::123:456', 'cidr_match',
'2001:db8:a0b:12f0::1/96 ', array( '2001:db8:a0b:12f0::123:456', '2001:db8:a0b:12f0::1/96 ' )
)
) )
); );
$this->assertFalse( $this->assertFalse(
invoke_static( invoke_static(
StatifyBlacklist::class, 'cidr_match', array( StatifyBlacklist::class,
'2001:db8:a0b:12f0::1:132:465', 'cidr_match',
'2001:db8:a0b:12f0::1/96 ', array( '2001:db8:a0b:12f0::1:132:465', '2001:db8:a0b:12f0::1/96 ' )
)
) )
); );
} }
@ -373,6 +363,7 @@ class StatifyBlacklist_Test extends PHPUnit\Framework\TestCase {
$invalid = array( '12.34.56.789', '192.0.2.123/33', '192.0.2.123/-1' ); $invalid = array( '12.34.56.789', '192.0.2.123/33', '192.0.2.123/-1' );
$result = invoke_static( StatifyBlacklist_Admin::class, 'sanitize_ips', array( array_merge( $valid, $invalid ) ) ); $result = invoke_static( StatifyBlacklist_Admin::class, 'sanitize_ips', array( array_merge( $valid, $invalid ) ) );
$this->assertNotFalse( $result ); $this->assertNotFalse( $result );
/* /*
* Unfortunately this is nencessary as long as we run PHP 5 tests, because "assertInternalType" is deprecated * Unfortunately this is nencessary as long as we run PHP 5 tests, because "assertInternalType" is deprecated
* as of PHPUnit 8, but "assertIsArray" has been introduces in PHPUnit 7.5 which requires PHP >= 7.1. * as of PHPUnit 8, but "assertIsArray" has been introduces in PHPUnit 7.5 which requires PHP >= 7.1.
@ -576,13 +567,13 @@ class StatifyBlacklist_Test extends PHPUnit\Framework\TestCase {
'cron' => 0, 'cron' => 0,
'regexp' => StatifyBlacklist::MODE_NORMAL, 'regexp' => StatifyBlacklist::MODE_NORMAL,
'blacklist' => array( 'blacklist' => array(
'/excluded/page/' => 0 '/excluded/page/' => 0,
), ),
), ),
'ip' => array( 'ip' => array(
'active' => 1, 'active' => 1,
'blacklist' => array( 'blacklist' => array(
'192.0.2.123' '192.0.2.123',
), ),
), ),
'version' => StatifyBlacklist::VERSION_MAIN, 'version' => StatifyBlacklist::VERSION_MAIN,

View File

@ -9,6 +9,8 @@
* @since 1.0.0 * @since 1.0.0
*/ */
// phpcs:disable WordPress.WhiteSpace.PrecisionAlignment.Found
// Quit. // Quit.
defined( 'ABSPATH' ) || exit; defined( 'ABSPATH' ) || exit;
@ -132,8 +134,8 @@ if ( ! empty( $_POST['statifyblacklist'] ) ) {
} else { } else {
$statifyblacklist_post_success = __( 'Settings updated successfully.', 'statify-blacklist' ); $statifyblacklist_post_success = __( 'Settings updated successfully.', 'statify-blacklist' );
} }
} // End if(). }
} // End if(). }
/* /*
* Disable some code style rules that are impractical for textarea content: * Disable some code style rules that are impractical for textarea content: