From c42cac8f8350c008f07410f1027589611aa59384 Mon Sep 17 00:00:00 2001 From: Ryan Kanner Date: Wed, 7 Jun 2017 21:38:19 -0600 Subject: [PATCH] phpcs cleanup and some documentation fixes #32 --- includes/class-dfm-async-handler.php | 4 +- includes/class-dfm-async-nonce.php | 2 +- includes/class-dfm-transient-scheduler.php | 13 +++--- includes/class-dfm-transients.php | 50 ++++++++++++---------- 4 files changed, 38 insertions(+), 31 deletions(-) diff --git a/includes/class-dfm-async-handler.php b/includes/class-dfm-async-handler.php index 8306149..39703ce 100644 --- a/includes/class-dfm-async-handler.php +++ b/includes/class-dfm-async-handler.php @@ -41,8 +41,8 @@ class DFM_Async_Handler { function __construct( $transient, $modifier, $lock_key = '' ) { $this->transient_name = $transient; - $this->modifier = $modifier; - $this->lock_key = $lock_key; + $this->modifier = $modifier; + $this->lock_key = $lock_key; // Spawn the event on shutdown so we are less likely to run into timeouts, or block other processes add_action( 'shutdown', array( $this, 'spawn_event' ) ); diff --git a/includes/class-dfm-async-nonce.php b/includes/class-dfm-async-nonce.php index 799d893..6c2626d 100644 --- a/includes/class-dfm-async-nonce.php +++ b/includes/class-dfm-async-nonce.php @@ -34,7 +34,7 @@ class DFM_Async_Nonce { */ function __construct( $transient ) { $this->transient = $transient; - $this->action = 'dfm_' . $this->transient; + $this->action = 'dfm_' . $this->transient; } /** diff --git a/includes/class-dfm-transient-scheduler.php b/includes/class-dfm-transient-scheduler.php index f0bc6b7..7277ef2 100644 --- a/includes/class-dfm-transient-scheduler.php +++ b/includes/class-dfm-transient-scheduler.php @@ -1,6 +1,7 @@ transient = $transient; - $this->modifier = $modifier; + $this->transient = $transient; + $this->modifier = $modifier; $this->transient_object = $dfm_transients[ $this->transient ]; - $this->key = $this->cache_key(); - $this->lock_key = uniqid( 'dfm_lt_' ); - $this->prefix = apply_filters( 'dfm_transient_prefix', 'dfm_transient_' ); + $this->key = $this->cache_key(); + $this->lock_key = uniqid( 'dfm_lt_' ); + $this->prefix = apply_filters( 'dfm_transient_prefix', 'dfm_transient_' ); } @@ -122,14 +122,14 @@ public function get() { /** * This method handles storing transient data to the database or object cache * - * @param string|array $data + * @param string|array $data The data to add to the transient * @access public + * @return WP_Error|void */ public function set( $data ) { if ( ! isset( $this->transient_object ) ) { - new WP_Error( 'invalid-transient', __( 'You are trying to set data to a transient that doesn\'t exist', 'dfm-transients' ) ); - return; + return new WP_Error( 'invalid-transient', __( 'You are trying to set data to a transient that doesn\'t exist', 'dfm-transients' ) ); } if ( false === $data || is_wp_error( $data ) ) { @@ -225,14 +225,17 @@ public function is_locked() { * @access public */ public function owns_lock( $lock_key ) { + if ( empty( $this->lock ) ) { $this->lock = get_transient( 'dfm_lt_' . $this->key ); } + if ( $this->lock === $lock_key ) { return true; } else { return false; } + } /** @@ -274,16 +277,16 @@ private function get_from_transient() { /** * Handles retrieving data from post_meta or term_meta * - * @param string $type + * @param string $type The object type the meta is attached to * @return mixed string|array * @access private */ private function get_from_meta( $type ) { $data = get_metadata( $type, $this->modifier, $this->key, true ); - + $data_exists = true; - + if ( empty( $data ) ) { $data_exists = metadata_exists( $type, $this->modifier, $this->key ); } @@ -317,7 +320,7 @@ private function get_from_meta( $type ) { /** * Handles saving of data for a transient storage type * - * @param string|array $data + * @param string|array $data The data to save to the transient * @return void * @access private */ @@ -331,8 +334,8 @@ private function save_to_transient( $data ) { // Set expiration to a year if we aren't using an object cache, so the transient // isn't autoloaded from the database $expiration = ( true === wp_using_ext_object_cache() ) ? 0 : YEAR_IN_SECONDS; - $data = array( - 'data' => $data, + $data = array( + 'data' => $data, 'expiration' => time() + (int) $this->transient_object->expiration, ); } @@ -345,14 +348,17 @@ private function save_to_transient( $data ) { /** * Handles saving data for meta storage engine * - * @param string|array $data - * @param string $type + * @param string|array $data The data to save + * @param string $type The object type the meta is connected to + * + * @access private + * @return void */ private function save_to_metadata( $data, $type ) { if ( $this->should_expire() ) { $data = array( - 'data' => $data, + 'data' => $data, 'expiration' => time() + (int) $this->transient_object->expiration, ); } @@ -440,7 +446,7 @@ private function facilitate_retry() { /** * Hashes storage key * - * @param string $key + * @param string $key Name of the key to hash * @return string * @access private */ @@ -470,7 +476,7 @@ private function cache_key() { $key = $this->hash_key( $key ); } - switch( $this->transient_object->cache_type ) { + switch ( $this->transient_object->cache_type ) { case 'post_meta': case 'term_meta': case 'user_meta': @@ -520,7 +526,7 @@ private function should_soft_expire() { /** * Whether or not the transient data has expired * - * @param array|string $data + * @param array|string $data The data to check if it's expired * @return bool */ private function is_expired( $data ) {