diff --git a/.phpcs.xml.dist b/.phpcs.xml.dist
index 0946d68..d1ffe94 100644
--- a/.phpcs.xml.dist
+++ b/.phpcs.xml.dist
@@ -25,6 +25,9 @@
+
+
diff --git a/composer.json b/composer.json
index fd94908..a7536f1 100644
--- a/composer.json
+++ b/composer.json
@@ -19,6 +19,7 @@
"composer/installers": "^1 || ^2"
},
"require-dev": {
+ "phpcompatibility/phpcompatibility-wp": "^2",
"wp-cli/entity-command": "^2",
"wp-cli/extension-command": "^2",
"wp-cli/wp-cli-tests": "^4",
diff --git a/includes/class-list-redirects.php b/includes/class-list-redirects.php
index fcf9e19..d69f79d 100644
--- a/includes/class-list-redirects.php
+++ b/includes/class-list-redirects.php
@@ -23,10 +23,8 @@ public function init() {
/**
* Set Columns for Redirect Table.
- *
- * @param array $columns Columns to show for the post type.
*/
- public function set_columns( $columns ) {
+ public function set_columns() {
return array(
'cb' => '',
'from' => __( 'Redirect From', 'wpcom-legacy-redirector' ),
@@ -59,12 +57,10 @@ public function posts_custom_column( $column, $post_id ) {
echo esc_html( $excerpt );
} elseif ( 0 === strpos( $excerpt, 'http' ) ) {
echo esc_url_raw( $excerpt );
+ } elseif ( 'private' === \WPCOM_Legacy_Redirector::vip_legacy_redirect_check_if_public( $excerpt ) ) {
+ echo esc_html( $excerpt ) . '
' . esc_html__( 'Warning: Redirect is not a public URL.', 'wpcom-legacy-redirector' ) . '';
} else {
- if ( 'private' === \WPCOM_Legacy_Redirector::vip_legacy_redirect_check_if_public( $excerpt ) ) {
- echo esc_html( $excerpt ) . '
' . esc_html__( 'Warning: Redirect is not a public URL.', 'wpcom-legacy-redirector' ) . '';
- } else {
- echo esc_html( $excerpt );
- }
+ echo esc_html( $excerpt );
}
} else {
switch ( \WPCOM_Legacy_Redirector::vip_legacy_redirect_parent_id( $post ) ) {
diff --git a/includes/class-lookup.php b/includes/class-lookup.php
index f59f647..9844fcc 100644
--- a/includes/class-lookup.php
+++ b/includes/class-lookup.php
@@ -130,5 +130,4 @@ public static function get_redirect_post_id( $url ) {
return $redirect_post_id;
}
-
}
diff --git a/includes/class-wpcom-legacy-redirector-cli.php b/includes/class-wpcom-legacy-redirector-cli.php
index a42a086..828cb56 100644
--- a/includes/class-wpcom-legacy-redirector-cli.php
+++ b/includes/class-wpcom-legacy-redirector-cli.php
@@ -5,7 +5,7 @@
* @package Automattic\LegacyRedirector
*/
-use \Automattic\LegacyRedirector\Post_Type;
+use Automattic\LegacyRedirector\Post_Type;
/**
* Manage redirects added via the WPCOM Legacy Redirector plugin.
@@ -68,7 +68,7 @@ public function find_domains( $args, $assoc_args ) {
// Pause.
sleep( 1 );
- $paged++;
+ ++$paged;
} while ( count( $redirect_urls ) );
$progress->finish();
@@ -77,7 +77,7 @@ public function find_domains( $args, $assoc_args ) {
$domains_count = count( $domains );
/* translators: %s = count of the domains */
- $translatable_text = _n( 'Found %s unique outbound domain.', 'Found %s unique outbound domains.', $domains_count );
+ $translatable_text = _n( 'Found %s unique outbound domain.', 'Found %s unique outbound domains.', $domains_count, 'wpcom-legacy-redirector' );
WP_CLI::line( sprintf( $translatable_text, number_format( $domains_count ) ) );
@@ -221,7 +221,7 @@ public function import_from_meta( $args, $assoc_args ) {
$total = count( $redirects );
foreach ( $redirects as $redirect ) {
- $i++;
+ ++$i;
$progress->tick();
if ( true === $skip_dupes && 0 !== WPCOM_Legacy_Redirector::get_redirect_post_id( wp_parse_url( $redirect->meta_value, PHP_URL_PATH ) ) ) {
@@ -351,7 +351,7 @@ public function import_from_csv( $args, $assoc_args ) {
$handle = fopen( $csv, 'r' );
if ( false !== $handle ) {
while ( ( $data = fgetcsv( $handle, 2000, ',' ) ) !== false ) {
- $row++;
+ ++$row;
$redirect_from = $data[0];
$redirect_to = $data[1];
if ( $verbose ) {
@@ -467,12 +467,11 @@ public function export_to_csv( $args, $assoc_args ) {
vip_inmemory_cleanup();
}
- $paged++;
+ ++$paged;
} while ( count( $posts ) );
$progress->finish();
WP_CLI\Utils\write_csv( $file_descriptor, $output );
fclose( $file_descriptor );
}
-
}
diff --git a/includes/class-wpcom-legacy-redirector-ui.php b/includes/class-wpcom-legacy-redirector-ui.php
index 31745f1..d1054c4 100644
--- a/includes/class-wpcom-legacy-redirector-ui.php
+++ b/includes/class-wpcom-legacy-redirector-ui.php
@@ -5,8 +5,8 @@
* @package Automattic\LegacyRedirector
*/
-use \Automattic\LegacyRedirector\Capability;
-use \Automattic\LegacyRedirector\Post_Type;
+use Automattic\LegacyRedirector\Capability;
+use Automattic\LegacyRedirector\Post_Type;
/**
* User interface additions.
@@ -128,7 +128,7 @@ public function validate_vip_legacy_redirect() {
$this->vip_legacy_redirect_sendback( 'null', $post->ID );
}
// Check if $redirect is valid.
- if ( wp_validate_redirect( $redirect, false ) && 404 !== $status || 'valid' === $redirect ) {
+ if ( ( wp_validate_redirect( $redirect, false ) && 404 !== $status ) || 'valid' === $redirect ) {
$this->vip_legacy_redirect_sendback( 'valid', $post->ID );
}
}
diff --git a/includes/class-wpcom-legacy-redirector.php b/includes/class-wpcom-legacy-redirector.php
index 166371e..cf2c306 100644
--- a/includes/class-wpcom-legacy-redirector.php
+++ b/includes/class-wpcom-legacy-redirector.php
@@ -5,10 +5,10 @@
* @package Automattic\LegacyRedirector
*/
-use \Automattic\LegacyRedirector\Capability;
-use \Automattic\LegacyRedirector\List_Redirects;
-use \Automattic\LegacyRedirector\Lookup;
-use \Automattic\LegacyRedirector\Post_Type;
+use Automattic\LegacyRedirector\Capability;
+use Automattic\LegacyRedirector\List_Redirects;
+use Automattic\LegacyRedirector\Lookup;
+use Automattic\LegacyRedirector\Post_Type;
/**
* Plugin core functionality for creating, validating, and performing redirect rules.
@@ -267,13 +267,13 @@ public static function normalise_url( $url ) {
}
/**
- * Utility function to lowercase string.
+ * Utility function to lowercase a string.
*
- * @param string $string To apply lowercase.
+ * @param string $a_string To apply lowercase.
* @return string Lowercase representation of string.
*/
- public static function lowercase( $string ) {
- return ! empty( $string ) ? strtolower( $string ) : $string;
+ public static function lowercase( $a_string ) {
+ return ! empty( $a_string ) ? strtolower( $a_string ) : $a_string;
}
/**
diff --git a/tests/Behat/FeatureContext.php b/tests/Behat/FeatureContext.php
index 1a2231b..68224c3 100644
--- a/tests/Behat/FeatureContext.php
+++ b/tests/Behat/FeatureContext.php
@@ -53,8 +53,9 @@ private function ensure_dir_exists( $directory ) {
$this->ensure_dir_exists( $parent );
}
+ // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_mkdir
if ( ! is_dir( $directory ) && ! mkdir( $directory ) && ! is_dir( $directory ) ) {
- throw new \RuntimeException( "Could not create directory '{$directory}'." );
+ throw new \RuntimeException( esc_html( "Could not create directory '{$directory}'." ) );
}
}
@@ -69,7 +70,7 @@ public function i_add_host_to_allowed_redirect_hosts( $host ) {
$filter_allowed_redirect_hosts = <<variables['RUN_DIR'] . "/wp-content/mu-plugins/allowed_redirect_hosts-{$host}.php",
$filter_allowed_redirect_hosts
diff --git a/tests/Integration/RedirectsTest.php b/tests/Integration/RedirectsTest.php
index c8fb489..93bb26f 100644
--- a/tests/Integration/RedirectsTest.php
+++ b/tests/Integration/RedirectsTest.php
@@ -7,7 +7,7 @@
namespace Automattic\LegacyRedirector\Tests\Integration;
-use \Automattic\LegacyRedirector\Lookup;
+use Automattic\LegacyRedirector\Lookup;
use WPCOM_Legacy_Redirector;
/**
@@ -128,7 +128,7 @@ public function get_protected_redirect_data() {
public function test_protected_query_redirect( $from, $to, $protected_from, $protected_to ) {
add_filter(
'wpcom_legacy_redirector_preserve_query_params',
- function( $preserved_params ) {
+ function ( $preserved_params ) {
array_push(
$preserved_params,
'utm_source',
@@ -145,6 +145,4 @@ function( $preserved_params ) {
$redirect = Lookup::get_redirect_uri( $protected_from );
$this->assertEquals( $redirect, $protected_to, 'get_redirect_uri failed' );
}
-
}
-
diff --git a/tests/Unit/PreservableParamsTest.php b/tests/Unit/PreservableParamsTest.php
index e3cd648..f466be9 100644
--- a/tests/Unit/PreservableParamsTest.php
+++ b/tests/Unit/PreservableParamsTest.php
@@ -67,6 +67,7 @@ public function data_get_preservable_querystring_params_from_url() {
array(
'foo' => '123',
'bar' => 'qwerty',
+ // phpcs:ignore Universal.Arrays.DuplicateArrayKey.Found -- intentional duplicate.
'foo' => '456',
),
),