diff --git a/RoboFile.php b/RoboFile.php index b08f75b..fc7fe1e 100644 --- a/RoboFile.php +++ b/RoboFile.php @@ -19,10 +19,10 @@ use Robo\Tasks; */ class RoboFile extends Tasks { const PROJECT_NAME = 'statify-blacklist'; - const SVN_URL = 'https://plugins.svn.wordpress.org/statify-blacklist'; + const SVN_URL = 'https://plugins.svn.wordpress.org/statify-blacklist'; - const OPT_TARGET = 'target'; - const OPT_SKIPTEST = 'skipTests'; + const OPT_TARGET = 'target'; + const OPT_SKIPTEST = 'skipTests'; const OPT_SKIPSTYLE = 'skipStyle'; /** @@ -134,10 +134,12 @@ class RoboFile extends Tasks { */ private function bundle() { $this->say( 'Bundling resources...' ); - $this->taskCopyDir( [ - 'inc' => $this->target_dir . '/' . $this->final_name . '/inc', - 'views' => $this->target_dir . '/' . $this->final_name . '/views', - ] )->run(); + $this->taskCopyDir( + [ + 'inc' => $this->target_dir . '/' . $this->final_name . '/inc', + 'views' => $this->target_dir . '/' . $this->final_name . '/views', + ] + )->run(); $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( 'README.md', $this->target_dir . '/' . $this->final_name . '/README.md' ); diff --git a/composer.json b/composer.json index 8dc9df3..a2190ec 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,7 @@ "type": "wordpress-plugin", "require": { "php": ">=5.5", - "composer/installers": "~1.0" + "composer/installers": "~1.7" }, "require-dev": { "dealerdirect/phpcodesniffer-composer-installer": "^0.5", @@ -27,8 +27,8 @@ "phpunit/phpunit": "*", "phpunit/php-code-coverage": "*", "slowprog/composer-copy-file": "~0.2", - "squizlabs/php_codesniffer": "^3.4", - "phpcompatibility/php-compatibility": "^9.2", + "squizlabs/php_codesniffer": "^3.5", + "phpcompatibility/php-compatibility": "^9.3", "wp-coding-standards/wpcs": "^2.1" }, "scripts": { diff --git a/inc/class-statifyblacklist-admin.php b/inc/class-statifyblacklist-admin.php index 9a77a26..2ab7e29 100644 --- a/inc/class-statifyblacklist-admin.php +++ b/inc/class-statifyblacklist-admin.php @@ -354,6 +354,8 @@ class StatifyBlacklist_Admin extends StatifyBlacklist { array_flip( $expressions ), function ( $re ) { // Check of preg_match() fails (warnings suppressed). + + // phpcs:disable WordPress.PHP.NoSilencedErrors.Discouraged return false === @preg_match( StatifyBlacklist::regex( $re, false ), null ); } ); diff --git a/phpcs.xml b/phpcs.xml index b317a5b..3e2fb67 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -2,7 +2,7 @@ Derived from WordPress Coding Standard - + @@ -13,13 +13,9 @@ - - - - - - + + diff --git a/statify-blacklist.php b/statify-blacklist.php index f7d5111..2e94b7c 100644 --- a/statify-blacklist.php +++ b/statify-blacklist.php @@ -105,9 +105,11 @@ function statify_blacklist_disable() { if ( is_plugin_active( STATIFYBLACKLIST_BASE ) ) { deactivate_plugins( STATIFYBLACKLIST_BASE ); add_action( 'admin_notices', 'statify_blacklist_disabled_notice' ); + // phpcs:disable WordPress.Security.NonceVerification.Recommended if ( isset( $_GET['activate'] ) ) { unset( $_GET['activate'] ); } + // phpcs:enable } } diff --git a/test/statifyblacklist-test.php b/test/statifyblacklist-test.php index cd3aad6..16c6f41 100644 --- a/test/statifyblacklist-test.php +++ b/test/statifyblacklist-test.php @@ -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->assertFalse( invoke_static( - StatifyBlacklist::class, 'cidr_match', array( - '127.0.0.1', - '127.0.0.1/33', - ) + StatifyBlacklist::class, + 'cidr_match', + array( '127.0.0.1', '127.0.0.1/33' ) ) ); $this->assertFalse( invoke_static( - StatifyBlacklist::class, 'cidr_match', array( - '127.0.0.1', - '127.0.0.1/-1', - ) + StatifyBlacklist::class, + 'cidr_match', + array( '127.0.0.1', '127.0.0.1/-1' ) ) ); $this->assertTrue( invoke_static( - StatifyBlacklist::class, 'cidr_match', array( - '192.0.2.123', - '192.0.2.0/24', - ) + StatifyBlacklist::class, + 'cidr_match', + array( '192.0.2.123', '192.0.2.0/24' ) ) ); $this->assertFalse( invoke_static( - StatifyBlacklist::class, 'cidr_match', array( - '192.0.3.123', - '192.0.2.0/24', - ) + StatifyBlacklist::class, + 'cidr_match', + array( '192.0.3.123', '192.0.2.0/24' ) ) ); $this->assertTrue( invoke_static( - StatifyBlacklist::class, 'cidr_match', array( - '192.0.2.123', - '192.0.2.120/29', - ) + StatifyBlacklist::class, + 'cidr_match', + array( '192.0.2.123', '192.0.2.120/29' ) ) ); $this->assertFalse( invoke_static( - StatifyBlacklist::class, 'cidr_match', array( - '192.0.2.128', - '192.0.2.120/29', - ) + StatifyBlacklist::class, + 'cidr_match', + 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->assertFalse( invoke_static( - StatifyBlacklist::class, 'cidr_match', array( - '10.11.12.345', - '10.0.0.0/8', - ) + StatifyBlacklist::class, + 'cidr_match', + 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->assertTrue( invoke_static( - StatifyBlacklist::class, 'cidr_match', array( - '2001:db8:a0b:12f0:1:2:3:4', - '2001:db8:a0b:12f0::1/64 ', - ) + StatifyBlacklist::class, + 'cidr_match', + array( '2001:db8:a0b:12f0:1:2:3:4', '2001:db8:a0b:12f0::1/64 ' ) ) ); $this->assertTrue( invoke_static( - StatifyBlacklist::class, 'cidr_match', array( - '2001:db8:a0b:12f0::123:456', - '2001:db8:a0b:12f0::1/96 ', - ) + StatifyBlacklist::class, + 'cidr_match', + array( '2001:db8:a0b:12f0::123:456', '2001:db8:a0b:12f0::1/96 ' ) ) ); $this->assertFalse( invoke_static( - StatifyBlacklist::class, 'cidr_match', array( - '2001:db8:a0b:12f0::1:132:465', - '2001:db8:a0b:12f0::1/96 ', - ) + StatifyBlacklist::class, + 'cidr_match', + 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' ); $result = invoke_static( StatifyBlacklist_Admin::class, 'sanitize_ips', array( array_merge( $valid, $invalid ) ) ); $this->assertNotFalse( $result ); + /* * 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. @@ -576,13 +567,13 @@ class StatifyBlacklist_Test extends PHPUnit\Framework\TestCase { 'cron' => 0, 'regexp' => StatifyBlacklist::MODE_NORMAL, 'blacklist' => array( - '/excluded/page/' => 0 + '/excluded/page/' => 0, ), ), 'ip' => array( 'active' => 1, 'blacklist' => array( - '192.0.2.123' + '192.0.2.123', ), ), 'version' => StatifyBlacklist::VERSION_MAIN, @@ -593,8 +584,8 @@ class StatifyBlacklist_Test extends PHPUnit\Framework\TestCase { // No match. $_SERVER['HTTP_REFERER'] = 'https://example.net'; - $_SERVER['REQUEST_URI'] = '/normal/page/'; - $_SERVER['REMOTE_ADDR'] = '192.0.2.234'; + $_SERVER['REQUEST_URI'] = '/normal/page/'; + $_SERVER['REMOTE_ADDR'] = '192.0.2.234'; unset( $_SERVER['HTTP_X_FORWARDED_FOR'] ); unset( $_SERVER['HTTP_X_REAL_IP'] ); @@ -604,7 +595,7 @@ class StatifyBlacklist_Test extends PHPUnit\Framework\TestCase { // Matching target. $_SERVER['HTTP_REFERER'] = 'https://example.net'; - $_SERVER['REQUEST_URI'] = '/excluded/page/'; + $_SERVER['REQUEST_URI'] = '/excluded/page/'; $this->assertTrue( StatifyBlacklist::apply_blacklist_filter() ); // Matching IP. @@ -628,7 +619,7 @@ class StatifyBlacklist_Test extends PHPUnit\Framework\TestCase { StatifyBlacklist::$options['referer']['regexp'] = StatifyBlacklist::MODE_REGEX_CI; $this->assertTrue( StatifyBlacklist::apply_blacklist_filter() ); $_SERVER['HTTP_REFERER'] = 'https://example.net'; - $_SERVER['REQUEST_URI'] = '/excluded/page/'; + $_SERVER['REQUEST_URI'] = '/excluded/page/'; $this->assertTrue( StatifyBlacklist::apply_blacklist_filter() ); $_SERVER['REQUEST_URI'] = '/normal/page/'; $_SERVER['REMOTE_ADDR'] = '192.0.2.123'; diff --git a/views/settings-page.php b/views/settings-page.php index dd1a75a..e4c6404 100755 --- a/views/settings-page.php +++ b/views/settings-page.php @@ -9,6 +9,8 @@ * @since 1.0.0 */ +// phpcs:disable WordPress.WhiteSpace.PrecisionAlignment.Found + // Quit. defined( 'ABSPATH' ) || exit; @@ -132,8 +134,8 @@ if ( ! empty( $_POST['statifyblacklist'] ) ) { } else { $statifyblacklist_post_success = __( 'Settings updated successfully.', 'statify-blacklist' ); } - } // End if(). -} // End if(). + } +} /* * Disable some code style rules that are impractical for textarea content: