Skip to content
20 changes: 18 additions & 2 deletions phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,24 @@
<ruleset>
<config name="testVersion" value="5.6-"/>

<rule ref="WordPress-Core">
<exclude name="Universal.Operators.StrictComparisons" />
<rule ref="WordPress">
<exclude name="Universal.Operators.StrictComparisons" />

<!-- Resolve commenting related violations -->
<exclude name="Squiz.Commenting" />
<exclude name="Generic.Commenting" />
<exclude name="Squiz.PHP.CommentedOutCode.Found" />

<!-- Fix security issues -->
<exclude name="WordPress.Security.EscapeOutput" />
<exclude name="WordPress.Security.ValidatedSanitizedInput" />
<exclude name="WordPress.Security.NonceVerification" />

<!-- Fix AlternativeFunctons-->
<exclude name="WordPress.WP.AlternativeFunctions" />
<exclude name="WordPress.WP.GlobalVariablesOverride.Prohibited" />
<exclude name="WordPress.DB.DirectDatabaseQuery.DirectQuery" />
<exclude name="WordPress.DB.DirectDatabaseQuery.NoCaching" />
</rule>
<rule ref="Generic.Files.LineLength">
<properties>
Expand Down
6 changes: 3 additions & 3 deletions src/class-tiny-apache-rewrite.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class Tiny_Apache_Rewrite extends Tiny_WP_Base {

/**
* seperator when rules are inserted
*
* @var string
*/
const MARKER = 'tiny-compress-images';
Expand All @@ -40,9 +41,8 @@ class Tiny_Apache_Rewrite extends Tiny_WP_Base {
* hooked into `update_option_tinypng_convert_format`
* https://developer.wordpress.org/reference/hooks/update_option_option/
*
*
* @param mixed $old_value
* @param mixed $value
* @param mixed $old_value
* @param mixed $value
* @param string $option
* @return void
*/
Expand Down
4 changes: 2 additions & 2 deletions src/class-tiny-bulk-optimization.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static function get_optimization_statistics( $settings, $result = null )
if ( isset( $last_image['ID'] ) ) {
$last_image_id = $last_image['ID'];
}
} while ( sizeof( $result ) == self::PAGING_SIZE );
} while ( count( $result ) == self::PAGING_SIZE );
} else {
$stats = self::populate_optimization_statistics( $settings, $result, $stats );
}
Expand Down Expand Up @@ -104,7 +104,7 @@ private static function populate_optimization_statistics( $settings, $result, $s
$active_tinify_sizes = $settings->get_active_tinify_sizes();
$conversion_enabled = $settings->get_conversion_enabled();

for ( $i = 0; $i < sizeof( $result ); $i++ ) {
for ( $i = 0; $i < count( $result ); $i++ ) {
$wp_metadata = unserialize( (string) $result[ $i ]['meta_value'] );
$tiny_metadata = isset( $result[ $i ]['tiny_meta_value'] ) ?
unserialize( (string) $result[ $i ]['tiny_meta_value'] ) :
Expand Down
1 change: 0 additions & 1 deletion src/class-tiny-cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public static function register_command( $settings ) {
* optimize all unprocessed images
* wp tiny optimize
*
*
* @param array $args
* @param array $assoc_args
* @return void
Expand Down
9 changes: 5 additions & 4 deletions src/class-tiny-compress-client.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ protected function validate() {
}

throw new Tiny_Exception(
$err->getMessage(),
esc_html( $err->getMessage() ),
get_class( $err ),
$err->status
);
Expand Down Expand Up @@ -165,7 +165,7 @@ protected function compress( $input, $resize_opts, $preserve_opts, $convert_to )
);

throw new Tiny_Exception(
$err->getMessage(),
esc_html( $err->getMessage() ),
get_class( $err ),
$err->status
);
Expand All @@ -184,15 +184,16 @@ public function create_key( $email, $options ) {
$this->last_error_code = $err->status;

throw new Tiny_Exception(
$err->getMessage(),
esc_html( $err->getMessage() ),
get_class( $err ),
$err->status
);
}
}

private function set_request_options( $client ) {
/* The client does not let us override cURL properties yet, so we have
/*
The client does not let us override cURL properties yet, so we have
to use a reflection property. */
$property = new ReflectionProperty( $client, 'options' );
$property->setAccessible( true );
Expand Down
6 changes: 3 additions & 3 deletions src/class-tiny-compress.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ public function get_status() {
/**
* Compresses a single file
*
* @param [type] $file
* @param array $resize_opts
* @param array $preserve_opts
* @param [type] $file
* @param array $resize_opts
* @param array $preserve_opts
* @param array{ string } conversion options
* @return void
*/
Expand Down
24 changes: 12 additions & 12 deletions src/class-tiny-helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Tiny_Helpers {
* We can use mb_strlen & mb_substr as WordPress provides a compat function for
* it if mbstring php module is not installed.
*
* @param string $text the text
* @param string $text the text
* @param integer $length the maximum length of the string
* @return string the truncated string
*/
Expand Down Expand Up @@ -173,17 +173,17 @@ public static function get_wp_filesystem() {
}

/**
* Polyfill for `str_starts_with()` function added in PHP 8.0.
*
* Performs a case-sensitive check indicating if
* the haystack begins with needle.
*
* @since 5.9.0
*
* @param string $haystack The string to search in.
* @param string $needle The substring to search for in the `$haystack`.
* @return bool True if `$haystack` starts with `$needle`, otherwise false.
*/
* Polyfill for `str_starts_with()` function added in PHP 8.0.
*
* Performs a case-sensitive check indicating if
* the haystack begins with needle.
*
* @since 5.9.0
*
* @param string $haystack The string to search in.
* @param string $needle The substring to search for in the `$haystack`.
* @return bool True if `$haystack` starts with `$needle`, otherwise false.
*/
public static function str_starts_with( $haystack, $needle ) {
if ( function_exists( 'str_starts_with' ) ) {
return str_starts_with( $haystack, $needle );
Expand Down
8 changes: 5 additions & 3 deletions src/class-tiny-image.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ private function parse_wp_metadata() {
}

if ( ! is_array( $this->wp_metadata ) || ! isset( $this->wp_metadata['file'] ) ) {
/* No file metadata found, this might be another plugin messing with
/*
No file metadata found, this might be another plugin messing with
metadata. Simply ignore this! */
return;
}
Expand All @@ -63,7 +64,8 @@ private function parse_wp_metadata() {
$path_prefix .= $path_info['dirname'] . '/';
}

/* Do not use pathinfo for getting the filename.
/*
Do not use pathinfo for getting the filename.
It doesn't work when the filename starts with a special character. */
$path_parts = explode( '/', $this->wp_metadata['file'] );
$this->name = end( $path_parts );
Expand Down Expand Up @@ -471,7 +473,7 @@ public function get_savings( $stats ) {

public function get_statistics( $active_sizes, $active_tinify_sizes ) {
if ( $this->statistics ) {
error_log( 'Strangely the image statistics are asked for again.' );
Tiny_Logger::error( 'Strangely the image statistics are asked for again.' );
return $this->statistics;
}

Expand Down
6 changes: 3 additions & 3 deletions src/class-tiny-logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
/**
* Handles logging of plugin events to file.
*
*
* @since 3.7.0
*/
class Tiny_Logger {
Expand Down Expand Up @@ -73,7 +72,7 @@ public static function init() {
'pre_update_option_tinypng_logging_enabled',
'Tiny_Logger::on_save_log_enabled',
10,
3
2
);
}

Expand Down Expand Up @@ -114,7 +113,7 @@ public function get_log_file_path() {
*
* @return bool true if enabled
*/
public static function on_save_log_enabled( $log_enabled, $old, $option ) {
public static function on_save_log_enabled( $log_enabled, $old ) {
$instance = self::get_instance();
$was_enabled = 'on' === $old;
$is_now_enabled = 'on' === $log_enabled;
Expand Down Expand Up @@ -190,6 +189,7 @@ private function log( $level, $message, $context = array() ) {
$context_str = ! empty( $context ) ? ' ' . wp_json_encode( $context ) : '';
$log_entry = "[{$timestamp}] [{$level_str}] {$message}{$context_str}" . PHP_EOL;

// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
error_log( $log_entry, 3, $this->log_file_path );
}

Expand Down
6 changes: 3 additions & 3 deletions src/class-tiny-php.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public static function curl_exec_disabled() {
}

public static function client_supported() {
return Tiny_PHP::has_fully_supported_php() &&
Tiny_PHP::curl_available() &&
! Tiny_PHP::curl_exec_disabled();
return self::has_fully_supported_php() &&
self::curl_available() &&
! self::curl_exec_disabled();
}
}
6 changes: 3 additions & 3 deletions src/class-tiny-picture.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ private function replace_picture_sources( $content ) {
private function replace_img_sources( $content ) {
$image_sources = $this->filter_images( $content );
foreach ( $image_sources as $image_source ) {
$content = Tiny_Picture::replace_image( $content, $image_source );
$content = self::replace_image( $content, $image_source );
}
return $content;
}
Expand Down Expand Up @@ -145,7 +145,7 @@ private function filter_pictures( $content ) {
/**
* Will add additional sourcesets to picture elements.
*
* @param string $content the full page content
* @param string $content the full page content
* @param Tiny_Source_Picture $source the picture element
*
* @return string the updated content including augmented picture elements
Expand All @@ -159,7 +159,7 @@ private function replace_picture( $content, $source ) {
/**
* Will replace img elements with picture elements that (possibly) have additional formats.
*
* @param string $content the full page content
* @param string $content the full page content
* @param Tiny_Source_Image $source the picture element
*
* @return string the updated content including augmented picture elements
Expand Down
10 changes: 7 additions & 3 deletions src/class-tiny-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ public static function jpeg_quality() {
}

public static function version() {
/* Avoid using get_plugin_data() because it is not loaded early enough
/*
Avoid using get_plugin_data() because it is not loaded early enough
in xmlrpc.php. */
return self::VERSION;
}
Expand Down Expand Up @@ -111,7 +112,8 @@ public function ajax_init() {
$this->get_method( 'mark_image_as_compressed' )
);

/* When touching any functionality linked to image compressions when
/*
When touching any functionality linked to image compressions when
uploading images make sure it also works with XML-RPC. See README. */
add_filter(
'wp_ajax_nopriv_tiny_rpc',
Expand Down Expand Up @@ -788,7 +790,8 @@ public function add_dashboard_widget() {
true
);

/* This might be deduplicated with the admin script localization, but
/*
This might be deduplicated with the admin script localization, but
the order of including scripts is sometimes different. So in that
case we need to make sure that the order of inclusion is correc.t */
wp_localize_script(
Expand Down Expand Up @@ -850,6 +853,7 @@ public function friendly_user_name() {
* Will clean up converted files (if any) when the original is deleted
*
* Hooked to the `delete_attachment` action.
*
* @see https://developer.wordpress.org/reference/hooks/deleted_post/
*
* @param [int] $post_id
Expand Down
19 changes: 11 additions & 8 deletions src/class-tiny-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,23 @@ public function xmlrpc_init() {
try {
$this->init_compressor();
} catch ( Tiny_Exception $e ) {
Tiny_Logger::error( $e->getMessage() );
}
}

public function cli_init() {
try {
$this->init_compressor();
} catch ( Tiny_Exception $e ) {
Tiny_Logger::error( $e->getMessage() );
}
}

public function ajax_init() {
try {
$this->init_compressor();
} catch ( Tiny_Exception $e ) {
Tiny_Logger::error( $e->getMessage() );
}

add_action(
Expand Down Expand Up @@ -89,6 +92,7 @@ public function rest_init() {
try {
$this->init_compressor();
} catch ( Tiny_Exception $e ) {
Tiny_Logger::error( $e->getMessage() );
}
}

Expand All @@ -98,7 +102,7 @@ public function admin_init() {
} catch ( Tiny_Exception $e ) {
$this->notices->show(
'compressor_exception',
esc_html( $e->getMessage(), 'tiny-compress-images' ),
esc_html( $e->getMessage() ),
'error',
false
);
Expand Down Expand Up @@ -221,7 +225,8 @@ protected function clear_api_key_pending() {
}

protected static function get_intermediate_size( $size ) {
/* Inspired by
/*
Inspired by
http://codex.wordpress.org/Function_Reference/get_intermediate_image_sizes */
global $_wp_additional_image_sizes;

Expand Down Expand Up @@ -378,7 +383,7 @@ public function get_resize_options( $size_name ) {
if ( $height > 0 ) {
$options['height'] = $height;
}
return sizeof( $options ) >= 2 ? $options : false;
return count( $options ) >= 2 ? $options : false;
}

/**
Expand Down Expand Up @@ -686,8 +691,8 @@ public function render_compression_timing_radiobutton(
}

$id = sprintf( self::get_prefixed_name( 'compression_timing_%s' ), $value );
$label = esc_html( $label, 'tiny-compress-images' );
$desc = esc_html( $desc, 'tiny-compress-images' );
$label = esc_html( $label );
$desc = esc_html( $desc );
echo '<input type="radio" id="' . $id . '" name="' . $name .
'" value="' . $value . '" ' . $checked . '/>';
echo '<label for="' . $id . '">' . $label . '</label>';
Expand Down Expand Up @@ -789,14 +794,12 @@ public function render_account_status() {
if ( $this->get_api_key_pending() ) {
$this->clear_api_key_pending();
}
} else {
if ( $this->get_api_key_pending() ) {
} elseif ( $this->get_api_key_pending() ) {
$status->ok = true;
$status->pending = true;
$status->message = (
'An email has been sent to activate your account'
);
}
}
include __DIR__ . '/views/account-status-connected.php';
}
Expand Down
Loading
Loading