Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions php/cache/class-cache-point.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 );
Expand Down
8 changes: 4 additions & 4 deletions php/cache/class-file-system.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class File_System {
/**
* WP file system
*
* @var \WP_Filesystem_Direct
* @var \WP_Filesystem_Direct|null
*/
public $wp_file_system;

Expand Down Expand Up @@ -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
*/
Expand Down
14 changes: 7 additions & 7 deletions php/class-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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 ) {

Expand Down
8 changes: 4 additions & 4 deletions php/class-analytics.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
}

Expand Down Expand Up @@ -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'];
}

Expand Down Expand Up @@ -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 ) {
Expand Down Expand Up @@ -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 );
}

Expand Down
2 changes: 1 addition & 1 deletion php/class-cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Cache extends Settings_Component implements Setup {
/**
* File System
*
* @var File_System
* @var File_System|null
*/
public $file_system;

Expand Down
7 changes: 3 additions & 4 deletions php/class-connect.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class Connect extends Settings_Component implements Config, Setup, Notice {
*
* @since 0.1
*
* @var array
* @var array|mixed
*/
public $usage;

Expand Down Expand Up @@ -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 ) {
Expand Down Expand Up @@ -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 ) {
Expand Down Expand Up @@ -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'] )
) {
Expand Down
8 changes: 4 additions & 4 deletions php/class-delivery.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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 ] ) ) {
Expand Down Expand Up @@ -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, '/' );
Expand Down Expand Up @@ -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
*/
Expand Down
33 changes: 12 additions & 21 deletions php/class-media.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -98,7 +89,7 @@ class Media extends Settings_Component implements Setup {
/**
* Gallery instance.
*
* @var \Cloudinary\Media\Gallery
* @var \Cloudinary\Media\Gallery|null
*/
public $gallery;

Expand All @@ -112,7 +103,7 @@ class Media extends Settings_Component implements Setup {
/**
* Sync instance.
*
* @var \Cloudinary\Sync
* @var \Cloudinary\Sync|null
*/
public $sync;

Expand Down Expand Up @@ -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'] ) ) {
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 ) {

Expand Down Expand Up @@ -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 ) {

Expand Down Expand Up @@ -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() );
Expand Down
9 changes: 4 additions & 5 deletions php/class-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -45,7 +44,7 @@ final class Plugin {
/**
* The core Settings object.
*
* @var Settings
* @var Settings|null
*/
public $settings;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
}

/**
Expand Down Expand Up @@ -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;
}

Expand Down
8 changes: 3 additions & 5 deletions php/class-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 6 additions & 6 deletions php/class-sync.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, Delete_Sync|Push_Sync|Upload_Sync|Media|Unsync|Download_Sync|Sync_Queue|null>
*/
public $managers;

Expand Down Expand Up @@ -70,7 +70,7 @@ class Sync implements Setup, Assets {
/**
* Holds the sync settings object.
*
* @var Setting
* @var Setting|null
*/
public $settings;

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 ) {

Expand Down
5 changes: 3 additions & 2 deletions php/class-utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Loading
Loading