Skip to content

Commit

Permalink
Merge pull request #88 from cmanon/feature/phpcs-improvements
Browse files Browse the repository at this point in the history
Feature/phpcs improvements
  • Loading branch information
jrfoell authored Mar 26, 2021
2 parents e251fa5 + 5c1a0bc commit 8a5a9df
Show file tree
Hide file tree
Showing 9 changed files with 159 additions and 22 deletions.
7 changes: 6 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
"require-dev": {
"wp-coding-standards/wpcs": "^2",
"phpunit/phpunit": "^8",
"10up/wp_mock": "^0.4"
"10up/wp_mock": "^0.4",
"phpcompatibility/php-compatibility": "^9.3",
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.1"
},
"scripts": {
"lint": "@php ./vendor/bin/phpcs -s"
}
}
134 changes: 130 additions & 4 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
<exclude name="WordPress.Files.FileName.InvalidClassFileName" />
</rule>

<file>./includes</file>
<rule ref="PHPCompatibility"/>
<config name="testVersion" value="5.3-7.4"/>
<arg name="extensions" value="php"/>

<file>./src</file>
<file>./wp-strava.php</file>

<exclude-pattern>*/vendor/*</exclude-pattern>

<config name="installed_paths" value="../../../vendor/wp-coding-standards/wpcs/" />
</ruleset>
4 changes: 3 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Contributors: cmanon, jrfoell, lancewillett, dlintott, sebastianerb
Tags: strava, activity, bicycle, cycling, biking, running, run, swimming, swim, paddle, kayak, gps, shortcode, widget, plugin, block, blocks
Requires at least: 4.6
Tested up to: 5.6
Tested up to: 5.7
Stable tag: 2.7.0
Requires PHP: 5.3
License: GPLv2 or later
Expand Down Expand Up @@ -121,6 +121,8 @@ On the WP-Strava settings page you cannot currently remove and add another athle

= Unreleased =
Revised `block.json` based on feedback from https://wordpress.org/plugins/developers/block-plugin-validator/
Add PHPCompatibility checks to coding standards (and fixes from recommendations)


= 2.7.0 =
Add setting to choose API cache interval (1 hour / 15 minutes) https://wordpress.org/support/topic/decrease-update-time-for-group-recent-activities/
Expand Down
2 changes: 1 addition & 1 deletion src/WPStrava/API.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function get( $uri, $args = null ) {
$data = $this->remote_get( $uri, $args );

// Default to 1 hour of transient cache unless set otherwise.
$settings = WPStrava::get_instance()->settings;
$settings = WPStrava::get_instance()->settings;
$cache_time = $settings->cache_time ? absint( $settings->cache_time ) : HOUR_IN_SECONDS;

set_transient( $transient_key, $data, $cache_time );
Expand Down
2 changes: 1 addition & 1 deletion src/WPStrava/Blocks/Activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function render_block( $attributes, $content ) {

$this->add_script = true;

$matches = [];
$matches = array();
preg_match( '/\/activities\/([0-9].*)$/', $attributes['url'], $matches );
if ( $matches[1] ) {
// Transform from block attributes to shortcode standard.
Expand Down
2 changes: 1 addition & 1 deletion src/WPStrava/Blocks/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function render_block( $attributes, $content ) {

$this->add_script = true;

$matches = [];
$matches = array();
preg_match( '/\/routes\/([0-9].*)$/', $attributes['url'], $matches );
if ( $matches[1] ) {
// Transform from block attributes to shortcode standard.
Expand Down
18 changes: 10 additions & 8 deletions src/WPStrava/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -544,8 +544,8 @@ public function print_cache_input() {
$fifteen_min = 15 * MINUTE_IN_SECONDS;
?>
<select id="strava_cache_time" name="strava_cache_time">
<option value="<?php echo esc_attr( HOUR_IN_SECONDS )?>" <?php selected( $this->cache_time, HOUR_IN_SECONDS ); ?>><?php esc_html_e( '1 Hour', 'wp-strava' ); ?></option>
<option value="<?php echo esc_attr( $fifteen_min )?>" <?php selected( $this->cache_time, $fifteen_min ); ?>><?php esc_html_e( '15 Minutes', 'wp-strava' ); ?></option>
<option value="<?php echo esc_attr( HOUR_IN_SECONDS ); ?>" <?php selected( $this->cache_time, HOUR_IN_SECONDS ); ?>><?php esc_html_e( '1 Hour', 'wp-strava' ); ?></option>
<option value="<?php echo esc_attr( $fifteen_min ); ?>" <?php selected( $this->cache_time, $fifteen_min ); ?>><?php esc_html_e( '15 Minutes', 'wp-strava' ); ?></option>
</select>
<p class="description"><?php esc_html_e( 'How often to refresh data from the Strava API', 'wp-strava' ); ?></p>
<?php
Expand Down Expand Up @@ -692,27 +692,29 @@ public function add_id( $id ) {
public function save_info( $id, $secret, $info ) {
$infos = get_option( 'strava_info' );
$infos = empty( $infos ) ? array() : $infos;
$infos = array_filter( $infos, array( $this, 'filter_by_id' ), ARRAY_FILTER_USE_KEY ); // Remove old IDs.

array_walk( $infos, array( $this, 'filter_by_id' ) );
$infos = array_filter( $infos );

$info->client_secret = $secret;
$infos[ $id ] = $info;
update_option( 'strava_info', $infos );
}

/**
* array_filter() callback to remove info for IDs we no longer have.
* array_walk() callback to clear IDs we no longer want.
*
* @param int $key Strava Client ID
* @return boolean True if Client ID is in $this->ids, false otherwise.
* @author Justin Foell <[email protected]>
* @since 2.0.0
*/
public function filter_by_id( $key ) {
public function filter_by_id( &$value, $key ) {
$ids = $this->get_ids();
if ( in_array( $key, $ids ) ) { // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict -- Loose comparison OK.
return true;
return;
}
return false;

$value = null;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/WPStrava/SOMEnglishTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ class WPStrava_SOMEnglishTest extends TestCase {

private $som;

public function setUp() : void {
public function setUp() : void { // phpcs:ignore PHPCompatibility.FunctionDeclarations.NewReturnTypeDeclarations.voidFound -- PHPUnit requires PHP7
\WP_Mock::setUp();
$this->som = new WPStrava_SOMEnglish();
}

public function tearDown() : void {
public function tearDown() : void { // phpcs:ignore PHPCompatibility.FunctionDeclarations.NewReturnTypeDeclarations.voidFound -- PHPUnit requires PHP7
\WP_Mock::tearDown();
}

Expand Down

0 comments on commit 8a5a9df

Please sign in to comment.