diff --git a/php/cache/class-cache-point.php b/php/cache/class-cache-point.php index af4dd0239..b7ac92e96 100644 --- a/php/cache/class-cache-point.php +++ b/php/cache/class-cache-point.php @@ -406,7 +406,7 @@ function ( $post ) { * * @param string $url The URL to convert. * - * @return string + * @return string|null */ public function url_to_path( $url ) { $url = $this->clean_url( $url ); @@ -451,7 +451,7 @@ protected function load_cache_point( $url ) { * * @param string $url The cache point url to get. * - * @return \WP_Post + * @return \WP_Post|null */ public function get_cache_point( $url ) { // Lets check if the cache_point is a file. @@ -647,7 +647,7 @@ public function create_cache_point( $url, $src_path, $version ) { */ protected function check_version( $url, $version ) { $cache_point = $this->get_cache_point( $url ); - if ( ! is_numeric( $cache_point ) ) { + if ( $cache_point instanceof \WP_Post ) { $prev_version = get_post_meta( $cache_point->ID, self::META_KEYS['version'], true ); if ( $prev_version !== $version ) { update_post_meta( $cache_point->ID, self::META_KEYS['version'], $version ); diff --git a/php/cache/class-file-system.php b/php/cache/class-file-system.php index 44e06d17b..5e13a05f3 100644 --- a/php/cache/class-file-system.php +++ b/php/cache/class-file-system.php @@ -27,7 +27,7 @@ class File_System { /** * WP file system * - * @var \WP_Filesystem_Direct + * @var \WP_Filesystem_Direct|null */ public $wp_file_system; @@ -210,9 +210,9 @@ public function get_src_path( $file_url ) { /** * Get the URL's for a list of src files. * - * @param string $path The path to get urls for. - * @param array $files The list of files. - * @param null $version The version. + * @param string $path The path to get urls for. + * @param array $files The list of files. + * @param string|null $version The version. * * @return array|false|mixed */ diff --git a/php/class-admin.php b/php/class-admin.php index e9fef78fb..2b602787e 100644 --- a/php/class-admin.php +++ b/php/class-admin.php @@ -367,7 +367,7 @@ public function init_components( $template, $slug ) { /** * Filter out non-setting params. * - * @param numeric-string $key The key to filter out. + * @param int|string $key The key to filter out. * * @return bool */ @@ -465,12 +465,12 @@ protected function save_settings( $submission, $data ) { /** * Set an error/notice for a setting. * - * @param string $error_code The error code/slug. - * @param string $error_message The error text/message. - * @param string $type The error type. - * @param bool $dismissible If notice is dismissible. - * @param int $duration How long it's dismissible for. - * @param string $icon Optional icon. + * @param string $error_code The error code/slug. + * @param string|array $error_message The error text/message. + * @param string $type The error type. + * @param bool $dismissible If notice is dismissible. + * @param int $duration How long it's dismissible for. + * @param string $icon Optional icon. */ public function add_admin_notice( $error_code, $error_message, $type = 'error', $dismissible = true, $duration = 0, $icon = null ) { diff --git a/php/class-analytics.php b/php/class-analytics.php index bd3f07220..61df3b29c 100644 --- a/php/class-analytics.php +++ b/php/class-analytics.php @@ -160,7 +160,7 @@ public function maybe_send_pending_activation() { if ( ! empty( $pending['previous_version'] ) ) { $params['previous_version'] = $pending['previous_version']; } - if ( isset( $pending['days_since_last_active'] ) && null !== $pending['days_since_last_active'] ) { + if ( isset( $pending['days_since_last_active'] ) ) { $params['days_since_last_active'] = $pending['days_since_last_active']; } @@ -193,7 +193,7 @@ public function maybe_first_api_consumption( $attachment_id, $result ) { update_option( self::FIRST_API_FLAG, $cloud, false ); $asset_type = ''; - if ( is_array( $result ) && ! empty( $result['resource_type'] ) ) { + if ( ! empty( $result['resource_type'] ) ) { $asset_type = $result['resource_type']; } @@ -260,7 +260,7 @@ public function track( $event_name, $category, $funnel_step = null, $params = ar 'event_category' => $category, 'event_timestamp' => gmdate( 'Y-m-d\TH:i:s\Z' ), ), - is_array( $params ) ? $params : array() + $params ); if ( null !== $funnel_step ) { @@ -365,7 +365,7 @@ protected function get_session_id() { */ protected function get_user_role() { $user = wp_get_current_user(); - if ( $user && ! empty( $user->roles ) ) { + if ( ! empty( $user->roles ) ) { return (string) reset( $user->roles ); } diff --git a/php/class-cache.php b/php/class-cache.php index 98bddd37e..4ec472372 100644 --- a/php/class-cache.php +++ b/php/class-cache.php @@ -37,7 +37,7 @@ class Cache extends Settings_Component implements Setup { /** * File System * - * @var File_System + * @var File_System|null */ public $file_system; diff --git a/php/class-connect.php b/php/class-connect.php index 403eb7d1f..3d7345e2e 100644 --- a/php/class-connect.php +++ b/php/class-connect.php @@ -46,7 +46,7 @@ class Connect extends Settings_Component implements Config, Setup, Notice { * * @since 0.1 * - * @var array + * @var array|mixed */ public $usage; @@ -156,7 +156,7 @@ public function rest_test_connection( WP_REST_Request $request ) { /** * The analytics component. * - * @var \Cloudinary\Analytics $analytics + * @var \Cloudinary\Analytics|null $analytics */ $analytics = $this->plugin->get_component( 'analytics' ); if ( $analytics ) { @@ -248,7 +248,7 @@ public function rest_save_wizard( WP_REST_Request $request ) { /** * The analytics component. * - * @var \Cloudinary\Analytics $analytics + * @var \Cloudinary\Analytics|null $analytics */ $analytics = $this->plugin->get_component( 'analytics' ); if ( $analytics ) { @@ -774,7 +774,6 @@ public function usage_stats( $refresh = false ) { $stats = $this->api->usage(); if ( ! is_wp_error( $stats ) - && is_array( $stats ) && isset( $stats['media_limits'] ) && is_array( $stats['media_limits'] ) ) { diff --git a/php/class-delivery.php b/php/class-delivery.php index 2745ae87b..416ad8b13 100644 --- a/php/class-delivery.php +++ b/php/class-delivery.php @@ -232,7 +232,7 @@ public function maybe_filter_out_metadata( $check, $object_id, $meta_key, $meta_ /** * Filter out Cloudinary URLS and replace with local. * - * @param string $content The content to filter. + * @param mixed $content The content to filter. * * @return string */ @@ -541,7 +541,7 @@ public function unsync_size_relationship( $attachment_id ) { */ public function get_sized( $attachment_id ) { static $sizes = array(), $registered_sizes; - if ( ! $registered_sizes && is_callable( 'wp_get_registered_image_subsizes' ) ) { + if ( ! $registered_sizes ) { $registered_sizes = wp_get_registered_image_subsizes(); } if ( empty( $sizes[ $attachment_id ] ) ) { @@ -1125,7 +1125,7 @@ function ( $tag ) use ( $content ) { if ( empty( $cloudinary_url ) ) { continue; } - if ( ! empty( $relation['slashed'] ) && $relation['slashed'] ) { + if ( ! empty( $relation['slashed'] ) ) { $aliases[ $base . '?_i=AA' ] = addcslashes( $cloudinary_url, '/' ); $aliases[ $base . '?' ] = addcslashes( $cloudinary_url . '&', '/' ); $aliases[ $base ] = addcslashes( $cloudinary_url, '/' ); @@ -1939,7 +1939,7 @@ protected function set_usability( $item, $auto_sync = null ) { /** * Sanitize a url. * - * @param string $url URL to sanitize. + * @param mixed $url URL to sanitize. * * @return string|null */ diff --git a/php/class-media.php b/php/class-media.php index 3d4ff61d4..e17af96fc 100644 --- a/php/class-media.php +++ b/php/class-media.php @@ -51,15 +51,6 @@ class Media extends Settings_Component implements Setup { */ private $cloudinary_folder; - /** - * Holds the found Cloudinary ID's - * - * @since 0.1 - * - * @var array - */ - private $cloudinary_ids = array(); - /** * Cloudinary credentials. * @@ -98,7 +89,7 @@ class Media extends Settings_Component implements Setup { /** * Gallery instance. * - * @var \Cloudinary\Media\Gallery + * @var \Cloudinary\Media\Gallery|null */ public $gallery; @@ -112,7 +103,7 @@ class Media extends Settings_Component implements Setup { /** * Sync instance. * - * @var \Cloudinary\Sync + * @var \Cloudinary\Sync|null */ public $sync; @@ -1572,7 +1563,7 @@ public function prepare_size( $attachment_id, $size ) { 'full' => true, ); } - } elseif ( is_string( $size ) || ( is_array( $size ) && 3 === count( $size ) ) ) { + } elseif ( is_string( $size ) || 3 === count( $size ) ) { $intermediate = image_get_intermediate_size( $attachment_id, $size ); // PDF's do not have intermediate URL. if ( is_array( $intermediate ) && ! empty( $intermediate['url'] ) ) { @@ -1646,7 +1637,7 @@ public function get_cloudinary_folder( $add_trailing_slash = true ) { * @param int $attachment_id The Attachment ID. * @param bool $suffixed Flag to get suffixed version of ID. * - * @return string + * @return string|null */ public function get_public_id( $attachment_id, $suffixed = false ) { // Check for a public_id. @@ -1880,13 +1871,13 @@ public function convert_url( $url, $attachment_id, $transformations = array(), $ /** * Get the responsive breakpoints for the image. * - * @param array $sources The original sources array. - * @param array $size_array The size array. - * @param string $image_src The original image source. - * @param array $image_meta The image meta array. - * @param int $attachment_id The attachment id. + * @param array|false $sources The original sources array. + * @param array $size_array The size array. + * @param string $image_src The original image source. + * @param array $image_meta The image meta array. + * @param int $attachment_id The attachment id. * - * @return array Altered or same sources array. + * @return array|false Altered or same sources array. */ public function image_srcset( $sources, $size_array, $image_src, $image_meta, $attachment_id ) { @@ -2107,7 +2098,7 @@ public function editor_assets() { * @param array $asset The asset array data. * @param string $public_id The cloudinary public id. * - * @return int|WP_Error + * @return int */ private function create_attachment( $asset, $public_id ) { @@ -3262,7 +3253,7 @@ public function is_enabled( $enabled ) { */ public function upgrade_settings( $previous_version, $new_version ) { - if ( 2.4 === $previous_version ) { + if ( version_compare( $previous_version, '2.5', '<' ) ) { // Setup new data from old. $images = get_option( 'cloudinary_global_transformations', array() ); $video = get_option( self::GLOBAL_VIDEO_TRANSFORMATIONS, array() ); diff --git a/php/class-plugin.php b/php/class-plugin.php index 6603bf055..c104b5ac7 100644 --- a/php/class-plugin.php +++ b/php/class-plugin.php @@ -20,7 +20,6 @@ use Cloudinary\Sync\Storage; use Cloudinary\UI\State; use const E_USER_WARNING; -use const WPCOM_IS_VIP_ENV; /** * Main plugin bootstrap file. @@ -45,7 +44,7 @@ final class Plugin { /** * The core Settings object. * - * @var Settings + * @var Settings|null */ public $settings; @@ -147,7 +146,7 @@ public function plugins_loaded() { * * @param mixed $component The component. * - * @return Admin|CLD_Assets|Connect|Dashboard|Deactivation|Delivery|Extensions|Gallery|Lazy_Load|Media|Meta_Box|Relate|Report|Responsive_Breakpoints|REST_API|State|Storage|SVG|Sync|URL|null + * @return Admin|CLD_Assets|Connect|Cron|Dashboard|Deactivation|Delivery|Extensions|Gallery|Lazy_Load|Media|Meta_Box|Relate|Report|Responsive_Breakpoints|REST_API|State|Storage|SVG|Sync|URL|null */ public function get_component( $component ) { $return = null; @@ -699,7 +698,7 @@ public function relative_path( $path, $start, $sep ) { * @return bool */ public function is_wpcom_vip_prod() { - return ( defined( '\WPCOM_IS_VIP_ENV' ) && WPCOM_IS_VIP_ENV ); + return ( defined( '\WPCOM_IS_VIP_ENV' ) && constant( '\WPCOM_IS_VIP_ENV' ) ); // @phpstan-ignore booleanAnd.rightAlwaysFalse } /** @@ -734,7 +733,7 @@ public function add_script_data( $slug, $value, $handle = null ) { * Output script data if set. */ public function print_script_data() { - if ( ! isset( $this->settings ) || ! method_exists( $this->settings, 'get_param' ) ) { + if ( ! isset( $this->settings ) ) { return; } diff --git a/php/class-settings.php b/php/class-settings.php index 817d7e337..21ad2bb10 100644 --- a/php/class-settings.php +++ b/php/class-settings.php @@ -503,11 +503,9 @@ public function set_value( $slug, $value ) { $set = true; } } else { - $found = $this->find_setting( $slug ); - if ( $found ) { - $storage_path = $found->get_param( self::META_KEYS['storage'], $found->get_slug() ); - $set = $this->set_value( $storage_path, $value ); - } + $found = $this->find_setting( $slug ); + $storage_path = $found->get_param( self::META_KEYS['storage'], $found->get_slug() ); + $set = $this->set_value( $storage_path, $value ); } return $set; diff --git a/php/class-sync.php b/php/class-sync.php index 5ee820415..f6397fa5f 100644 --- a/php/class-sync.php +++ b/php/class-sync.php @@ -35,7 +35,7 @@ class Sync implements Setup, Assets { /** * Contains all the different sync components. * - * @var Delete_Sync[]|Push_Sync[]|Upload_Sync[]|Media[]|Unsync[]|Download_Sync[]|Sync_Queue[] + * @var array */ public $managers; @@ -70,7 +70,7 @@ class Sync implements Setup, Assets { /** * Holds the sync settings object. * - * @var Setting + * @var Setting|null */ public $settings; @@ -281,7 +281,7 @@ public function is_required( $type, $attachment_id ) { * @param int $attachment_id The Attachment id to generate a signature for. * @param bool $cache Flag to specify if a cached signature is to be used or build a new one. * - * @return string|bool + * @return mixed */ public function generate_signature( $attachment_id, $cache = true ) { static $signatures = array(); // cache signatures. @@ -1030,9 +1030,9 @@ public function sync_signature_by_type( $attachment_id, $type ) { /** * Set an item to the signature set. * - * @param int $attachment_id The attachment ID. - * @param string $type The sync type. - * @param null $value The value. + * @param int $attachment_id The attachment ID. + * @param string $type The sync type. + * @param string|null $value The value. */ public function set_signature_item( $attachment_id, $type, $value = null ) { diff --git a/php/class-utils.php b/php/class-utils.php index 1e552d080..14d6ea70f 100644 --- a/php/class-utils.php +++ b/php/class-utils.php @@ -755,11 +755,12 @@ public static function svg_encoded( $width = '600px', $height = '400px', $color * @return WP_Post|null */ public static function get_post_parent( $post = null ) { - if ( is_callable( 'get_post_parent' ) ) { + // get_post_parent() was added in WP 6.0; keep a fallback for older supported versions. + if ( is_callable( 'get_post_parent' ) ) { // @phpstan-ignore function.alreadyNarrowedType return get_post_parent( $post ); } - $wp_post = get_post( $post ); + $wp_post = get_post( $post ); // @phpstan-ignore deadCode.unreachable return ! empty( $wp_post->post_parent ) ? get_post( $wp_post->post_parent ) : null; } diff --git a/php/connect/class-api.php b/php/connect/class-api.php index 01a0aba09..fa387c2fa 100644 --- a/php/connect/class-api.php +++ b/php/connect/class-api.php @@ -55,7 +55,7 @@ class Api { /** * Holds the media instance. * - * @var Media + * @var Media|null */ protected $media; @@ -269,7 +269,7 @@ function ( $item ) use ( $transformation_index ) { // Prepare the eager transformations for the upload. if ( 'upload' === $context ) { foreach ( $transformations as &$transformation ) { - if ( 0 <= strpos( $transformation, 'f_auto' ) ) { + if ( false !== strpos( $transformation, 'f_auto' ) ) { $parts = explode( ',', $transformation ); unset( $parts[ array_search( 'f_auto', $parts, true ) ] ); $remaining_transformations = implode( ',', $parts ); @@ -362,7 +362,7 @@ public function cloudinary_url( $public_id = null, $args = array(), $size = arra $base = Utils::pathinfo( $public_id ); // Add size. - if ( ! empty( $size ) && is_array( $size ) ) { + if ( ! empty( $size ) ) { if ( ! empty( $size['transformation'] ) ) { $url_parts[] = $size['transformation']; } @@ -649,7 +649,7 @@ public function upload( $attachment_id, $args, $headers = array(), $try_remote = * * @param array $args The upload parameters. * - * @return array $the url to the cached item. + * @return array|string|\WP_Error $the url to the cached item. */ public function upload_cache( $args ) { $call_args = array( diff --git a/php/integrations/class-elementor.php b/php/integrations/class-elementor.php index 5e366c732..c2f91751e 100644 --- a/php/integrations/class-elementor.php +++ b/php/integrations/class-elementor.php @@ -63,7 +63,8 @@ public function register_hooks() { * @return void */ public function replace_background_images_in_css( $post_css, $element ) { - if ( ! method_exists( $element, 'get_settings_for_display' ) ) { + // Elementor is optional; guard against API differences across versions. + if ( ! method_exists( $element, 'get_settings_for_display' ) ) { // @phpstan-ignore function.alreadyNarrowedType return; } @@ -184,7 +185,8 @@ public function clear_elementor_css_cache() { * @return string|null */ private function find_unique_selector( $post_css, $element ) { - if ( ! method_exists( $element, 'get_unique_selector' ) ) { + // Elementor is optional; guard against API differences across versions. + if ( ! method_exists( $element, 'get_unique_selector' ) ) { // @phpstan-ignore function.alreadyNarrowedType return null; } @@ -203,7 +205,8 @@ private function find_unique_selector( $post_css, $element ) { * @return bool True if the rule could be overridden, false if the internal Elementor methods aren't available. */ private function override_elementor_css_rule( $post_css, $css_selector, $css_rule, $media_query ) { - if ( ! method_exists( $post_css, 'get_stylesheet' ) ) { + // Elementor is optional; guard against API differences across versions. + if ( ! method_exists( $post_css, 'get_stylesheet' ) ) { // @phpstan-ignore function.alreadyNarrowedType return false; } diff --git a/php/media/class-filter.php b/php/media/class-filter.php index 0867c9ccd..af99911ec 100644 --- a/php/media/class-filter.php +++ b/php/media/class-filter.php @@ -229,7 +229,7 @@ public function filter_video_shortcodes( $content ) { // Get the format. list( $format ) = array_intersect( $exts, array_keys( $args ) ); - if ( null !== $format ) { + if ( ! empty( $format ) ) { $url = $args[ $format ]; if ( empty( $args['id'] ) ) { $attachment_id = $this->media->get_id_from_url( $url ); @@ -509,7 +509,7 @@ public function transform_to_editor( $html, $id, $attachment ) { // Ensure there is a Cloudinary URL. $url = $this->get_url_from_tag( $html ); $new_url = $this->media->cloudinary_url( $id, $attachment['image-size'], $attachment['transformations'] ); - if ( false !== $new_url ) { + if ( ! empty( $new_url ) ) { $html = str_replace( $url, $new_url, $html ); } } diff --git a/php/media/class-gallery.php b/php/media/class-gallery.php index d8f82e1cc..ba9df9d22 100644 --- a/php/media/class-gallery.php +++ b/php/media/class-gallery.php @@ -559,7 +559,7 @@ function_exists( 'has_block' ) && has_block( 'cloudinary/gallery' ) if ( ! is_null( $screen ) && ( - 'cloudinary_page_cloudinary_gallery' === $screen->id || ( method_exists( $screen, 'is_block_editor' ) && $screen->is_block_editor() ) + 'cloudinary_page_cloudinary_gallery' === $screen->id || $screen->is_block_editor() ) ) { $can = true; diff --git a/php/media/class-upgrade.php b/php/media/class-upgrade.php index b0d0e0ccd..a45ff9b95 100644 --- a/php/media/class-upgrade.php +++ b/php/media/class-upgrade.php @@ -205,7 +205,7 @@ public function migrate_legacy_meta( $attachment_id ) { * The raw attachment metadata, which may contain plugin-specific keys * beyond WordPress core's documented shape. * - * @var array $old_meta + * @var array|false $old_meta */ $old_meta = wp_get_attachment_metadata( $attachment_id, true ); if ( ! is_array( $old_meta ) ) { diff --git a/php/media/class-video.php b/php/media/class-video.php index 18d51dc8a..478582eab 100644 --- a/php/media/class-video.php +++ b/php/media/class-video.php @@ -35,13 +35,6 @@ class Video { */ private $config; - /** - * List of attachment ID's to enable. - * - * @var array - */ - private $attachments = array(); - /** * Meta key to store usable video transformations for an attachment. * @@ -70,31 +63,6 @@ public function player_enabled() { return isset( $this->config['video_player'] ) && 'cld' === $this->config['video_player'] && ! is_admin(); } - /** - * Queue video tag for script init in footer. - * - * @param int $attachment_id Attachment ID. - * @param string $url The video URL. - * @param string|array $format The video formats. - * @param array $args Args to be passed to video init. - * - * @return int - */ - private function queue_video_config( $attachment_id, $url, $format, $args = array() ) { - - if ( ! empty( $args['transformation'] ) && false === $this->validate_usable_transformations( $attachment_id, $args['transformation'] ) ) { - unset( $args['transformation'] ); - } - $this->attachments[] = array( - 'id' => $attachment_id, - 'url' => $url, - 'format' => $format, - 'args' => $args, - ); - - return count( $this->attachments ) - 1;// Return the queue index. - } - /** * Checks if the transformation is able to be applied to the video and removes it if not. * diff --git a/php/relate/class-relationship.php b/php/relate/class-relationship.php index 96bc5a7d9..bedeef302 100644 --- a/php/relate/class-relationship.php +++ b/php/relate/class-relationship.php @@ -83,7 +83,7 @@ public function get_data() { global $wpdb; $table_name = Utils::get_relationship_table(); // method_exists guard handles the case where Utils was autoloaded from the old plugin version during a plugin update request. - $default_contexts = method_exists( Utils::class, 'get_media_context_things' ) ? Utils::get_media_context_things() : array( 'default' ); + $default_contexts = method_exists( Utils::class, 'get_media_context_things' ) ? Utils::get_media_context_things() : array( 'default' ); // @phpstan-ignore function.alreadyNarrowedType // If the context is in the default contexts, we want to query for all of them. // This ensures that a media uploaded with a previous default context will still be found, even if the default context has changed since it was uploaded. diff --git a/php/settings/class-setting.php b/php/settings/class-setting.php index f729f9154..eb88dab50 100644 --- a/php/settings/class-setting.php +++ b/php/settings/class-setting.php @@ -30,7 +30,7 @@ class Setting { /** * Holds the settings component. * - * @var Component + * @var Component|null */ protected $component; /** diff --git a/php/settings/storage/class-storage.php b/php/settings/storage/class-storage.php index fa74bfd61..49648738e 100644 --- a/php/settings/storage/class-storage.php +++ b/php/settings/storage/class-storage.php @@ -41,7 +41,7 @@ public function __construct( $prefix ) { * Get the data. * * @param string $slug The slug of the setting storage to get. - * @param false $reload Flag to force a reload. + * @param bool $reload Flag to force a reload. * * @return mixed */ diff --git a/php/sync/class-download-sync.php b/php/sync/class-download-sync.php index f0cc21272..b949f8be8 100644 --- a/php/sync/class-download-sync.php +++ b/php/sync/class-download-sync.php @@ -142,6 +142,11 @@ public function download_asset( $attachment_id, $source = null, $date = null ) { $source = wp_get_attachment_url( $attachment_id ); } + /** + * Raw attachment metadata; may include keys beyond core's documented shape. + * + * @var array|false $meta + */ $meta = wp_get_attachment_metadata( $attachment_id ); if ( ! empty( $meta['file'] ) ) { $file_name = isset( $meta['original_image'] ) ? wp_basename( $meta['original_image'] ) : wp_basename( $meta['file'] ); diff --git a/php/sync/class-push-sync.php b/php/sync/class-push-sync.php index 52be58e61..a35f430a4 100644 --- a/php/sync/class-push-sync.php +++ b/php/sync/class-push-sync.php @@ -206,7 +206,7 @@ public function process_assets( $attachments = array() ) { /** * The analytics component. * - * @var \Cloudinary\Analytics $analytics + * @var \Cloudinary\Analytics|null $analytics */ $analytics = $this->plugin->get_component( 'analytics' ); if ( $analytics ) { diff --git a/php/sync/class-storage.php b/php/sync/class-storage.php index 55b5a3f1a..0d97ba4f9 100644 --- a/php/sync/class-storage.php +++ b/php/sync/class-storage.php @@ -33,7 +33,7 @@ class Storage implements Notice { * * @since 2.2.0 * - * @var \Cloudinary\Media Instance of the media object. + * @var \Cloudinary\Media|null Instance of the media object. */ protected $media; @@ -42,7 +42,7 @@ class Storage implements Notice { * * @since 2.2.0 * - * @var \Cloudinary\Sync Instance of the plugin. + * @var \Cloudinary\Sync|null Instance of the plugin. */ protected $sync; @@ -51,7 +51,7 @@ class Storage implements Notice { * * @since 2.2.0 * - * @var \Cloudinary\Sync\Download_Sync Instance of the plugin. + * @var \Cloudinary\Sync\Download_Sync|null Instance of the plugin. */ protected $download; @@ -60,7 +60,7 @@ class Storage implements Notice { * * @since 2.2.0 * - * @var \Cloudinary\Connect Instance of the plugin. + * @var \Cloudinary\Connect|null Instance of the plugin. */ protected $connect; diff --git a/php/sync/class-upload-sync.php b/php/sync/class-upload-sync.php index a8f18fd05..dd2d9100f 100644 --- a/php/sync/class-upload-sync.php +++ b/php/sync/class-upload-sync.php @@ -29,7 +29,7 @@ class Upload_Sync { /** * The Push_Sync object. * - * @var \Cloudinary\Sync\Push_Sync + * @var \Cloudinary\Sync\Push_Sync|null */ private $pusher; @@ -54,24 +54,15 @@ class Upload_Sync { */ protected $media; - /** - * This feature is enabled. - * - * @var bool - */ - private $enabled; - /** * Upload_Sync constructor. * - * @param \Cloudinary\Plugin $plugin The plugin. - * @param bool $enabled Is this feature enabled. - * @param object $pusher An object that implements `push_attachments`. Default: null. + * @param \Cloudinary\Plugin $plugin The plugin. + * @param object $pusher An object that implements `push_attachments`. Default: null. */ - public function __construct( \Cloudinary\Plugin $plugin, $enabled = false, $pusher = null ) { - $this->plugin = $plugin; - $this->pusher = $pusher; - $this->enabled = $enabled; + public function __construct( \Cloudinary\Plugin $plugin, $pusher = null ) { + $this->plugin = $plugin; + $this->pusher = $pusher; } /** @@ -123,12 +114,6 @@ public function add_inline_action( $actions, $post ) { ), 'upload.php' ); - if ( ! $this->media->is_uploadable_media( $post->ID ) ) { - return $actions; - } - if ( ! $this->sync->is_syncable( $post->ID ) ) { - return $actions; - } if ( ! $this->plugin->components['sync']->is_synced( $post->ID ) ) { $actions['cloudinary-push'] = sprintf( '%s', diff --git a/php/traits/trait-params.php b/php/traits/trait-params.php index da7f7e4b2..9f2785316 100644 --- a/php/traits/trait-params.php +++ b/php/traits/trait-params.php @@ -41,7 +41,7 @@ trait Params_Trait { * Sets the params recursively. * * @param array $parts The parts to set. - * @param array $param The param being set. + * @param mixed $param The param being set. * @param mixed $value The value to set. * * @return mixed @@ -246,7 +246,7 @@ public function get_params() { /** * Check if a param is public. * - * @param string $key The param key. + * @param int|string $key The param key. * * @return bool */ diff --git a/php/traits/trait-relation.php b/php/traits/trait-relation.php index bc1ed00d0..948364f11 100644 --- a/php/traits/trait-relation.php +++ b/php/traits/trait-relation.php @@ -22,7 +22,7 @@ trait Relation_Trait { * * @method array query_relations( array $public_ids, array $urls = array() ) * - * @var callable + * @var callable|null */ protected $query_relations; diff --git a/php/traits/trait-singleton.php b/php/traits/trait-singleton.php index f3fc0a3cf..be8d28c62 100644 --- a/php/traits/trait-singleton.php +++ b/php/traits/trait-singleton.php @@ -19,7 +19,7 @@ trait Singleton_Trait { /** * Holds the singleton instance. * - * @var self + * @var self|null */ protected static $instance; diff --git a/php/ui/class-component.php b/php/ui/class-component.php index 28514b39c..bea5e9dac 100644 --- a/php/ui/class-component.php +++ b/php/ui/class-component.php @@ -420,7 +420,7 @@ protected function prepare_struct_array( &$struct, &$parts, $name ) { /** * Check if the structure is an array of structures. * - * @param array $struct The structure to check. + * @param mixed $struct The structure to check. * * @return bool */ @@ -554,7 +554,7 @@ protected function close_tag( $struct ) { /** * Adds the content to the html. * - * @param string $content The content to add. + * @param mixed $content The content to add. */ protected function add_content( $content ) { diff --git a/php/ui/component/class-asset.php b/php/ui/component/class-asset.php index 0b00b548b..677ea3354 100644 --- a/php/ui/component/class-asset.php +++ b/php/ui/component/class-asset.php @@ -273,6 +273,6 @@ protected function pre_render() { wp_add_inline_script( 'cloudinary', 'var CLDASSETS = ' . wp_json_encode( $export ), 'before' ); $plugin->add_script_data( 'editor', $export ); - parent::pre_render(); + parent::pre_render(); // @phpstan-ignore staticMethod.resultUnused } } diff --git a/php/ui/component/class-color.php b/php/ui/component/class-color.php index c49d52407..b5e51d0f8 100644 --- a/php/ui/component/class-color.php +++ b/php/ui/component/class-color.php @@ -20,7 +20,7 @@ class Color extends Text { * Enqueue scripts. */ public function enqueue_scripts() { - parent::enqueue_scripts(); + parent::enqueue_scripts(); // @phpstan-ignore staticMethod.resultUnused $instance = get_plugin_instance(); wp_enqueue_style( 'wp-color-picker' ); wp_enqueue_script( 'wp-color-picker-alpha', $instance->dir_url . 'js/wp-color-picker-alpha.js', array( 'wp-color-picker' ), $instance->version, true ); diff --git a/php/ui/component/class-file-folder.php b/php/ui/component/class-file-folder.php index d3e6cae7f..b0e1663fe 100644 --- a/php/ui/component/class-file-folder.php +++ b/php/ui/component/class-file-folder.php @@ -147,7 +147,7 @@ protected function set_main( $main, $slug ) { /** * Decode the serialised value. * - * @param string $value The string to decode. + * @param mixed $value The string to decode. * * @return array|bool|string */ diff --git a/php/ui/component/class-folder-table.php b/php/ui/component/class-folder-table.php index 4952cc5e2..2f0ffebd4 100644 --- a/php/ui/component/class-folder-table.php +++ b/php/ui/component/class-folder-table.php @@ -360,6 +360,6 @@ protected function get_filter_slug( $filter ) { */ protected function pre_render() { wp_add_inline_script( 'cloudinary', 'var CLDCACHE = ' . wp_json_encode( $this->export ), 'before' ); - parent::pre_render(); + parent::pre_render(); // @phpstan-ignore staticMethod.resultUnused } } diff --git a/php/ui/component/class-image-preview.php b/php/ui/component/class-image-preview.php index 8f47164e4..aaba4b6b3 100644 --- a/php/ui/component/class-image-preview.php +++ b/php/ui/component/class-image-preview.php @@ -216,6 +216,6 @@ protected function pre_render() { ); wp_add_inline_script( 'cloudinary', 'var CLD_GLOBAL_TRANSFORMATIONS = CLD_GLOBAL_TRANSFORMATIONS ? CLD_GLOBAL_TRANSFORMATIONS : {};', 'before' ); wp_add_inline_script( 'cloudinary', 'CLD_GLOBAL_TRANSFORMATIONS.image = ' . wp_json_encode( $script_data ), 'before' ); - parent::pre_render(); + parent::pre_render(); // @phpstan-ignore staticMethod.resultUnused } } diff --git a/php/ui/component/class-opt-level.php b/php/ui/component/class-opt-level.php index c2383f94c..5ff1eb178 100644 --- a/php/ui/component/class-opt-level.php +++ b/php/ui/component/class-opt-level.php @@ -199,7 +199,7 @@ public function calculate_percentage() { foreach ( $this->settings_slugs as $slug ) { $setting = $this->plugin_settings->get_setting( $slug ); $meet_depends = true; - if ( null !== $setting && ! is_wp_error( $setting ) ) { + if ( null !== $setting ) { $params = $setting->get_params(); if ( ! empty( $params['depends'] ) ) { foreach ( $params['depends'] as $depend ) { diff --git a/php/ui/component/class-react.php b/php/ui/component/class-react.php index e44541373..65a48ad3b 100644 --- a/php/ui/component/class-react.php +++ b/php/ui/component/class-react.php @@ -89,7 +89,7 @@ protected function scripts( $struct ) { /** * Sanitize the value. * - * @param string $value The value to sanitize. + * @param mixed $value The value to sanitize. * * @return array|bool|null */ diff --git a/php/url/class-wordpress.php b/php/url/class-wordpress.php index 2ea20de00..13e1681f2 100644 --- a/php/url/class-wordpress.php +++ b/php/url/class-wordpress.php @@ -15,7 +15,7 @@ class WordPress extends Url_Object { /** * Holds the Cloudinary URL object. * - * @var Cloudinary + * @var Cloudinary|null */ protected $cloudinary_url; diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 65109885a..b83f7deab 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -14,7 +14,7 @@ parameters: - identifier: return.void message: '#^Action callback returns .+ but should not return anything\.$#' - level: 3 + level: 4 paths: - php - cloudinary.php