Skip to content

Commit

Permalink
fix errors reported by PHPStan
Browse files Browse the repository at this point in the history
  • Loading branch information
remyperona committed Nov 27, 2024
1 parent 148229e commit c7fdb25
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 43 deletions.
9 changes: 4 additions & 5 deletions classes/Bulk/Bulk.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ private function decrease_counter( string $context ) {
* @param int $optimization_level Optimization level.
*/
public function optimize_media( int $media_id, string $context, int $optimization_level ) {
if ( ! $media_id || ! $context || ! is_numeric( $optimization_level ) ) {
if ( ! $media_id || ! $context ) {
$this->decrease_counter( $context );

return;
Expand Down Expand Up @@ -565,7 +565,7 @@ public function bulk_get_stats_callback() {
imagify_check_nonce( 'imagify-bulk-optimize' );

$folder_types = filter_input( INPUT_GET, 'types', FILTER_REQUIRE_ARRAY );
$folder_types = is_array( $folder_types ) ? array_filter( $folder_types, 'is_string' ) : [];
$folder_types = is_array( $folder_types ) ? $folder_types : [];

if ( ! $folder_types ) {
imagify_die( __( 'Invalid request', 'imagify' ) );
Expand Down Expand Up @@ -644,7 +644,7 @@ public function get_contexts() {
$types = apply_filters( 'imagify_bulk_page_types', $types );
$types = array_filter( (array) $types );

if ( isset( $types['library|wp'] ) && ! in_array( 'wp', $contexts, true ) ) {
if ( isset( $types['library|wp'] ) ) {
$contexts[] = 'wp';
}

Expand All @@ -656,12 +656,11 @@ public function get_contexts() {
if ( ! in_array( 'wp', $contexts, true ) ) {
$contexts[] = 'wp';
}
} elseif ( $folders_instance->has_active_folders() && ! in_array( 'custom-folders', $contexts, true ) ) {
} elseif ( $folders_instance->has_active_folders() ) {
$contexts[] = 'custom-folders';
}
}

return $contexts;
}

}
9 changes: 5 additions & 4 deletions classes/Context/AbstractContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ abstract class AbstractContext implements ContextInterface {
* @since 1.9
* @author Grégory Viguier
*/
protected $context;
protected $context = '';

/**
* Tell if the media/context is network-wide.
Expand Down Expand Up @@ -55,7 +55,7 @@ abstract class AbstractContext implements ContextInterface {
* @since 1.9
* @author Grégory Viguier
*/
protected $thumbnail_sizes;
protected $thumbnail_sizes = [];

/**
* Tell if the optimization process is allowed to backup in this context.
Expand All @@ -64,7 +64,7 @@ abstract class AbstractContext implements ContextInterface {
* @since 1.9
* @author Grégory Viguier
*/
protected $can_backup;
protected $can_backup = false;

/**
* Get the context "short name".
Expand Down Expand Up @@ -161,7 +161,7 @@ public function can_backup() {
* @return bool
*/
public function current_user_can( $describer, $media_id = null ) {
return $this->user_can( null, $describer, $media_id );
return $this->user_can( 0 , $describer, $media_id );
}

/**
Expand All @@ -176,6 +176,7 @@ public function current_user_can( $describer, $media_id = null ) {
* @return bool
*/
public function user_can( $user_id, $describer, $media_id = null ) {
$user = 0;
$current_user_id = get_current_user_id();

if ( ! $user_id ) {
Expand Down
4 changes: 0 additions & 4 deletions classes/Context/CustomFolders.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,6 @@ public function get_resizing_threshold() {
* @return bool
*/
public function can_backup() {
if ( isset( $this->can_backup ) ) {
return $this->can_backup;
}

$this->can_backup = get_imagify_option( 'backup' );

return $this->can_backup;
Expand Down
18 changes: 2 additions & 16 deletions classes/Context/WP.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ final class WP extends AbstractContext {
* @since 1.9.8
* @author Grégory Viguier
*/
protected $resizing_threshold;
protected $resizing_threshold = 0;

/**
* Get the thumbnail sizes for this context, except the full size.
Expand All @@ -47,10 +47,6 @@ final class WP extends AbstractContext {
* }
*/
public function get_thumbnail_sizes() {
if ( isset( $this->thumbnail_sizes ) ) {
return $this->thumbnail_sizes;
}

$this->thumbnail_sizes = get_imagify_thumbnail_sizes();

return $this->thumbnail_sizes;
Expand All @@ -66,13 +62,7 @@ public function get_thumbnail_sizes() {
* @return int
*/
public function get_resizing_threshold() {
if ( isset( $this->resizing_threshold ) ) {
return $this->resizing_threshold;
}

if ( ! get_imagify_option( 'resize_larger' ) ) {
$this->resizing_threshold = 0;
} else {
if ( get_imagify_option( 'resize_larger' ) ) {
$this->resizing_threshold = max( 0, get_imagify_option( 'resize_larger_w' ) );
}

Expand All @@ -88,10 +78,6 @@ public function get_resizing_threshold() {
* @return bool
*/
public function can_backup() {
if ( isset( $this->can_backup ) ) {
return $this->can_backup;
}

$this->can_backup = get_imagify_option( 'backup' );

return $this->can_backup;
Expand Down
2 changes: 1 addition & 1 deletion classes/Imagifybeat/Actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ private function get_modified_optimization_statuses( $data ) {
// Sanitize the IDs: IDs come as strings, prefixed with an undescore character (to prevent JavaScript from screwing everything).
$media_ids = array_keys( $media_statuses );
$media_ids = array_map( function( $media_id ) {
return (int) substr( $media_id, 1 );
return substr( $media_id, 1 );
}, $media_ids );
$media_ids = array_filter( $media_ids );

Expand Down
6 changes: 1 addition & 5 deletions classes/Media/WP.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class WP extends AbstractMedia {
* @access protected
* @author Grégory Viguier
*/
protected $is_wp53;
protected $is_wp53 = false;

/**
* The constructor.
Expand Down Expand Up @@ -419,10 +419,6 @@ protected function update_media_data_dimensions( $dimensions ) {
* @return bool
*/
protected function is_wp_53() {
if ( isset( $this->is_wp53 ) ) {
return $this->is_wp53;
}

$this->is_wp53 = function_exists( 'wp_get_original_image_path' );

return $this->is_wp53;
Expand Down
4 changes: 2 additions & 2 deletions classes/Traits/InstanceGetterTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ trait InstanceGetterTrait {
/**
* The "not-so-single" instance of the class.
*
* @var object
* @var ?object
* @since 1.9
* @access protected
* @author Grégory Viguier
*/
protected static $instance;
protected static $instance = null;

/**
* Get the main Instance.
Expand Down
4 changes: 1 addition & 3 deletions classes/User/User.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php
namespace Imagify\User;

use Date;
use Imagify_Data;
use WP_Error;

Expand Down Expand Up @@ -115,7 +114,7 @@ class User {
* @var bool|WP_Error
* @since 1.9.9
*/
private $error;
private $error = false;

/**
* The constructor.
Expand Down Expand Up @@ -143,7 +142,6 @@ public function __construct() {
$this->next_date_update = $user->next_date_update;
$this->is_active = $user->is_active;
$this->is_monthly = $user->is_monthly;
$this->error = is_wp_error( $user );
}

/**
Expand Down
7 changes: 4 additions & 3 deletions inc/functions/admin-ui.php
Original file line number Diff line number Diff line change
Expand Up @@ -450,9 +450,10 @@ function get_imagify_attachment_delete_nextgen_versions_link( $process ) {
* @since 1.9 Function signature changed.
* @author Jonathan Buttigieg
*
* @param ProcessInterface $process The optimization process object.
* @param bool $with_container Set to false to not return the HTML container.
* @return string The output to print.
* @param \Imagify\Optimization\Process\ProcessInterface $process The optimization process object.
* @param bool $with_container Set to false to not return the HTML container.
*
* @return string The output to print.
*/
function get_imagify_media_column_content( $process, $with_container = true ) {
if ( ! $process->is_valid() ) {
Expand Down

0 comments on commit c7fdb25

Please sign in to comment.