Skip to content

Commit

Permalink
Merge pull request #130 from Automattic/fix/cs-refresh
Browse files Browse the repository at this point in the history
Fix some Coding Standards issues
  • Loading branch information
GaryJones authored May 22, 2024
2 parents d2e4a5d + 8905378 commit 583c48d
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 33 deletions.
3 changes: 3 additions & 0 deletions .phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
<!-- Enables parallel processing when available for faster results. -->
<arg name="parallel" value="8"/>

<!-- Rules: Check PHP version compatibility - see
https://github.com/PHPCompatibility/PHPCompatibilityWP -->
<rule ref="PHPCompatibilityWP"/>
<!-- For help in understanding this testVersion:
https://github.com/PHPCompatibility/PHPCompatibility#sniffing-your-code-for-compatibility-with-specific-php-versions -->
<config name="testVersion" value="7.4-"/>
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 4 additions & 8 deletions includes/class-list-redirects.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => '<input type="checkbox" />',
'from' => __( 'Redirect From', 'wpcom-legacy-redirector' ),
Expand Down Expand Up @@ -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 ) . '<br /><em>' . esc_html__( 'Warning: Redirect is not a public URL.', 'wpcom-legacy-redirector' ) . '</em>';
} else {
if ( 'private' === \WPCOM_Legacy_Redirector::vip_legacy_redirect_check_if_public( $excerpt ) ) {
echo esc_html( $excerpt ) . '<br /><em>' . esc_html__( 'Warning: Redirect is not a public URL.', 'wpcom-legacy-redirector' ) . '</em>';
} else {
echo esc_html( $excerpt );
}
echo esc_html( $excerpt );
}
} else {
switch ( \WPCOM_Legacy_Redirector::vip_legacy_redirect_parent_id( $post ) ) {
Expand Down
1 change: 0 additions & 1 deletion includes/class-lookup.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,5 +130,4 @@ public static function get_redirect_post_id( $url ) {

return $redirect_post_id;
}

}
13 changes: 6 additions & 7 deletions includes/class-wpcom-legacy-redirector-cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -68,7 +68,7 @@ public function find_domains( $args, $assoc_args ) {

// Pause.
sleep( 1 );
$paged++;
++$paged;
} while ( count( $redirect_urls ) );

$progress->finish();
Expand All @@ -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 ) ) );

Expand Down Expand Up @@ -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 ) ) ) {
Expand Down Expand Up @@ -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 ) {
Expand Down Expand Up @@ -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 );
}

}
6 changes: 3 additions & 3 deletions includes/class-wpcom-legacy-redirector-ui.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 );
}
}
Expand Down
16 changes: 8 additions & 8 deletions includes/class-wpcom-legacy-redirector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}

/**
Expand Down
5 changes: 3 additions & 2 deletions tests/Behat/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}'." ) );
}
}

Expand All @@ -69,7 +70,7 @@ public function i_add_host_to_allowed_redirect_hosts( $host ) {
$filter_allowed_redirect_hosts = <<<PHPCODE
<?php add_filter( 'allowed_redirect_hosts', function( \$hosts ) { return array_merge( \$hosts, array( '$host' ) ); } );
PHPCODE;
// phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_file_put_contents
// phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_file_put_contents
file_put_contents(
$this->variables['RUN_DIR'] . "/wp-content/mu-plugins/allowed_redirect_hosts-{$host}.php",
$filter_allowed_redirect_hosts
Expand Down
6 changes: 2 additions & 4 deletions tests/Integration/RedirectsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Automattic\LegacyRedirector\Tests\Integration;

use \Automattic\LegacyRedirector\Lookup;
use Automattic\LegacyRedirector\Lookup;
use WPCOM_Legacy_Redirector;

/**
Expand Down Expand Up @@ -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',
Expand All @@ -145,6 +145,4 @@ function( $preserved_params ) {
$redirect = Lookup::get_redirect_uri( $protected_from );
$this->assertEquals( $redirect, $protected_to, 'get_redirect_uri failed' );
}

}

1 change: 1 addition & 0 deletions tests/Unit/PreservableParamsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
),
),
Expand Down

0 comments on commit 583c48d

Please sign in to comment.