diff --git a/php/class-admin.php b/php/class-admin.php index 422218e4..be9642dd 100644 --- a/php/class-admin.php +++ b/php/class-admin.php @@ -433,7 +433,6 @@ public function init_setting_save() { */ protected function save_settings( $submission, $data ) { $page = $this->settings->get_setting( $submission ); - $errors = array(); $pending = false; foreach ( $data as $key => $value ) { $slug = $submission . $page->separator . $key; @@ -451,7 +450,7 @@ protected function save_settings( $submission, $data ) { $pending = true; } - if ( empty( $errors ) && true === $pending ) { + if ( true === $pending ) { $results = $this->settings->save(); if ( ! empty( $results ) ) { $this->add_admin_notice( 'error_notice', __( 'Settings updated successfully', 'cloudinary' ), 'success' ); diff --git a/php/class-connect.php b/php/class-connect.php index bc7e75a4..1779cb67 100644 --- a/php/class-connect.php +++ b/php/class-connect.php @@ -606,7 +606,7 @@ public function test_ping() { protected function extract_cname( $parsed_url ) { $cname = null; - if ( ! empty( $test['query'] ) ) { + if ( ! empty( $parsed_url['query'] ) ) { $config_params = array(); wp_parse_str( $parsed_url['query'], $config_params ); $cname = isset( $config_params['cname'] ) ? $config_params['cname'] : $cname; @@ -921,6 +921,7 @@ public function get_notices() { */ public function upgrade_connection( $old_version ) { + $data = array(); if ( version_compare( $old_version, '2.0.0', '>' ) ) { // Post V1 - quick check all details are valid. $data = $this->settings->get_value( 'connect' ); @@ -951,6 +952,9 @@ public function upgrade_connection( $old_version ) { } // Test upgraded details. + if ( empty( $data['cloudinary_url'] ) ) { + return; // Nothing to upgrade. + } $data['cloudinary_url'] = str_replace( 'CLOUDINARY_URL=', '', $data['cloudinary_url'] ); $test = $this->test_connection( $data['cloudinary_url'] ); diff --git a/php/class-delivery.php b/php/class-delivery.php index e334c6b8..e8e55273 100644 --- a/php/class-delivery.php +++ b/php/class-delivery.php @@ -1747,7 +1747,7 @@ protected function is_content_dir( $url ) { $dirname = trim( substr( $path, strlen( $base ), 8 ), DIRECTORY_SEPARATOR ); if ( empty( $dirname ) || preg_match( '/\d{4}\/\d{2}/', $dirname ) ) { $is_local = true; - } elseif ( ! empty( $dirname ) ) { + } else { $is_local = false; } } diff --git a/php/class-rest-api.php b/php/class-rest-api.php index d130b657..7ce24a3b 100644 --- a/php/class-rest-api.php +++ b/php/class-rest-api.php @@ -26,6 +26,13 @@ class REST_API { */ public $endpoints; + /** + * Holds the plugin instance. + * + * @var Plugin + */ + protected $plugin; + /** * The nonce key used for WordPress REST API authentication. * @@ -38,7 +45,8 @@ class REST_API { * * @param Plugin $plugin Instance of the global Plugin. */ - public function __construct( Plugin $plugin ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found + public function __construct( Plugin $plugin ) { + $this->plugin = $plugin; add_action( 'rest_api_init', array( $this, 'rest_api_init' ), PHP_INT_MAX ); } diff --git a/php/connect/class-api.php b/php/connect/class-api.php index dc593927..33ec732c 100644 --- a/php/connect/class-api.php +++ b/php/connect/class-api.php @@ -439,6 +439,7 @@ public function upload_large( $attachment_id, $args ) { $chunk_size = 20000000; $index = 0; $file_size = filesize( $args['file'] ); + $result = new \WP_Error( 'upload_error', __( 'No data to upload.', 'cloudinary' ) ); while ( ! feof( $src ) ) { $current_loc = $index * $chunk_size; if ( $current_loc >= $file_size ) { diff --git a/php/media/class-upgrade.php b/php/media/class-upgrade.php index 2db0b101..be45fe56 100644 --- a/php/media/class-upgrade.php +++ b/php/media/class-upgrade.php @@ -248,7 +248,7 @@ public function migrate_legacy_meta( $attachment_id ) { update_post_meta( $attachment_id, '_wp_attachment_metadata', $old_meta ); // migrate from pre v2 meta. - if ( empty( $v2_meta ) && empty( $v3_meta ) ) { + if ( empty( $v2_meta ) ) { // Attempt old post meta. $public_id = get_post_meta( $attachment_id, Sync::META_KEYS['public_id'], true ); if ( ! empty( $public_id ) ) { diff --git a/php/media/class-video.php b/php/media/class-video.php index 57ab0c2e..6c214b9f 100644 --- a/php/media/class-video.php +++ b/php/media/class-video.php @@ -221,7 +221,7 @@ public function admin_enqueue_scripts() { */ public function filter_video_block_render_block( $block_content, array $block ) { if ( 'core/video' === $block['blockName'] ) { - remove_filter( 'render_block', array( $this, 'filter_video_block_render_block' ), 10, 2 ); + remove_filter( 'render_block', array( $this, 'filter_video_block_render_block' ), 10 ); $filtered_block = $this->filter_video_block_pre_render( $block, $block ); $block_content = render_block( $filtered_block ); diff --git a/php/relate/class-relationship.php b/php/relate/class-relationship.php index 09db1f41..dee31bd4 100644 --- a/php/relate/class-relationship.php +++ b/php/relate/class-relationship.php @@ -22,6 +22,7 @@ * @property string|null $text_overlay * @property string|null $image_overlay * @property string|null $sized_url + * @property string|null $url_hash * @property string|null $media_context */ class Relationship { diff --git a/php/templates/connection-string.php b/php/templates/connection-string.php index eff6b46c..ad8c5313 100644 --- a/php/templates/connection-string.php +++ b/php/templates/connection-string.php @@ -14,7 +14,8 @@
plugin = get_plugin_instance(); + public function __construct( Plugin $plugin ) { + $this->plugin = $plugin; $this->user_id = get_current_user_id(); if ( ! empty( $this->user_id ) ) { diff --git a/phpstan.neon.dist b/phpstan.neon.dist index c4bf7ab4..63e08f19 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: 0 + level: 1 paths: - php - cloudinary.php @@ -25,9 +25,13 @@ parameters: - vendor/php-stubs/woocommerce-stubs/woocommerce-stubs.php - tests/phpstan/stubs/wpml.php - tests/phpstan/stubs/wpcom-vip.php + - tests/phpstan/stubs/constants.php excludePaths: - build/* - node_modules/* - vendor/* # Extends WPCOM_VIP_CLI_Command, only available on the WordPress VIP platform. - php/class-cli-vip.php + # View templates are included into a class scope (so $this is bound at + # runtime), which PHPStan cannot model when analysing them standalone. + - php/templates/* diff --git a/tests/phpstan/stubs/constants.php b/tests/phpstan/stubs/constants.php new file mode 100644 index 00000000..355fb8db --- /dev/null +++ b/tests/phpstan/stubs/constants.php @@ -0,0 +1,41 @@ +