Skip to content

Commit 302a540

Browse files
committed
Bump PHPStan to level 3 and fix type/annotation issues
Raise the PHPStan analysis level from 2 to 3 and resolve the resulting issues, all safe PHPDoc/annotation corrections with no behavior change: - Correct return-type PHPDoc to match actual behavior: Assets:: generate_storage_signature (bool), Assets::build_item (array|null), Media::get_transformation (int|string|false), Media::cloudinary_url (string|null), Media::filter_downsize (array|false), Media:: get_context_options (string), Settings::save (string[]), Api::sign (string), Api::call (array|string|WP_Error), Page::form/notice and Sync::action (array|null), On_Off::sanitize_value (string). - Widen base Text::sanitize_value PHPDoc to mixed so the array/bool overrides (Checkbox, Cron, Crops, React, Tags_Input, On_Off) are covariant-compatible. - Fix settings/setting type confusion: correct Component\Settings interface param to Cloudinary\Settings, widen Settings_Component:: $settings and Delivery_Feature::$settings to Settings|Setting, align Gallery/Extensions/Global_Transformations settings property types. - Fix Setting::$parent (string slug, not self) and get_option_parent return (Setting|null). - Fix Sync::$managers to include Sync_Queue. - Fix Line_Stat $connect type (Cloudinary\Connect) and narrow at call site; allow numeric used_percent/limit. - Cast ini_get in Cron::$daemon_watcher_interval; default Api:: $pending_url to null; widen Url_Object::get_id to int|string|null. - Correct get_terms return-type PHPDoc and annotate video metadata to resolve offset access on WP stub arrays.
1 parent 1a2fbe9 commit 302a540

21 files changed

Lines changed: 52 additions & 36 deletions

php/class-assets.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ public function generate_file_signature( $asset_id ) {
713713
*
714714
* @param int $asset_id The attachment/asset ID.
715715
*
716-
* @return string
716+
* @return bool
717717
*/
718718
public function generate_storage_signature( $asset_id ) {
719719
return $this->get_asset_storage_folder( $asset_id ) === $this->media->get_public_id( $asset_id );
@@ -1199,7 +1199,7 @@ public function get_asset( $post_id, $type = 'object' ) {
11991199
*
12001200
* @param array $item The raw data for an asset.
12011201
*
1202-
* @return array
1202+
* @return array|null
12031203
*/
12041204
public function build_item( $item ) {
12051205
if ( empty( $item ) ) {

php/class-cron.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function __construct() {
8181

8282
// Ensure it's safe.
8383
if ( self::$daemon_watcher_interval > ini_get( 'max_execution_time' ) ) {
84-
self::$daemon_watcher_interval = ini_get( 'max_execution_time' );
84+
self::$daemon_watcher_interval = (int) ini_get( 'max_execution_time' );
8585
}
8686

8787
$this->init_time = time();

php/class-delivery-feature.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
namespace Cloudinary;
99

1010
use Cloudinary\Component\Assets;
11-
use Cloudinary\Settings\Setting;
1211

1312
/**
1413
* Class Delivery_Feature
@@ -57,7 +56,7 @@ abstract class Delivery_Feature implements Assets {
5756
/**
5857
* Holds the settings.
5958
*
60-
* @var Setting
59+
* @var Settings|\Cloudinary\Settings\Setting
6160
*/
6261
protected $settings;
6362

php/class-extensions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class Extensions extends Settings_Component implements Setup {
2424
/**
2525
* Holds the core plugin settings.
2626
*
27-
* @var Settings
27+
* @var Settings|\Cloudinary\Settings\Setting
2828
*/
2929
protected $settings;
3030

php/class-media.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -941,7 +941,7 @@ public function set_transformation( &$transformations, $type, $value, $index = f
941941
* @param array $transformations The transformation set to check.
942942
* @param string $type The type of transformation to check for.
943943
*
944-
* @return bool
944+
* @return int|string|false
945945
*/
946946
public function get_transformation( $transformations, $type ) {
947947
foreach ( $transformations as $index => $transformation ) {
@@ -1372,7 +1372,7 @@ protected function get_cache_key( $args ) {
13721372
* @param string|null $cloudinary_id Optional forced cloudinary ID.
13731373
* @param bool $overwrite_transformations Flag url is a breakpoint URL to stop re-applying default transformations.
13741374
*
1375-
* @return string The converted URL.
1375+
* @return string|null The converted URL.
13761376
*/
13771377
public function cloudinary_url( $attachment_id, $size = array(), $transformations = array(), $cloudinary_id = null, $overwrite_transformations = false ) {
13781378
static $cache = array();
@@ -1777,11 +1777,11 @@ public function cloudinary_id( $attachment_id ) {
17771777
/**
17781778
* Filter the requested image and return image source.
17791779
*
1780-
* @param null $image The null image value for short circuit check.
1780+
* @param array|false $image The image value for short circuit check.
17811781
* @param int $attachment_id The ID of the attachment.
17821782
* @param string|array $size The requested size of the image.
17831783
*
1784-
* @return array The image array of size and url.
1784+
* @return array|false The image array of size and url.
17851785
* @uses filter:image_downsize
17861786
*/
17871787
public function filter_downsize( $image, $attachment_id, $size ) {
@@ -2781,7 +2781,7 @@ public function get_breakpoint_options( $attachment_id ) {
27812781
*
27822782
* @param int $attachment_id The ID of the attachment.
27832783
*
2784-
* @return array
2784+
* @return string
27852785
*/
27862786
public function get_context_options( $attachment_id ) {
27872787
$caption = get_post( $attachment_id )->post_excerpt;

php/class-settings-component.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
use Cloudinary\Component;
1111
use Cloudinary\Settings as CoreSetting;
12+
use Cloudinary\Settings\Setting;
1213

1314
/**
1415
* Plugin Settings Component class.
@@ -18,7 +19,7 @@ abstract class Settings_Component implements Component\Settings {
1819
/**
1920
* Holds the settings object for this Class.
2021
*
21-
* @var CoreSetting
22+
* @var CoreSetting|Setting
2223
*/
2324
protected $settings;
2425

php/class-settings.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ public function remove_pending( $slug ) {
590590
/**
591591
* Save settings.
592592
*
593-
* @return bool[]|\WP_Error[]
593+
* @return string[]
594594
*/
595595
public function save() {
596596
$pending = array_keys( $this->get_pending() );

php/class-sync.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class Sync implements Setup, Assets {
3535
/**
3636
* Contains all the different sync components.
3737
*
38-
* @var Delete_Sync[]|Push_Sync[]|Upload_Sync[]|Media[]|Unsync[]|Download_Sync[]
38+
* @var Delete_Sync[]|Push_Sync[]|Upload_Sync[]|Media[]|Unsync[]|Download_Sync[]|Sync_Queue[]
3939
*/
4040
public $managers;
4141

php/component/class-settings.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
namespace Cloudinary\Component;
99

10-
use Cloudinary\Settings\Setting;
10+
use Cloudinary\Settings as CoreSettings;
1111

1212
/**
1313
* Defines an object that requires settings.
@@ -17,7 +17,7 @@ interface Settings {
1717
/**
1818
* Init Settings Object.
1919
*
20-
* @param Setting $setting The core setting.
20+
* @param CoreSettings $setting The core setting.
2121
*/
2222
public function init_settings( $setting );
2323
}

php/connect/class-api.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ class Api {
156156
*
157157
* @var string|null
158158
*/
159-
private $pending_url = array();
159+
private $pending_url = null;
160160

161161
/**
162162
* API constructor.
@@ -801,7 +801,7 @@ public function __call( $name, $args ) {
801801
*
802802
* @param array $args Array of parameters to sign.
803803
*
804-
* @return array|\WP_Error
804+
* @return string
805805
*/
806806
public function sign( $args ) {
807807

@@ -988,7 +988,7 @@ protected static function get_hostname( $upload_prefix ) {
988988
* @param array $args The optional arguments to send.
989989
* @param string $method The call HTTP method.
990990
*
991-
* @return array|\WP_Error
991+
* @return array|string|\WP_Error
992992
*/
993993
private function call( $url, $args = array(), $method = 'get' ) {
994994
$args['method'] = strtoupper( $method );

0 commit comments

Comments
 (0)