diff --git a/projects/packages/analyzer/.phan/baseline.php b/projects/packages/analyzer/.phan/baseline.php index 223c0ad67dc70..7b9b523e1542e 100644 --- a/projects/packages/analyzer/.phan/baseline.php +++ b/projects/packages/analyzer/.phan/baseline.php @@ -11,16 +11,13 @@ // # Issue statistics: // PhanUndeclaredProperty : 25+ occurrences // PhanTypeMismatchArgument : 8 occurrences - // PhanPossiblyUndeclaredVariable : 7 occurrences // PhanParamSignatureMismatch : 6 occurrences // PhanPluginDuplicateConditionalNullCoalescing : 6 occurrences // PhanTypeMismatchReturnProbablyReal : 6 occurrences // PhanUndeclaredClassMethod : 6 occurrences // PhanUndeclaredMethod : 6 occurrences // PhanTypeArraySuspiciousNullable : 5 occurrences - // PhanTypeMismatchArgumentNullable : 5 occurrences // PhanUndeclaredTypeParameter : 4 occurrences - // PhanNonClassMethodCall : 2 occurrences // PhanPluginDuplicateCatchStatementBody : 2 occurrences // PhanTypeMismatchDeclaredParam : 2 occurrences // PhanUndeclaredClassStaticProperty : 2 occurrences @@ -49,7 +46,6 @@ 'src/api/class-model.php' => ['PhanTypeArraySuspiciousNullable'], 'src/api/class-plugin-downloader.php' => ['PhanPluginDuplicateExpressionAssignmentOperation'], 'src/class-declarations.php' => ['PhanPluginDuplicateCatchStatementBody'], - 'src/class-differences.php' => ['PhanNonClassMethodCall', 'PhanPossiblyUndeclaredVariable', 'PhanTypeMismatchArgumentNullable'], 'src/class-invocations.php' => ['PhanPluginDuplicateCatchStatementBody'], 'src/class-utils.php' => ['PhanTypeMismatchArgument', 'PhanUndeclaredMethod', 'PhanUndeclaredProperty', 'PhanUndeclaredTypeParameter'], 'src/class-warnings.php' => ['PhanUndeclaredMethod'], diff --git a/projects/packages/analyzer/changelog/fix-phan-PhanPossiblyUndeclaredVariable b/projects/packages/analyzer/changelog/fix-phan-PhanPossiblyUndeclaredVariable new file mode 100644 index 0000000000000..473f10d2c7859 --- /dev/null +++ b/projects/packages/analyzer/changelog/fix-phan-PhanPossiblyUndeclaredVariable @@ -0,0 +1,4 @@ +Significance: patch +Type: fixed + +Phan: Address PhanPossiblyUndeclaredVariable violations. diff --git a/projects/packages/analyzer/src/class-differences.php b/projects/packages/analyzer/src/class-differences.php index 304b2ec9ccc59..4e63d6c9c24c6 100644 --- a/projects/packages/analyzer/src/class-differences.php +++ b/projects/packages/analyzer/src/class-differences.php @@ -36,6 +36,7 @@ public function find( $new_declarations, $prev_declarations, $new_root = null, $ $moved = false; $moved_with_empty_file = false; $deprecated = false; + $new_declaration = false; foreach ( $new_declarations->get() as $new_declaration ) { if ( $prev_declaration->match( $new_declaration ) ) { @@ -56,7 +57,7 @@ public function find( $new_declarations, $prev_declarations, $new_root = null, $ $moved = true; } } - $matched = true; + $matched = $new_declaration; break; } elseif ( $prev_declaration->partial_match( $new_declaration ) ) { // TODO this is to catch things like function args changed, method the same @@ -69,7 +70,7 @@ public function find( $new_declarations, $prev_declarations, $new_root = null, $ } // Add differences for any detected deprecations. - if ( $deprecated ) { + if ( $deprecated && $matched ) { switch ( $new_declaration->type() ) { case 'method': $this->add( new Differences\Class_Method_Deprecated( $prev_declaration ) ); diff --git a/projects/packages/backup/.phan/baseline.php b/projects/packages/backup/.phan/baseline.php index 6d2c06fd19914..810069a69e88c 100644 --- a/projects/packages/backup/.phan/baseline.php +++ b/projects/packages/backup/.phan/baseline.php @@ -12,11 +12,10 @@ // PhanTypeMismatchReturnProbablyReal : 15+ occurrences // PhanTypeMismatchReturn : 6 occurrences // PhanUndeclaredStaticMethod : 2 occurrences - // PhanPossiblyUndeclaredVariable : 1 occurrence // Currently, file_suppressions and directory_suppressions are the only supported suppressions 'file_suppressions' => [ - 'src/class-jetpack-backup.php' => ['PhanPossiblyUndeclaredVariable', 'PhanTypeMismatchReturn', 'PhanTypeMismatchReturnProbablyReal', 'PhanUndeclaredStaticMethod'], + 'src/class-jetpack-backup.php' => ['PhanTypeMismatchReturn', 'PhanTypeMismatchReturnProbablyReal', 'PhanUndeclaredStaticMethod'], 'src/class-rest-controller.php' => ['PhanTypeMismatchReturn', 'PhanTypeMismatchReturnProbablyReal'], ], // 'directory_suppressions' => ['src/directory_name' => ['PhanIssueName1', 'PhanIssueName2']] can be manually added if needed. diff --git a/projects/packages/backup/changelog/fix-phan-PhanPossiblyUndeclaredVariable b/projects/packages/backup/changelog/fix-phan-PhanPossiblyUndeclaredVariable new file mode 100644 index 0000000000000..473f10d2c7859 --- /dev/null +++ b/projects/packages/backup/changelog/fix-phan-PhanPossiblyUndeclaredVariable @@ -0,0 +1,4 @@ +Significance: patch +Type: fixed + +Phan: Address PhanPossiblyUndeclaredVariable violations. diff --git a/projects/packages/backup/src/class-jetpack-backup.php b/projects/packages/backup/src/class-jetpack-backup.php index 46cbdbea1c182..385c24b8fa2b3 100644 --- a/projects/packages/backup/src/class-jetpack-backup.php +++ b/projects/packages/backup/src/class-jetpack-backup.php @@ -717,6 +717,7 @@ public static function get_storage_addon_upsell_slug( $bytes_used, $bytes_availa return $upsell_products[ $bytes_1tb ]; } + $matched_bytes = $bytes_10gb; foreach ( $upsell_products as $bytes => $product ) { if ( $bytes > $additional_bytes_needed ) { $matched_bytes = $bytes; @@ -724,10 +725,6 @@ public static function get_storage_addon_upsell_slug( $bytes_used, $bytes_availa } } - if ( ! $matched_bytes ) { - $matched_bytes = $bytes_10gb; - } - return $upsell_products[ $matched_bytes ]; } diff --git a/projects/packages/connection/.phan/baseline.php b/projects/packages/connection/.phan/baseline.php index bf846b955fdbd..7c25835af9119 100644 --- a/projects/packages/connection/.phan/baseline.php +++ b/projects/packages/connection/.phan/baseline.php @@ -21,14 +21,13 @@ // PhanDeprecatedFunction : 2 occurrences // PhanNonClassMethodCall : 2 occurrences // PhanPluginUnreachableCode : 2 occurrences - // PhanPossiblyUndeclaredVariable : 2 occurrences // PhanTypeMismatchPropertyDefault : 2 occurrences - // PhanTypeMismatchReturnNullable : 2 occurrences // PhanTypePossiblyInvalidDimOffset : 2 occurrences // PhanPluginDuplicateAdjacentStatement : 1 occurrence // PhanPluginSimplifyExpressionBool : 1 occurrence // PhanTypeMismatchArgumentNullable : 1 occurrence // PhanTypeMismatchDeclaredParamNullable : 1 occurrence + // PhanTypeMismatchReturnNullable : 1 occurrence // PhanUndeclaredClassMethod : 1 occurrence // Currently, file_suppressions and directory_suppressions are the only supported suppressions @@ -40,7 +39,6 @@ 'src/class-error-handler.php' => ['PhanTypeMismatchReturnProbablyReal'], 'src/class-heartbeat.php' => ['PhanTypeMismatchPropertyDefault'], 'src/class-manager.php' => ['PhanPluginDuplicateConditionalNullCoalescing', 'PhanTypeMismatchArgument', 'PhanTypeMismatchDeclaredParamNullable', 'PhanTypeMismatchDefault', 'PhanTypeMismatchPropertyProbablyReal', 'PhanTypeMismatchReturn', 'PhanTypeMismatchReturnNullable', 'PhanTypeMismatchReturnProbablyReal'], - 'src/class-nonce-handler.php' => ['PhanPossiblyUndeclaredVariable', 'PhanTypeMismatchReturnNullable'], 'src/class-partner-coupon.php' => ['PhanPluginDuplicateConditionalNullCoalescing'], 'src/class-partner.php' => ['PhanTypeMismatchPropertyProbablyReal'], 'src/class-rest-authentication.php' => ['PhanTypeMismatchPropertyDefault', 'PhanTypeMismatchPropertyProbablyReal'], diff --git a/projects/packages/connection/changelog/fix-phan-PhanPossiblyUndeclaredVariable b/projects/packages/connection/changelog/fix-phan-PhanPossiblyUndeclaredVariable new file mode 100644 index 0000000000000..473f10d2c7859 --- /dev/null +++ b/projects/packages/connection/changelog/fix-phan-PhanPossiblyUndeclaredVariable @@ -0,0 +1,4 @@ +Significance: patch +Type: fixed + +Phan: Address PhanPossiblyUndeclaredVariable violations. diff --git a/projects/packages/connection/src/class-nonce-handler.php b/projects/packages/connection/src/class-nonce-handler.php index 48e14a15b8abd..888e46c887c3f 100644 --- a/projects/packages/connection/src/class-nonce-handler.php +++ b/projects/packages/connection/src/class-nonce-handler.php @@ -90,6 +90,8 @@ public function add( $timestamp, $nonce ) { // Raw query so we can avoid races: add_option will also update. $show_errors = $this->db->hide_errors(); + $return = false; + // Running `try...finally` to make sure that we re-enable errors in case of an exception. try { $old_nonce = $this->db->get_row( @@ -105,8 +107,6 @@ public function add( $timestamp, $nonce ) { 'no' ) ); - } else { - $return = false; } } finally { $this->db->show_errors( $show_errors ); diff --git a/projects/packages/image-cdn/.phan/baseline.php b/projects/packages/image-cdn/.phan/baseline.php index cc6e5297c116c..18fd0cfa387ee 100644 --- a/projects/packages/image-cdn/.phan/baseline.php +++ b/projects/packages/image-cdn/.phan/baseline.php @@ -13,11 +13,9 @@ // PhanPluginSimplifyExpressionBool : 6 occurrences // PhanPluginDuplicateConditionalNullCoalescing : 4 occurrences // PhanTypeMismatchArgumentProbablyReal : 4 occurrences - // PhanPossiblyUndeclaredVariable : 2 occurrences // PhanTypeMismatchPropertyProbablyReal : 2 occurrences // PhanNonClassMethodCall : 1 occurrence // PhanTypeArraySuspicious : 1 occurrence - // PhanTypeMismatchArgumentNullable : 1 occurrence // PhanTypeMismatchArgumentNullableInternal : 1 occurrence // PhanTypeMismatchReturn : 1 occurrence // PhanTypeMismatchReturnProbablyReal : 1 occurrence @@ -28,10 +26,10 @@ // Currently, file_suppressions and directory_suppressions are the only supported suppressions 'file_suppressions' => [ 'src/class-image-cdn-image-sizes.php' => ['PhanPluginSimplifyExpressionBool'], - 'src/class-image-cdn.php' => ['PhanNonClassMethodCall', 'PhanPluginDuplicateConditionalNullCoalescing', 'PhanPluginSimplifyExpressionBool', 'PhanPossiblyUndeclaredVariable', 'PhanTypeArraySuspicious', 'PhanTypeMismatchPropertyProbablyReal', 'PhanTypeMismatchReturn', 'PhanTypeMismatchReturnProbablyReal', 'PhanTypePossiblyInvalidDimOffset'], + 'src/class-image-cdn.php' => ['PhanNonClassMethodCall', 'PhanPluginDuplicateConditionalNullCoalescing', 'PhanPluginSimplifyExpressionBool', 'PhanTypeArraySuspicious', 'PhanTypeMismatchPropertyProbablyReal', 'PhanTypeMismatchReturn', 'PhanTypeMismatchReturnProbablyReal', 'PhanTypePossiblyInvalidDimOffset'], 'src/compatibility/photon.php' => ['PhanTypeMismatchArgumentNullableInternal'], 'tests/php/Image_CDN_Core_Test.php' => ['PhanTypeMismatchArgumentProbablyReal', 'PhanTypeObjectUnsetDeclaredProperty'], - 'tests/php/Image_CDN_Test.php' => ['PhanPluginDuplicateConditionalNullCoalescing', 'PhanPossiblyUndeclaredVariable', 'PhanTypeMismatchArgumentNullable', 'PhanTypeMismatchPropertyProbablyReal', 'PhanUndeclaredMethod', 'PhanUndeclaredStaticMethod'], + 'tests/php/Image_CDN_Test.php' => ['PhanPluginDuplicateConditionalNullCoalescing', 'PhanTypeMismatchPropertyProbablyReal', 'PhanUndeclaredMethod', 'PhanUndeclaredStaticMethod'], ], // 'directory_suppressions' => ['src/directory_name' => ['PhanIssueName1', 'PhanIssueName2']] can be manually added if needed. // (directory_suppressions will currently be ignored by subsequent calls to --save-baseline, but may be preserved in future Phan releases) diff --git a/projects/packages/image-cdn/changelog/fix-phan-PhanPossiblyUndeclaredVariable b/projects/packages/image-cdn/changelog/fix-phan-PhanPossiblyUndeclaredVariable new file mode 100644 index 0000000000000..473f10d2c7859 --- /dev/null +++ b/projects/packages/image-cdn/changelog/fix-phan-PhanPossiblyUndeclaredVariable @@ -0,0 +1,4 @@ +Significance: patch +Type: fixed + +Phan: Address PhanPossiblyUndeclaredVariable violations. diff --git a/projects/packages/image-cdn/src/class-image-cdn.php b/projects/packages/image-cdn/src/class-image-cdn.php index a71f82265f0c1..8f5e2e5b8f827 100644 --- a/projects/packages/image-cdn/src/class-image-cdn.php +++ b/projects/packages/image-cdn/src/class-image-cdn.php @@ -363,8 +363,10 @@ public static function filter_the_content( $content ) { } // Identify image source. - $src_orig = $processor->get_attribute( 'src' ); - $src = $src_orig; + $src_orig = $processor->get_attribute( 'src' ); + $src = $src_orig; + $placeholder_src = null; + $placeholder_src_orig = null; /* * Only examine tags that are considered an image, @@ -648,14 +650,12 @@ public static function filter_the_content( $content ) { $processor->set_attribute( 'src', $photon_url ); // If Lazy Load is in use, pass placeholder image through Photon. - if ( isset( $placeholder_src ) && self::validate_image_url( $placeholder_src ) ) { + if ( $placeholder_src !== null && self::validate_image_url( $placeholder_src ) ) { $placeholder_src = Image_CDN_Core::cdn_url( $placeholder_src ); if ( $placeholder_src !== $placeholder_src_orig ) { $processor->set_attribute( $source_type, $placeholder_src ); } - - unset( $placeholder_src ); } // If we are not transforming the image with resize, fit, or letterbox (lb), then we should remove diff --git a/projects/packages/image-cdn/tests/php/Image_CDN_Test.php b/projects/packages/image-cdn/tests/php/Image_CDN_Test.php index acf585b05ad32..90075f47d8dd2 100644 --- a/projects/packages/image-cdn/tests/php/Image_CDN_Test.php +++ b/projects/packages/image-cdn/tests/php/Image_CDN_Test.php @@ -143,10 +143,10 @@ protected function helper_get_query( $data ) { * @return int Post ID (attachment) of the image. */ protected function helper_get_image( $size = 'large', $meta = true ) { - if ( 'large' === $size ) { // 1600x1200 - $filename = __DIR__ . '/sample-content/test-image-large.png'; - } elseif ( 'medium' === $size ) { // 1024x768 + if ( 'medium' === $size ) { // 1024x768 $filename = __DIR__ . '/sample-content/test-image-medium.png'; + } else { // 1600x1200 - default to 'large' + $filename = __DIR__ . '/sample-content/test-image-large.png'; } // Add sizes that exist before uploading the file. add_image_size( 'jetpack_soft_defined', 700, 500, false ); // Intentionally not a 1.33333 ratio. diff --git a/projects/packages/publicize/.phan/baseline.php b/projects/packages/publicize/.phan/baseline.php index a7ed0443327d3..f89bfd2bd9dd4 100644 --- a/projects/packages/publicize/.phan/baseline.php +++ b/projects/packages/publicize/.phan/baseline.php @@ -14,7 +14,6 @@ // PhanPluginUnreachableCode : 4 occurrences // PhanTypeMismatchArgument : 3 occurrences // PhanUndeclaredClassMethod : 3 occurrences - // PhanPossiblyUndeclaredVariable : 2 occurrences // PhanTypeMismatchArgumentNullable : 2 occurrences // PhanTypeMismatchReturnProbablyReal : 2 occurrences // PhanTypeMissingReturn : 2 occurrences @@ -35,7 +34,7 @@ 'src/class-keyring-helper.php' => ['PhanTypeMismatchArgumentProbablyReal', 'PhanTypeMismatchDefault'], 'src/class-publicize-base.php' => ['PhanPluginDuplicateConditionalNullCoalescing', 'PhanPluginSimplifyExpressionBool', 'PhanSuspiciousMagicConstant', 'PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentNullable', 'PhanTypeMismatchArgumentNullableInternal', 'PhanTypeMismatchDimFetch'], 'src/class-publicize-ui.php' => ['PhanPluginDuplicateExpressionAssignmentOperation', 'PhanTypeMismatchReturnProbablyReal'], - 'src/class-publicize.php' => ['PhanParamSignatureMismatch', 'PhanPossiblyUndeclaredVariable', 'PhanTypeMismatchArgument', 'PhanTypeMissingReturn'], + 'src/class-publicize.php' => ['PhanParamSignatureMismatch', 'PhanTypeMismatchArgument', 'PhanTypeMissingReturn'], 'src/class-rest-controller.php' => ['PhanPluginDuplicateConditionalNullCoalescing', 'PhanTypeMismatchReturnProbablyReal'], 'src/rest-api/class-connections-controller.php' => ['PhanPluginMixedKeyNoKey', 'PhanTypeSuspiciousNonTraversableForeach'], 'src/rest-api/class-connections-post-field.php' => ['PhanPluginDuplicateConditionalNullCoalescing'], diff --git a/projects/packages/publicize/changelog/fix-phan-PhanPossiblyUndeclaredVariable b/projects/packages/publicize/changelog/fix-phan-PhanPossiblyUndeclaredVariable new file mode 100644 index 0000000000000..473f10d2c7859 --- /dev/null +++ b/projects/packages/publicize/changelog/fix-phan-PhanPossiblyUndeclaredVariable @@ -0,0 +1,4 @@ +Significance: patch +Type: fixed + +Phan: Address PhanPossiblyUndeclaredVariable violations. diff --git a/projects/packages/publicize/src/class-publicize.php b/projects/packages/publicize/src/class-publicize.php index 396bddc9cb219..82f498d99cdc0 100644 --- a/projects/packages/publicize/src/class-publicize.php +++ b/projects/packages/publicize/src/class-publicize.php @@ -653,8 +653,8 @@ public function test_connection( $service_name, $connection ) { $error_data = array( 'user_can_refresh' => $user_can_refresh, - 'refresh_text' => $refresh_text, - 'refresh_url' => $refresh_url, + 'refresh_text' => $refresh_text ?? null, + 'refresh_url' => $refresh_url ?? null, ); $this->test_connection_results[ $id ] = new WP_Error( $connection_error_code, $connection_test_message, $error_data ); diff --git a/projects/packages/search/.phan/baseline.php b/projects/packages/search/.phan/baseline.php index e7a91fd48081d..b780bdd14e659 100644 --- a/projects/packages/search/.phan/baseline.php +++ b/projects/packages/search/.phan/baseline.php @@ -20,7 +20,6 @@ // PhanImpossibleCondition : 2 occurrences // PhanDeprecatedPartiallySupportedCallable : 1 occurrence // PhanPluginSimplifyExpressionBool : 1 occurrence - // PhanPossiblyUndeclaredVariable : 1 occurrence // PhanTypeInvalidDimOffset : 1 occurrence // PhanTypeMismatchDeclaredParamNullable : 1 occurrence // PhanTypeMismatchDefault : 1 occurrence @@ -38,7 +37,7 @@ 'src/classic-search/class-classic-search.php' => ['PhanTypeInvalidDimOffset', 'PhanTypeMismatchDeclaredParamNullable', 'PhanTypeMismatchProperty', 'PhanTypeMismatchReturn', 'PhanTypePossiblyInvalidDimOffset'], 'src/customizer/customize-controls/class-excluded-post-types-control.php' => ['PhanTypeMismatchReturnProbablyReal'], 'src/instant-search/class-instant-search.php' => ['PhanTypeMismatchProperty', 'PhanTypeMismatchReturn', 'PhanTypeMismatchReturnProbablyReal'], - 'src/widgets/class-search-widget.php' => ['PhanPluginDuplicateConditionalNullCoalescing', 'PhanPossiblyUndeclaredVariable', 'PhanTypeMismatchArgument'], + 'src/widgets/class-search-widget.php' => ['PhanPluginDuplicateConditionalNullCoalescing', 'PhanTypeMismatchArgument'], 'src/wpes/class-query-builder.php' => ['PhanImpossibleCondition', 'PhanTypeMismatchDimAssignment', 'PhanTypeMismatchReturnProbablyReal'], 'tests/php/Helpers_Test.php' => ['PhanPluginMixedKeyNoKey', 'PhanTypeMismatchArgument'], 'tests/php/Plan_Test.php' => ['PhanDeprecatedFunction', 'PhanTypeMismatchArgumentProbablyReal'], diff --git a/projects/packages/search/changelog/fix-phan-PhanPossiblyUndeclaredVariable b/projects/packages/search/changelog/fix-phan-PhanPossiblyUndeclaredVariable new file mode 100644 index 0000000000000..473f10d2c7859 --- /dev/null +++ b/projects/packages/search/changelog/fix-phan-PhanPossiblyUndeclaredVariable @@ -0,0 +1,4 @@ +Significance: patch +Type: fixed + +Phan: Address PhanPossiblyUndeclaredVariable violations. diff --git a/projects/packages/search/src/widgets/class-search-widget.php b/projects/packages/search/src/widgets/class-search-widget.php index 3007b1a4dbbff..f451eb5cbc4e5 100644 --- a/projects/packages/search/src/widgets/class-search-widget.php +++ b/projects/packages/search/src/widgets/class-search-widget.php @@ -325,7 +325,7 @@ public function widget( $args, $instance ) { * @since 8.3.0 */ public function widget_non_instant( $args, $instance ) { - $display_filters = false; + $filters = array(); // Search instance must have been initialized before widget render. if ( is_search() ) { @@ -339,13 +339,9 @@ public function widget_non_instant( $args, $instance ) { if ( ! Helper::are_filters_by_widget_disabled() && ! $this->should_display_sitewide_filters() ) { $filters = array_filter( $filters, array( $this, 'is_for_current_widget' ) ); } - - if ( ! empty( $filters ) ) { - $display_filters = true; - } } - if ( ! $display_filters && empty( $instance['search_box_enabled'] ) && empty( $instance['user_sort_enabled'] ) ) { + if ( ! $filters && empty( $instance['search_box_enabled'] ) && empty( $instance['user_sort_enabled'] ) ) { return; } @@ -400,7 +396,7 @@ public function widget_non_instant( $args, $instance ) { ['PhanPluginDuplicateConditionalNullCoalescing', 'PhanTypeMismatchArgumentProbablyReal'], 'src/class-sender.php' => ['PhanNonClassMethodCall', 'PhanPluginDuplicateConditionalNullCoalescing', 'PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentProbablyReal', 'PhanTypeMismatchProperty', 'PhanTypeMismatchReturnProbablyReal'], 'src/class-server.php' => ['PhanTypeMismatchDeclaredParam', 'PhanTypeMismatchReturnProbablyReal'], - 'src/class-settings.php' => ['PhanPossiblyUndeclaredVariable', 'PhanTypeMismatchArgumentProbablyReal'], + 'src/class-settings.php' => ['PhanTypeMismatchArgumentProbablyReal'], 'src/class-utils.php' => ['PhanTypeExpectedObjectPropAccess'], 'src/modules/class-callables.php' => ['PhanParamSignatureMismatch', 'PhanTypeArraySuspicious', 'PhanTypeMismatchArgument'], 'src/modules/class-comments.php' => ['PhanTypeMismatchReturn', 'PhanTypeMismatchReturnProbablyReal'], 'src/modules/class-constants.php' => ['PhanParamSignatureMismatch'], 'src/modules/class-full-sync-immediately.php' => ['PhanPluginSimplifyExpressionBool', 'PhanTypeMismatchReturn'], - 'src/modules/class-full-sync.php' => ['PhanPluginDuplicateConditionalNullCoalescing', 'PhanPluginSimplifyExpressionBool', 'PhanPossiblyUndeclaredVariable'], + 'src/modules/class-full-sync.php' => ['PhanPluginDuplicateConditionalNullCoalescing', 'PhanPluginSimplifyExpressionBool'], 'src/modules/class-module.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchReturnProbablyReal'], 'src/modules/class-network-options.php' => ['PhanParamSignatureMismatch'], 'src/modules/class-options.php' => ['PhanParamSignatureMismatch', 'PhanTypeMismatchReturnProbablyReal'], diff --git a/projects/packages/sync/changelog/fix-phan-PhanPossiblyUndeclaredVariable b/projects/packages/sync/changelog/fix-phan-PhanPossiblyUndeclaredVariable new file mode 100644 index 0000000000000..473f10d2c7859 --- /dev/null +++ b/projects/packages/sync/changelog/fix-phan-PhanPossiblyUndeclaredVariable @@ -0,0 +1,4 @@ +Significance: patch +Type: fixed + +Phan: Address PhanPossiblyUndeclaredVariable violations. diff --git a/projects/packages/sync/src/class-settings.php b/projects/packages/sync/src/class-settings.php index 724df5a75e24d..1b1cec280416c 100644 --- a/projects/packages/sync/src/class-settings.php +++ b/projects/packages/sync/src/class-settings.php @@ -283,6 +283,7 @@ public static function update_settings( $new_settings ) { /** * Regular option update and handling */ + $updated = false; if ( self::is_network_setting( $setting ) ) { if ( is_multisite() && is_main_site() ) { $updated = update_site_option( self::SETTINGS_OPTION_PREFIX . $setting, $value ); diff --git a/projects/packages/sync/src/modules/class-full-sync.php b/projects/packages/sync/src/modules/class-full-sync.php index 67ad1694fbe17..af1f6fd65f091 100644 --- a/projects/packages/sync/src/modules/class-full-sync.php +++ b/projects/packages/sync/src/modules/class-full-sync.php @@ -340,6 +340,10 @@ public function get_range( $type ) { $id = 'comment_ID'; $where_sql = Settings::get_comments_filter_sql(); break; + default: + // This should never be reached due to the guard condition above, + // but Phan complains so let's make it happy. + return array(); } // TODO: Call $wpdb->prepare on the following query. diff --git a/projects/packages/videopress/.phan/baseline.php b/projects/packages/videopress/.phan/baseline.php index 16f09439cfe79..685af7ff78422 100644 --- a/projects/packages/videopress/.phan/baseline.php +++ b/projects/packages/videopress/.phan/baseline.php @@ -19,7 +19,6 @@ // PhanNonClassMethodCall : 4 occurrences // PhanTypeArraySuspiciousNullable : 4 occurrences // PhanTypeMismatchArgument : 4 occurrences - // PhanPossiblyUndeclaredVariable : 2 occurrences // PhanTypeInvalidDimOffset : 2 occurrences // PhanUndeclaredExtendedClass : 2 occurrences // PhanUndeclaredMethod : 2 occurrences @@ -53,7 +52,7 @@ 'src/videopress-divi/class-videopress-divi-extension.php' => ['PhanCommentOverrideOnNonOverrideMethod', 'PhanUndeclaredClass', 'PhanUndeclaredClassMethod', 'PhanUndeclaredExtendedClass', 'PhanUndeclaredMethod', 'PhanUndeclaredMethodInCallable'], 'src/videopress-divi/class-videopress-divi-module.php' => ['PhanUndeclaredExtendedClass'], 'tests/php/Uploader_Test.php' => ['PhanTypeMismatchArgumentProbablyReal'], - 'tests/php/VideoPress_Uploader_Test.php' => ['PhanPossiblyUndeclaredVariable', 'PhanTypeMismatchArgument'], + 'tests/php/VideoPress_Uploader_Test.php' => ['PhanTypeMismatchArgument'], ], // 'directory_suppressions' => ['src/directory_name' => ['PhanIssueName1', 'PhanIssueName2']] can be manually added if needed. // (directory_suppressions will currently be ignored by subsequent calls to --save-baseline, but may be preserved in future Phan releases) diff --git a/projects/packages/videopress/changelog/fix-phan-PhanPossiblyUndeclaredVariable b/projects/packages/videopress/changelog/fix-phan-PhanPossiblyUndeclaredVariable new file mode 100644 index 0000000000000..473f10d2c7859 --- /dev/null +++ b/projects/packages/videopress/changelog/fix-phan-PhanPossiblyUndeclaredVariable @@ -0,0 +1,4 @@ +Significance: patch +Type: fixed + +Phan: Address PhanPossiblyUndeclaredVariable violations. diff --git a/projects/packages/videopress/tests/php/VideoPress_Uploader_Test.php b/projects/packages/videopress/tests/php/VideoPress_Uploader_Test.php index 3df5c05babb4b..96f20a69e6b04 100644 --- a/projects/packages/videopress/tests/php/VideoPress_Uploader_Test.php +++ b/projects/packages/videopress/tests/php/VideoPress_Uploader_Test.php @@ -174,6 +174,8 @@ public function test_get_upload_token( $response_from_server, $expected, $throw $callback = array( $this, 'return_empty_response' ); } elseif ( 'error' === $response_from_server ) { $callback = array( $this, 'return_wp_error' ); + } else { + $this->fail( "Unsupported response '$response_from_server'" ); } $u = new Uploader( $this->valid_attachment_id ); if ( $throw ) { diff --git a/projects/plugins/boost/.phan/baseline.php b/projects/plugins/boost/.phan/baseline.php index 2c4106273d6ad..5a24e570c060e 100644 --- a/projects/plugins/boost/.phan/baseline.php +++ b/projects/plugins/boost/.phan/baseline.php @@ -18,12 +18,10 @@ // PhanUndeclaredClassConstant : 4 occurrences // PhanUndeclaredFunction : 4 occurrences // PhanPluginUseReturnValueInternalKnown : 2 occurrences - // PhanPossiblyUndeclaredVariable : 2 occurrences - // PhanTypeMismatchArgumentNullableInternal : 2 occurrences // PhanTypeMismatchPropertyDefault : 2 occurrences // PhanCoalescingNeverNull : 1 occurrence // PhanRedefineFunction : 1 occurrence - // PhanTypeInvalidUnaryOperandIncOrDec : 1 occurrence + // PhanTypeMismatchArgumentNullableInternal : 1 occurrence // PhanTypeMismatchProperty : 1 occurrence // PhanTypeMissingReturn : 1 occurrence // PhanUndeclaredClassMethod : 1 occurrence @@ -37,7 +35,7 @@ 'app/lib/class-cli.php' => ['PhanPluginDuplicateConditionalNullCoalescing', 'PhanTypeMismatchArgument'], 'app/lib/critical-css/class-critical-css-state.php' => ['PhanPluginDuplicateConditionalNullCoalescing', 'PhanTypeArraySuspiciousNullable'], 'app/lib/minify/class-concatenate-css.php' => ['PhanPluginUseReturnValueInternalKnown', 'PhanTypeMismatchArgument'], - 'app/lib/minify/class-concatenate-js.php' => ['PhanPluginUseReturnValueInternalKnown', 'PhanPossiblyUndeclaredVariable', 'PhanTypeInvalidUnaryOperandIncOrDec', 'PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentNullableInternal'], + 'app/lib/minify/class-concatenate-js.php' => ['PhanPluginUseReturnValueInternalKnown', 'PhanTypeMismatchArgument'], 'app/lib/minify/class-dependency-path-mapping.php' => ['PhanUndeclaredConstant'], 'app/lib/minify/functions-helpers.php' => ['PhanTypeMismatchArgumentNullableInternal', 'PhanUndeclaredClassMethod', 'PhanUndeclaredClassReference', 'PhanUndeclaredConstant'], 'app/modules/image-guide/class-image-guide-proxy.php' => ['PhanPluginDuplicateConditionalNullCoalescing'], diff --git a/projects/plugins/boost/app/lib/minify/class-concatenate-js.php b/projects/plugins/boost/app/lib/minify/class-concatenate-js.php index a98ffb9298640..e43c496ec0e30 100644 --- a/projects/plugins/boost/app/lib/minify/class-concatenate-js.php +++ b/projects/plugins/boost/app/lib/minify/class-concatenate-js.php @@ -83,6 +83,7 @@ public function do_items( $handles = false, $group = false ) { $level = 0; $using_strict = false; + $strict_count = 0; foreach ( $this->to_do as $key => $handle ) { $script_is_strict = false; if ( in_array( $handle, $this->done, true ) || ! isset( $this->registered[ $handle ] ) ) { @@ -140,6 +141,7 @@ public function do_items( $handles = false, $group = false ) { $do_concat = false; } + $js_realpath = false; if ( $do_concat ) { // Resolve paths and concat scripts that exist in the filesystem $js_realpath = $this->dependency_path_mapping->dependency_src_to_fs_path( $js_url ); diff --git a/projects/plugins/boost/changelog/fix-phan-PhanPossiblyUndeclaredVariable b/projects/plugins/boost/changelog/fix-phan-PhanPossiblyUndeclaredVariable new file mode 100644 index 0000000000000..473f10d2c7859 --- /dev/null +++ b/projects/plugins/boost/changelog/fix-phan-PhanPossiblyUndeclaredVariable @@ -0,0 +1,4 @@ +Significance: patch +Type: fixed + +Phan: Address PhanPossiblyUndeclaredVariable violations. diff --git a/projects/plugins/jetpack/.phan/baseline.php b/projects/plugins/jetpack/.phan/baseline.php index b24e9a3868045..99c6d56ee6811 100644 --- a/projects/plugins/jetpack/.phan/baseline.php +++ b/projects/plugins/jetpack/.phan/baseline.php @@ -16,10 +16,8 @@ // PhanTypeMismatchReturnProbablyReal : 120+ occurrences // PhanTypePossiblyInvalidDimOffset : 90+ occurrences // PhanDeprecatedFunction : 60+ occurrences - // PhanPossiblyUndeclaredVariable : 55+ occurrences // PhanTypeArraySuspiciousNullable : 55+ occurrences // PhanRedefineFunction : 45+ occurrences - // PhanTypeMismatchArgumentNullable : 45+ occurrences // PhanPluginDuplicateAdjacentStatement : 40+ occurrences // PhanTypeExpectedObjectPropAccess : 30+ occurrences // PhanTypeMismatchDefault : 25+ occurrences @@ -30,6 +28,7 @@ // PhanTypeArraySuspicious : 20+ occurrences // PhanTypeMismatchDimFetch : 20+ occurrences // PhanSuspiciousMagicConstant : 15+ occurrences + // PhanTypeMismatchArgumentNullable : 15+ occurrences // PhanTypeMismatchPropertyDefault : 15+ occurrences // PhanTypeSuspiciousNonTraversableForeach : 15+ occurrences // PhanPluginDuplicateExpressionAssignmentOperation : 10+ occurrences @@ -48,6 +47,7 @@ // PhanCommentAbstractOnInheritedMethod : 6 occurrences // PhanTypeInvalidLeftOperandOfNumericOp : 6 occurrences // PhanDeprecatedClass : 5 occurrences + // PhanPossiblyUndeclaredVariable : 5 occurrences // PhanTypeMismatchDimAssignment : 5 occurrences // PhanTypeInvalidDimOffset : 4 occurrences // PhanTypeInvalidLeftOperandOfAdd : 4 occurrences @@ -125,7 +125,7 @@ '_inc/lib/core-api/wpcom-endpoints/service-api-keys.php' => ['PhanPluginDuplicateConditionalNullCoalescing', 'PhanTypeArraySuspicious', 'PhanTypeMismatchReturnProbablyReal'], '_inc/lib/debugger/class-jetpack-cxn-test-base.php' => ['PhanDeprecatedFunctionInternal', 'PhanTypeArraySuspiciousNullable', 'PhanTypeMismatchArgumentInternal', 'PhanTypeMismatchReturn'], '_inc/lib/debugger/class-jetpack-cxn-tests.php' => ['PhanPluginSimplifyExpressionBool'], - '_inc/lib/debugger/class-jetpack-debug-data.php' => ['PhanPossiblyUndeclaredVariable', 'PhanTypeMismatchArgument'], + '_inc/lib/debugger/class-jetpack-debug-data.php' => ['PhanTypeMismatchArgument'], '_inc/lib/debugger/class-jetpack-debugger.php' => ['PhanTypeMismatchArgumentProbablyReal'], '_inc/lib/debugger/debug-functions.php' => ['PhanTypeMismatchReturnProbablyReal'], '_inc/lib/icalendar-reader.php' => ['PhanPluginDuplicateConditionalNullCoalescing', 'PhanPluginDuplicateExpressionAssignmentOperation', 'PhanPossiblyUndeclaredVariable', 'PhanTypeInvalidLeftOperandOfNumericOp', 'PhanTypeMismatchArgumentNullableInternal', 'PhanTypeMismatchDimFetch', 'PhanTypeMismatchReturnProbablyReal', 'PhanTypePossiblyInvalidDimOffset'], @@ -143,12 +143,12 @@ 'class.jetpack-heartbeat.php' => ['PhanTypeMismatchPropertyDefault'], 'class.jetpack-modules-list-table.php' => ['PhanCommentAbstractOnInheritedMethod'], 'class.jetpack-network-sites-list-table.php' => ['PhanCommentAbstractOnInheritedMethod'], - 'class.jetpack-network.php' => ['PhanPossiblyUndeclaredVariable', 'PhanTypeMismatchArgumentNullable', 'PhanTypeMismatchReturnNullable', 'PhanTypeMismatchReturnProbablyReal'], + 'class.jetpack-network.php' => ['PhanTypeMismatchReturnNullable', 'PhanTypeMismatchReturnProbablyReal'], 'class.jetpack-post-images.php' => ['PhanPluginDuplicateConditionalNullCoalescing', 'PhanTypeMismatchArgument', 'PhanTypeMismatchDefault', 'PhanTypeMismatchReturnProbablyReal'], 'class.jetpack-twitter-cards.php' => ['PhanPluginSimplifyExpressionBool', 'PhanTypeArraySuspiciousNullable', 'PhanTypeMismatchArgument', 'PhanTypePossiblyInvalidDimOffset'], - 'class.jetpack.php' => ['PhanDeprecatedFunction', 'PhanPluginDuplicateConditionalNullCoalescing', 'PhanPossiblyUndeclaredVariable', 'PhanTypeArraySuspiciousNullable', 'PhanTypeExpectedObjectPropAccess', 'PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentNullableInternal', 'PhanTypeMismatchArgumentProbablyReal', 'PhanTypeMismatchDefault', 'PhanTypeMismatchPropertyDefault', 'PhanTypeMismatchReturn', 'PhanTypeMismatchReturnProbablyReal'], - 'class.json-api-endpoints.php' => ['PhanPluginDuplicateConditionalNullCoalescing', 'PhanPluginSimplifyExpressionBool', 'PhanPossiblyUndeclaredVariable', 'PhanTypeArraySuspiciousNullable', 'PhanTypeComparisonToArray', 'PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentInternal', 'PhanTypeMismatchArgumentNullable', 'PhanTypeMismatchArgumentProbablyReal', 'PhanTypeMismatchReturnProbablyReal'], - 'class.json-api.php' => ['PhanPluginDuplicateSwitchCaseLooseEquality', 'PhanPluginSimplifyExpressionBool', 'PhanPossiblyUndeclaredVariable', 'PhanTypeArraySuspicious', 'PhanTypeArraySuspiciousNullable', 'PhanTypeMismatchArgumentNullable', 'PhanTypeMismatchProperty', 'PhanTypeMismatchPropertyDefault', 'PhanTypeMismatchReturnProbablyReal'], + 'class.jetpack.php' => ['PhanDeprecatedFunction', 'PhanPluginDuplicateConditionalNullCoalescing', 'PhanTypeArraySuspiciousNullable', 'PhanTypeExpectedObjectPropAccess', 'PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentNullableInternal', 'PhanTypeMismatchArgumentProbablyReal', 'PhanTypeMismatchDefault', 'PhanTypeMismatchPropertyDefault', 'PhanTypeMismatchReturn', 'PhanTypeMismatchReturnProbablyReal'], + 'class.json-api-endpoints.php' => ['PhanPluginDuplicateConditionalNullCoalescing', 'PhanPluginSimplifyExpressionBool', 'PhanTypeArraySuspiciousNullable', 'PhanTypeComparisonToArray', 'PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentInternal', 'PhanTypeMismatchArgumentNullable', 'PhanTypeMismatchArgumentProbablyReal', 'PhanTypeMismatchReturnProbablyReal'], + 'class.json-api.php' => ['PhanPluginDuplicateSwitchCaseLooseEquality', 'PhanPluginSimplifyExpressionBool', 'PhanTypeArraySuspicious', 'PhanTypeArraySuspiciousNullable', 'PhanTypeMismatchProperty', 'PhanTypeMismatchPropertyDefault', 'PhanTypeMismatchReturnProbablyReal'], 'enhanced-open-graph.php' => ['PhanPluginDuplicateConditionalNullCoalescing', 'PhanTypeArraySuspiciousNullable'], 'extensions/blocks/ai-chat/ai-chat.php' => ['PhanPluginDuplicateConditionalNullCoalescing', 'PhanTypeMismatchArgument'], 'extensions/blocks/blog-stats/blog-stats.php' => ['PhanTypeMismatchReturnProbablyReal'], @@ -173,7 +173,7 @@ 'extensions/blocks/repeat-visitor/repeat-visitor.php' => ['PhanPluginDuplicateConditionalNullCoalescing'], 'extensions/blocks/sharing-button/class-sharing-source-block.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchReturnProbablyReal'], 'extensions/blocks/slideshow/slideshow.php' => ['PhanPluginSimplifyExpressionBool', 'PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentInternal', 'PhanTypeMismatchReturnProbablyReal'], - 'extensions/blocks/story/story.php' => ['PhanPluginDuplicateConditionalNullCoalescing', 'PhanPossiblyUndeclaredVariable'], + 'extensions/blocks/story/story.php' => ['PhanPluginDuplicateConditionalNullCoalescing'], 'extensions/blocks/subscriptions/subscriptions.php' => ['PhanPluginDuplicateConditionalNullCoalescing'], 'extensions/blocks/top-posts/top-posts.php' => ['PhanTypeMismatchReturnProbablyReal'], 'extensions/blocks/wordads/wordads.php' => ['PhanTypeMismatchArgument'], @@ -232,9 +232,9 @@ 'json-endpoints/class.wpcom-json-api-update-customcss.php' => ['PhanTypeMismatchReturn'], 'json-endpoints/class.wpcom-json-api-update-media-endpoint.php' => ['PhanTypeMismatchReturn'], 'json-endpoints/class.wpcom-json-api-update-media-v1-1-endpoint.php' => ['PhanPluginDuplicateConditionalNullCoalescing', 'PhanTypeMismatchArgument', 'PhanTypeMismatchReturn'], - 'json-endpoints/class.wpcom-json-api-update-post-endpoint.php' => ['PhanPluginDuplicateConditionalNullCoalescing', 'PhanPluginSimplifyExpressionBool', 'PhanPossiblyUndeclaredVariable', 'PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentNullable', 'PhanTypeMismatchReturn', 'PhanTypePossiblyInvalidDimOffset'], + 'json-endpoints/class.wpcom-json-api-update-post-endpoint.php' => ['PhanPluginDuplicateConditionalNullCoalescing', 'PhanPluginSimplifyExpressionBool', 'PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentNullable', 'PhanTypeMismatchReturn', 'PhanTypePossiblyInvalidDimOffset'], 'json-endpoints/class.wpcom-json-api-update-post-v1-1-endpoint.php' => ['PhanPluginDuplicateConditionalNullCoalescing', 'PhanPluginSimplifyExpressionBool', 'PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentNullable', 'PhanTypeMismatchReturn', 'PhanTypePossiblyInvalidDimOffset'], - 'json-endpoints/class.wpcom-json-api-update-post-v1-2-endpoint.php' => ['PhanPluginDuplicateConditionalNullCoalescing', 'PhanPluginSimplifyExpressionBool', 'PhanPossiblyUndeclaredVariable', 'PhanTypeArraySuspiciousNullable', 'PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentNullable', 'PhanTypePossiblyInvalidDimOffset'], + 'json-endpoints/class.wpcom-json-api-update-post-v1-2-endpoint.php' => ['PhanPluginDuplicateConditionalNullCoalescing', 'PhanPluginSimplifyExpressionBool', 'PhanTypeArraySuspiciousNullable', 'PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentNullable', 'PhanTypePossiblyInvalidDimOffset'], 'json-endpoints/class.wpcom-json-api-update-site-homepage-endpoint.php' => ['PhanTypeMismatchReturn'], 'json-endpoints/class.wpcom-json-api-update-site-logo-endpoint.php' => ['PhanTypeMismatchReturn'], 'json-endpoints/class.wpcom-json-api-update-taxonomy-endpoint.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchReturn'], @@ -255,7 +255,7 @@ 'json-endpoints/jetpack/class.jetpack-json-api-log-endpoint.php' => ['PhanTypeMismatchPropertyDefault'], 'json-endpoints/jetpack/class.jetpack-json-api-modules-endpoint.php' => ['PhanParamSignatureMismatch', 'PhanTypeMismatchArgument'], 'json-endpoints/jetpack/class.jetpack-json-api-plugins-endpoint.php' => ['PhanParamSignatureMismatch', 'PhanPluginDuplicateExpressionAssignmentOperation', 'PhanTypeMismatchArgument'], - 'json-endpoints/jetpack/class.jetpack-json-api-plugins-install-endpoint.php' => ['PhanPossiblyUndeclaredVariable', 'PhanTypeMismatchDimAssignment'], + 'json-endpoints/jetpack/class.jetpack-json-api-plugins-install-endpoint.php' => ['PhanTypeMismatchDimAssignment'], 'json-endpoints/jetpack/class.jetpack-json-api-plugins-modify-endpoint.php' => ['PhanTypeInvalidLeftOperandOfBitwiseOp', 'PhanTypeInvalidRightOperandOfBitwiseOp', 'PhanTypeMismatchArgumentProbablyReal'], 'json-endpoints/jetpack/class.jetpack-json-api-plugins-modify-v1-2-endpoint.php' => ['PhanTypeInvalidLeftOperandOfBitwiseOp', 'PhanTypeInvalidRightOperandOfBitwiseOp'], 'json-endpoints/jetpack/class.jetpack-json-api-plugins-new-endpoint.php' => ['PhanParamSignatureMismatch', 'PhanTypeMismatchArgument', 'PhanTypeMissingReturn'], @@ -304,7 +304,6 @@ 'modules/shortcodes/archives.php' => ['PhanPluginSimplifyExpressionBool'], 'modules/shortcodes/brightcove.php' => ['PhanTypeMismatchArgument'], 'modules/shortcodes/class.filter-embedded-html-objects.php' => ['PhanTypeMismatchPropertyDefault'], - 'modules/shortcodes/crowdsignal.php' => ['PhanPossiblyUndeclaredVariable'], 'modules/shortcodes/dailymotion.php' => ['PhanTypeMismatchArgument'], 'modules/shortcodes/flickr.php' => ['PhanTypeMismatchReturn'], 'modules/shortcodes/getty.php' => ['PhanTypeMismatchArgument'], @@ -342,9 +341,9 @@ 'modules/sitemaps/sitemap-logger.php' => ['PhanTypeMismatchProperty'], 'modules/sitemaps/sitemaps.php' => ['PhanTypeMismatchArgument'], 'modules/stats.php' => ['PhanSuspiciousMagicConstant', 'PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentProbablyReal', 'PhanTypeMismatchReturn', 'PhanTypeMismatchReturnNullable', 'PhanTypeMismatchReturnProbablyReal'], - 'modules/subscriptions.php' => ['PhanPossiblyUndeclaredVariable', 'PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentProbablyReal', 'PhanTypeMismatchDefault', 'PhanTypeMismatchReturnProbablyReal', 'PhanTypeSuspiciousNonTraversableForeach'], + 'modules/subscriptions.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentProbablyReal', 'PhanTypeMismatchDefault', 'PhanTypeMismatchReturnProbablyReal', 'PhanTypeSuspiciousNonTraversableForeach'], 'modules/subscriptions/subscribe-modal/class-jetpack-subscribe-modal.php' => ['PhanTypeMismatchReturnNullable'], - 'modules/subscriptions/views.php' => ['PhanPluginDuplicateConditionalNullCoalescing', 'PhanPossiblyUndeclaredVariable', 'PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentNullable', 'PhanTypeMismatchArgumentNullableInternal', 'PhanTypePossiblyInvalidDimOffset'], + 'modules/subscriptions/views.php' => ['PhanPluginDuplicateConditionalNullCoalescing', 'PhanTypeMismatchArgument', 'PhanTypePossiblyInvalidDimOffset'], 'modules/theme-tools/content-options.php' => ['PhanRedefineFunction'], 'modules/theme-tools/content-options/author-bio.php' => ['PhanRedefineFunction', 'PhanTypeMismatchArgument'], 'modules/theme-tools/content-options/blog-display.php' => ['PhanPluginDuplicateExpressionAssignmentOperation', 'PhanRedefineFunction'], @@ -383,7 +382,7 @@ 'modules/widgets/class-jetpack-instagram-widget.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchReturn', 'PhanTypePossiblyInvalidDimOffset'], 'modules/widgets/contact-info.php' => ['PhanPluginDuplicateConditionalNullCoalescing', 'PhanTypeMismatchArgument'], 'modules/widgets/facebook-likebox.php' => ['PhanPluginDuplicateConditionalNullCoalescing', 'PhanTypeMismatchArgument', 'PhanTypePossiblyInvalidDimOffset'], - 'modules/widgets/flickr.php' => ['PhanPossiblyUndeclaredVariable', 'PhanTypeMismatchArgumentNullable'], + 'modules/widgets/flickr.php' => ['PhanTypeMismatchArgumentNullable'], 'modules/widgets/flickr/form.php' => ['PhanTypeMismatchArgument'], 'modules/widgets/follow-button.php' => ['PhanPluginUseReturnValueInternalKnown'], 'modules/widgets/gallery.php' => ['PhanPluginDuplicateConditionalNullCoalescing', 'PhanTypeMismatchReturnProbablyReal'], @@ -451,14 +450,14 @@ 'tests/php/modules/shortcodes/Jetpack_Shortcodes_Vimeo_Test.php' => ['PhanTypeMismatchArgumentProbablyReal'], 'tests/php/modules/sitemaps/Jetpack_Sitemap_Buffer_Test.php' => ['PhanTypeMismatchArgumentProbablyReal', 'PhanTypeMismatchPropertyProbablyReal'], 'tests/php/modules/sitemaps/Jetpack_Sitemap_Librarian_Test.php' => ['PhanTypeMismatchArgument'], - 'tests/php/modules/subscriptions/Jetpack_Subscriptions_Test.php' => ['PhanDeprecatedProperty', 'PhanPluginDuplicateConditionalNullCoalescing', 'PhanPossiblyUndeclaredVariable', 'PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentProbablyReal'], + 'tests/php/modules/subscriptions/Jetpack_Subscriptions_Test.php' => ['PhanDeprecatedProperty', 'PhanPluginDuplicateConditionalNullCoalescing', 'PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentProbablyReal'], 'tests/php/modules/widgets/Contact_Info_Widget_Test.php' => ['PhanTypeMismatchArgumentProbablyReal'], 'tests/php/modules/widgets/Jetpack_Display_Posts_Widget_Test.php' => ['PhanTypeMismatchArgumentProbablyReal'], 'tests/php/sync/Jetpack_Sync_Checksum_Smoke_Test.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchReturn'], 'tests/php/sync/Jetpack_Sync_Checksum_Test.php' => ['PhanTypeArraySuspiciousNullable', 'PhanTypeMismatchReturn'], 'tests/php/sync/Jetpack_Sync_Comments_Test.php' => ['PhanTypeMismatchArgument'], - 'tests/php/sync/Jetpack_Sync_Full_Immediately_Test.php' => ['PhanPluginDuplicateAdjacentStatement', 'PhanPossiblyUndeclaredVariable', 'PhanTypeArraySuspiciousNullable', 'PhanTypeMismatchArgumentNullable', 'PhanTypeMismatchArgumentProbablyReal'], - 'tests/php/sync/Jetpack_Sync_Full_Test.php' => ['PhanPluginDuplicateAdjacentStatement', 'PhanPossiblyUndeclaredVariable', 'PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentNullable', 'PhanTypeMismatchArgumentProbablyReal', 'PhanTypeMismatchArgumentReal'], + 'tests/php/sync/Jetpack_Sync_Full_Immediately_Test.php' => ['PhanPluginDuplicateAdjacentStatement', 'PhanTypeArraySuspiciousNullable', 'PhanTypeMismatchArgumentProbablyReal'], + 'tests/php/sync/Jetpack_Sync_Full_Test.php' => ['PhanPluginDuplicateAdjacentStatement', 'PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentProbablyReal', 'PhanTypeMismatchArgumentReal'], 'tests/php/sync/Jetpack_Sync_Functions_Test.php' => ['PhanPluginDuplicateConditionalNullCoalescing', 'PhanTypeMismatchArgumentProbablyReal', 'PhanTypeMissingReturn'], 'tests/php/sync/Jetpack_Sync_Import_Test.php' => ['PhanRedefineClass'], 'tests/php/sync/Jetpack_Sync_Integration_Test.php' => ['PhanTypeMismatchArgumentProbablyReal', 'PhanTypeMismatchPropertyProbablyReal'], diff --git a/projects/plugins/jetpack/_inc/lib/debugger/class-jetpack-debug-data.php b/projects/plugins/jetpack/_inc/lib/debugger/class-jetpack-debug-data.php index 4bf7131ffcb81..9cc7da823b5c1 100644 --- a/projects/plugins/jetpack/_inc/lib/debugger/class-jetpack-debug-data.php +++ b/projects/plugins/jetpack/_inc/lib/debugger/class-jetpack-debug-data.php @@ -226,12 +226,12 @@ public static function debug_data() { ); $debug_info['blog_token'] = array( 'label' => 'Blog Public Key', - 'value' => ( $blog_token ) ? $blog_key : 'Not set.', + 'value' => $blog_key ?? 'Not set.', 'private' => false, ); $debug_info['user_token'] = array( 'label' => 'User Public Key', - 'value' => ( $user_token ) ? $user_key : 'Not set.', + 'value' => $user_key ?? 'Not set.', 'private' => false, ); diff --git a/projects/plugins/jetpack/changelog/fix-phan-PhanPossiblyUndeclaredVariable b/projects/plugins/jetpack/changelog/fix-phan-PhanPossiblyUndeclaredVariable new file mode 100644 index 0000000000000..7d0055a6c5c14 --- /dev/null +++ b/projects/plugins/jetpack/changelog/fix-phan-PhanPossiblyUndeclaredVariable @@ -0,0 +1,4 @@ +Significance: patch +Type: other + +Phan: Address PhanPossiblyUndeclaredVariable violations. diff --git a/projects/plugins/jetpack/class.jetpack-network.php b/projects/plugins/jetpack/class.jetpack-network.php index 2e166064d57f2..3e8e4a9cec656 100644 --- a/projects/plugins/jetpack/class.jetpack-network.php +++ b/projects/plugins/jetpack/class.jetpack-network.php @@ -387,8 +387,8 @@ public function show_jetpack_notice() { $classname = 'error'; } ?> -
-

+
+

-1 ) { $author['site_ID'] = (int) $site_id; - $author['site_visible'] = $site_visible; + $author['site_visible'] = $site_visible ?? null; } // Only include WordPress.com user data when author_wpcom_data is enabled. diff --git a/projects/plugins/jetpack/class.json-api.php b/projects/plugins/jetpack/class.json-api.php index 21e8dbd2db0ea..5b5f67244227d 100644 --- a/projects/plugins/jetpack/class.json-api.php +++ b/projects/plugins/jetpack/class.json-api.php @@ -476,7 +476,8 @@ public function serve( $exit = true ) { } // Find which endpoint to serve. - $found = false; + $found = false; + $path_pieces = array(); foreach ( $this->endpoints as $endpoint_path_versions => $endpoints_by_method ) { // @todo Determine if anything depends on this being serialized rather than e.g. JSON. // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_unserialize -- Legacy, possibly depended on elsewhere. @@ -499,6 +500,7 @@ public function serve( $exit = true ) { $endpoint_path = untrailingslashit( $endpoint_path ); if ( $is_help ) { // Truncate path at help depth. + // @phan-suppress-next-line PhanPossiblyUndeclaredVariable -- $depth is set when $is_help is true. $endpoint_path = implode( '/', array_slice( explode( '/', $endpoint_path ), 0, $depth ) ); } @@ -557,6 +559,7 @@ public function serve( $exit = true ) { */ do_action( 'wpcom_json_api_output', 'help' ); $proxied = function_exists( 'wpcom_is_proxied_request' ) ? wpcom_is_proxied_request() : false; + // @phan-suppress-next-line PhanPossiblyUndeclaredVariable -- $help_content_type is set when $is_help is true. if ( 'json' === $help_content_type ) { $docs = array(); foreach ( $matching_endpoints as $matching_endpoint ) { @@ -576,13 +579,16 @@ public function serve( $exit = true ) { exit( 0 ); } + // @phan-suppress-next-line PhanPossiblyUndeclaredVariable -- $endpoint is set when $find_all_matching_endpoints is false and $found is true, which is guaranteed here. if ( $endpoint->in_testing && ! WPCOM_JSON_API__DEBUG ) { return $this->output( 404, '', 'text/plain' ); } /** This action is documented in class.json-api.php */ + // @phan-suppress-next-line PhanPossiblyUndeclaredVariable -- $endpoint is set when $find_all_matching_endpoints is false and $found is true, which is guaranteed here. do_action( 'wpcom_json_api_output', $endpoint->stat ); + // @phan-suppress-next-line PhanPossiblyUndeclaredVariable -- $endpoint is set when $find_all_matching_endpoints is false and $found is true, which is guaranteed here. $response = $this->process_request( $endpoint, $path_pieces ); if ( ! $response && ! is_array( $response ) ) { diff --git a/projects/plugins/jetpack/extensions/blocks/story/story.php b/projects/plugins/jetpack/extensions/blocks/story/story.php index e8658d464d124..471f5b763630b 100644 --- a/projects/plugins/jetpack/extensions/blocks/story/story.php +++ b/projects/plugins/jetpack/extensions/blocks/story/story.php @@ -187,6 +187,10 @@ function enrich_video_meta( $media_file ) { * @return string */ function render_image( $media ) { + $src = ''; + $width = null; + $height = null; + if ( empty( $media['id'] ) || empty( $media['url'] ) ) { return __( 'Error retrieving media', 'jetpack' ); } @@ -196,7 +200,7 @@ function render_image( $media ) { } // if image does not match. - if ( ! $image || isset( $media['url'] ) && ! is_same_resource( $media['url'], $src ) ) { + if ( ! $image || isset( $media['url'] ) && ! is_same_resource( $media['url'], $src ?? '' ) ) { $width = isset( $media['width'] ) ? $media['width'] : null; $height = isset( $media['height'] ) ? $media['height'] : null; $title = isset( $media['title'] ) ? $media['title'] : ''; diff --git a/projects/plugins/jetpack/json-endpoints/class.wpcom-json-api-update-post-endpoint.php b/projects/plugins/jetpack/json-endpoints/class.wpcom-json-api-update-post-endpoint.php index f14d0e76b20f7..d2f9c1d2f6272 100644 --- a/projects/plugins/jetpack/json-endpoints/class.wpcom-json-api-update-post-endpoint.php +++ b/projects/plugins/jetpack/json-endpoints/class.wpcom-json-api-update-post-endpoint.php @@ -543,6 +543,7 @@ public function write_post( $path, $blog_id, $post_id ) { $post_id = wp_insert_post( add_magic_quotes( $insert ), true ); } else { + // @phan-suppress-next-line PhanPossiblyUndeclaredVariable -- $post is set and validated several blocks earlier if $new (only set once) is falsy. $insert['ID'] = $post->ID; // wp_update_post ignores date unless edit_date is set diff --git a/projects/plugins/jetpack/json-endpoints/class.wpcom-json-api-update-post-v1-2-endpoint.php b/projects/plugins/jetpack/json-endpoints/class.wpcom-json-api-update-post-v1-2-endpoint.php index d93b77c791f08..bfdce982ef38e 100644 --- a/projects/plugins/jetpack/json-endpoints/class.wpcom-json-api-update-post-v1-2-endpoint.php +++ b/projects/plugins/jetpack/json-endpoints/class.wpcom-json-api-update-post-v1-2-endpoint.php @@ -621,6 +621,7 @@ public function write_post( $path, $blog_id, $post_id ) { $post_id = wp_insert_post( add_magic_quotes( $insert ), true ); } } else { + // @phan-suppress-next-line PhanPossiblyUndeclaredVariable -- $post is set and validated several blocks earlier if $new (only set once) is falsy. $insert['ID'] = $post->ID; // wp_update_post ignores date unless edit_date is set diff --git a/projects/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-plugins-install-endpoint.php b/projects/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-plugins-install-endpoint.php index 9fd8c6a4150ee..c3e4a5a642fc8 100644 --- a/projects/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-plugins-install-endpoint.php +++ b/projects/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-plugins-install-endpoint.php @@ -105,6 +105,8 @@ protected function install() { } // No errors, install worked. Now replace the slug with the actual plugin id + // @todo This code looks a bit suspect; why do we loop through plugins and only look at the last one? + // @phan-suppress-next-line PhanPossiblyUndeclaredVariable -- we return early if there is an issue; otherwise $index and $slug are set in the foreach loop $this->plugins[ $index ] = Plugins_Installer::get_plugin_id_by_slug( $slug ); return true; diff --git a/projects/plugins/jetpack/modules/shortcodes/crowdsignal.php b/projects/plugins/jetpack/modules/shortcodes/crowdsignal.php index df8b3e0b899b6..feab435a29843 100644 --- a/projects/plugins/jetpack/modules/shortcodes/crowdsignal.php +++ b/projects/plugins/jetpack/modules/shortcodes/crowdsignal.php @@ -647,7 +647,7 @@ class_exists( 'Jetpack_AMP_Support' ) 'back_color' => $back_color, 'align' => $attributes['align'], 'style' => $attributes['style'], - 'id' => $survey, + 'id' => $survey ?? null, 'site' => $attributes['site'], ) ); diff --git a/projects/plugins/jetpack/modules/subscriptions.php b/projects/plugins/jetpack/modules/subscriptions.php index c237a5a2445f3..3a1876a626965 100644 --- a/projects/plugins/jetpack/modules/subscriptions.php +++ b/projects/plugins/jetpack/modules/subscriptions.php @@ -566,6 +566,7 @@ public function subscribe( $email, $post_ids = 0, $async = true, $extra_data = a if ( $async ) { XMLRPC_Async_Call::add_call( 'jetpack.subscribeToSite', 0, $email, $post_id, serialize( $extra_data ) ); //phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize } else { + // @phan-suppress-next-line PhanPossiblyUndeclaredVariable -- $xml is set when $async is false $xml->addCall( 'jetpack.subscribeToSite', $email, $post_id, serialize( $extra_data ) ); //phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize } } @@ -575,17 +576,22 @@ public function subscribe( $email, $post_ids = 0, $async = true, $extra_data = a } // Call. + // @phan-suppress-next-line PhanPossiblyUndeclaredVariable -- $xml is set when $async is false, otherwise we return early $xml->query(); + // @phan-suppress-next-line PhanPossiblyUndeclaredVariable -- $xml is set when $async is false, otherwise we return early if ( $xml->isError() ) { + // @phan-suppress-next-line PhanPossiblyUndeclaredVariable -- $xml is set when $async is false, otherwise we return early return $xml->get_jetpack_error(); } + // @phan-suppress-next-line PhanPossiblyUndeclaredVariable -- $xml is set when $async is false $responses = $xml->getResponse(); $r = array(); foreach ( (array) $responses as $response ) { if ( isset( $response['faultCode'] ) || isset( $response['faultString'] ) ) { + // @phan-suppress-next-line PhanPossiblyUndeclaredVariable -- $xml is set when $async is false $r[] = $xml->get_jetpack_error( $response['faultCode'], $response['faultString'] ); continue; } diff --git a/projects/plugins/jetpack/modules/subscriptions/views.php b/projects/plugins/jetpack/modules/subscriptions/views.php index a7a4d2f7905a8..f5b35e9ac42bf 100644 --- a/projects/plugins/jetpack/modules/subscriptions/views.php +++ b/projects/plugins/jetpack/modules/subscriptions/views.php @@ -748,18 +748,6 @@ public function form( $instance ) { $subscribe_logged_in = ! empty( $instance['subscribe_logged_in'] ) ? esc_attr( stripslashes( $instance['subscribe_logged_in'] ) ) : ''; $subscribe_button = ! empty( $instance['subscribe_button'] ) ? esc_attr( stripslashes( $instance['subscribe_button'] ) ) : ''; $subscribers_total = self::fetch_subscriber_count(); - } - - if ( self::is_jetpack() ) { - $title = ! empty( $instance['title'] ) ? stripslashes( $instance['title'] ) : ''; - $subscribe_text = ! empty( $instance['subscribe_text'] ) ? stripslashes( $instance['subscribe_text'] ) : ''; - $subscribe_placeholder = ! empty( $instance['subscribe_placeholder'] ) ? stripslashes( $instance['subscribe_placeholder'] ) : ''; - $subscribe_button = ! empty( $instance['subscribe_button'] ) ? stripslashes( $instance['subscribe_button'] ) : ''; - $success_message = ! empty( $instance['success_message'] ) ? stripslashes( $instance['success_message'] ) : ''; - $subscribers_total = self::fetch_subscriber_count(); - } - - if ( self::is_wpcom() ) : ?>

get_enclosure()->get_link(); break; + default: + $src = ''; + break; } $photos .= '{$type_user_id}; } diff --git a/projects/plugins/jetpack/tests/php/sync/Jetpack_Sync_Full_Immediately_Test.php b/projects/plugins/jetpack/tests/php/sync/Jetpack_Sync_Full_Immediately_Test.php index 038492666780e..1c60933207184 100644 --- a/projects/plugins/jetpack/tests/php/sync/Jetpack_Sync_Full_Immediately_Test.php +++ b/projects/plugins/jetpack/tests/php/sync/Jetpack_Sync_Full_Immediately_Test.php @@ -334,6 +334,7 @@ public function test_full_sync_sends_all_term_relationships_with_previous_interv public function test_full_sync_sends_all_users() { self::factory()->user->create( array( 'role' => 'subscriber' ) ); $first_user_id = self::factory()->user->create( array( 'role' => 'contributor' ) ); + $user_id = 0; // Phan thinks the for loop might not run and thus $user_id might not be declared, so let's initialize it. for ( $i = 0; $i < 9; $i++ ) { $user_id = self::factory()->user->create( array( 'role' => 'contributor' ) ); } @@ -908,6 +909,7 @@ public function test_full_sync_end_sends_range() { public function create_dummy_data_and_reset_sync_status() { // lets create a bunch of posts + $post = 0; // Phan thinks the for loop might not run and thus $post might not be declared, so let's initialize it. for ( $i = 0; $i < $this->test_posts_count; $i++ ) { $post = self::factory()->post->create(); } diff --git a/projects/plugins/jetpack/tests/php/sync/Jetpack_Sync_Full_Test.php b/projects/plugins/jetpack/tests/php/sync/Jetpack_Sync_Full_Test.php index ac225fbcaec42..0e7272511d6c5 100644 --- a/projects/plugins/jetpack/tests/php/sync/Jetpack_Sync_Full_Test.php +++ b/projects/plugins/jetpack/tests/php/sync/Jetpack_Sync_Full_Test.php @@ -467,6 +467,7 @@ public function test_full_sync_sends_all_term_relationships_with_previous_interv public function test_full_sync_sends_all_users() { self::factory()->user->create( array( 'role' => 'subscriber' ) ); $first_user_id = self::factory()->user->create( array( 'role' => 'contributor' ) ); + $user_id = 0; // Phan thinks the for loop might not run and thus $user_id might not be declared, so let's initialize it. for ( $i = 0; $i < 9; $i++ ) { $user_id = self::factory()->user->create( array( 'role' => 'contributor' ) ); } @@ -1157,6 +1158,7 @@ public function record_full_sync_start_config( $modules ) { public function create_dummy_data_and_empty_the_queue() { // lets create a bunch of posts + $post = 0; // Phan thinks the for loop might not run and thus $post might not be declared, so let's initialize it. for ( $i = 0; $i < $this->test_posts_count; $i++ ) { $post = self::factory()->post->create(); } diff --git a/projects/plugins/vaultpress/.phan/baseline.php b/projects/plugins/vaultpress/.phan/baseline.php index cf843d6b9c5fc..d4fc63890e137 100644 --- a/projects/plugins/vaultpress/.phan/baseline.php +++ b/projects/plugins/vaultpress/.phan/baseline.php @@ -11,16 +11,14 @@ // # Issue statistics: // PhanUndeclaredClassMethod : 15+ occurrences // PhanPluginSimplifyExpressionBool : 8 occurrences - // PhanTypeMismatchArgumentNullableInternal : 8 occurrences // PhanUndeclaredConstant : 8 occurrences // PhanTypeMismatchArgument : 7 occurrences - // PhanPossiblyUndeclaredVariable : 6 occurrences + // PhanTypeMismatchArgumentNullableInternal : 6 occurrences // PhanTypePossiblyInvalidDimOffset : 6 occurrences // PhanPluginUnreachableCode : 5 occurrences // PhanTypeArraySuspiciousNullable : 5 occurrences // PhanTypeMismatchArgumentProbablyReal : 5 occurrences // PhanPluginDuplicateConditionalNullCoalescing : 4 occurrences - // PhanUndeclaredVariableDim : 4 occurrences // PhanCommentParamWithoutRealParam : 3 occurrences // PhanTypeMismatchDimFetch : 3 occurrences // PhanUndeclaredFunction : 3 occurrences @@ -33,7 +31,6 @@ // PhanUndeclaredMethod : 2 occurrences // PhanUndeclaredVariable : 2 occurrences // PhanAccessMethodProtected : 1 occurrence - // PhanParamSpecial1 : 1 occurrence // PhanPluginDuplicateExpressionAssignment : 1 occurrence // PhanTypeInvalidRightOperandOfNumericOp : 1 occurrence // PhanTypeMismatchArgumentInternal : 1 occurrence @@ -42,12 +39,12 @@ // Currently, file_suppressions and directory_suppressions are the only supported suppressions 'file_suppressions' => [ - 'class.vaultpress-database.php' => ['PhanParamSpecial1', 'PhanPluginDuplicateConditionalNullCoalescing', 'PhanPossiblyUndeclaredVariable', 'PhanTypeArraySuspiciousNullable', 'PhanTypeMismatchArgumentInternal', 'PhanTypeMismatchArgumentNullableInternal', 'PhanTypeNonVarPassByRef', 'PhanTypeObjectUnsetDeclaredProperty', 'PhanUndeclaredConstant', 'PhanUndeclaredVariableDim'], - 'class.vaultpress-filesystem.php' => ['PhanPluginNeverReturnMethod', 'PhanPluginSimplifyExpressionBool', 'PhanPluginUnreachableCode', 'PhanPossiblyUndeclaredVariable', 'PhanTypeMismatchArgumentNullableInternal', 'PhanTypeNonVarPassByRef', 'PhanTypeSuspiciousStringExpression', 'PhanUndeclaredVariable'], + 'class.vaultpress-database.php' => ['PhanPluginDuplicateConditionalNullCoalescing', 'PhanTypeArraySuspiciousNullable', 'PhanTypeMismatchArgumentInternal', 'PhanTypeNonVarPassByRef', 'PhanTypeObjectUnsetDeclaredProperty', 'PhanUndeclaredConstant'], + 'class.vaultpress-filesystem.php' => ['PhanPluginNeverReturnMethod', 'PhanPluginSimplifyExpressionBool', 'PhanPluginUnreachableCode', 'PhanTypeMismatchArgumentNullableInternal', 'PhanTypeNonVarPassByRef', 'PhanTypeSuspiciousStringExpression', 'PhanUndeclaredVariable'], 'class.vaultpress-hotfixes.php' => ['PhanDeprecatedFunction', 'PhanPluginSimplifyExpressionBool', 'PhanRedefineFunction', 'PhanTypeMismatchArgumentNullableInternal', 'PhanTypePossiblyInvalidDimOffset'], 'cron-tasks.php' => ['PhanRedefineFunction'], - 'vaultpress.php' => ['PhanAccessMethodProtected', 'PhanDeprecatedFunction', 'PhanPluginDuplicateConditionalNullCoalescing', 'PhanPluginDuplicateExpressionAssignment', 'PhanPluginNeverReturnMethod', 'PhanPluginSimplifyExpressionBool', 'PhanPluginUnreachableCode', 'PhanPossiblyUndeclaredVariable', 'PhanTypeArraySuspiciousNullable', 'PhanTypeExpectedObjectPropAccessButGotNull', 'PhanTypeInvalidRightOperandOfNumericOp', 'PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentNullableInternal', 'PhanTypeMismatchArgumentProbablyReal', 'PhanTypeMismatchDimFetch', 'PhanTypePossiblyInvalidDimOffset', 'PhanTypeSuspiciousStringExpression', 'PhanUndeclaredClassMethod', 'PhanUndeclaredClassReference', 'PhanUndeclaredConstant', 'PhanUndeclaredFunction', 'PhanUndeclaredMethod', 'PhanUndeclaredVariable'], - 'vp-scanner.php' => ['PhanCommentParamWithoutRealParam', 'PhanPossiblyUndeclaredVariable', 'PhanTypeMismatchArgumentNullableInternal', 'PhanUndeclaredFunction'], + 'vaultpress.php' => ['PhanAccessMethodProtected', 'PhanDeprecatedFunction', 'PhanPluginDuplicateConditionalNullCoalescing', 'PhanPluginDuplicateExpressionAssignment', 'PhanPluginNeverReturnMethod', 'PhanPluginSimplifyExpressionBool', 'PhanPluginUnreachableCode', 'PhanTypeArraySuspiciousNullable', 'PhanTypeExpectedObjectPropAccessButGotNull', 'PhanTypeInvalidRightOperandOfNumericOp', 'PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentNullableInternal', 'PhanTypeMismatchArgumentProbablyReal', 'PhanTypeMismatchDimFetch', 'PhanTypePossiblyInvalidDimOffset', 'PhanTypeSuspiciousStringExpression', 'PhanUndeclaredClassMethod', 'PhanUndeclaredClassReference', 'PhanUndeclaredConstant', 'PhanUndeclaredFunction', 'PhanUndeclaredMethod', 'PhanUndeclaredVariable'], + 'vp-scanner.php' => ['PhanCommentParamWithoutRealParam', 'PhanTypeMismatchArgumentNullableInternal', 'PhanUndeclaredFunction'], ], // 'directory_suppressions' => ['src/directory_name' => ['PhanIssueName1', 'PhanIssueName2']] can be manually added if needed. // (directory_suppressions will currently be ignored by subsequent calls to --save-baseline, but may be preserved in future Phan releases) diff --git a/projects/plugins/vaultpress/changelog/fix-phan-PhanPossiblyUndeclaredVariable b/projects/plugins/vaultpress/changelog/fix-phan-PhanPossiblyUndeclaredVariable new file mode 100644 index 0000000000000..473f10d2c7859 --- /dev/null +++ b/projects/plugins/vaultpress/changelog/fix-phan-PhanPossiblyUndeclaredVariable @@ -0,0 +1,4 @@ +Significance: patch +Type: fixed + +Phan: Address PhanPossiblyUndeclaredVariable violations. diff --git a/projects/plugins/vaultpress/class.vaultpress-database.php b/projects/plugins/vaultpress/class.vaultpress-database.php index df7b9528083f3..41a993a15555b 100644 --- a/projects/plugins/vaultpress/class.vaultpress-database.php +++ b/projects/plugins/vaultpress/class.vaultpress-database.php @@ -169,6 +169,9 @@ function convert_to_sql_string( $data, $datatypes ) { if ( !is_object( $data ) || !is_object( $datatypes ) ) return false; + $keys = array(); + $vals = array(); + foreach ( array_keys( (array)$data ) as $key ) $keys[] = sprintf( "`%s`", esc_sql( $key ) ); foreach ( (array)$data as $key => $val ) { diff --git a/projects/plugins/vaultpress/class.vaultpress-filesystem.php b/projects/plugins/vaultpress/class.vaultpress-filesystem.php index 6422fcf481b02..12a9e22bd0a6f 100644 --- a/projects/plugins/vaultpress/class.vaultpress-filesystem.php +++ b/projects/plugins/vaultpress/class.vaultpress-filesystem.php @@ -75,10 +75,13 @@ function exec_checksum( $file, $method ) { if ( !function_exists( 'exec' ) ) return false; $out = array(); - if ( 'md5' == $method ) + if ( 'md5' === $method ) { $method_bin = 'md5sum'; - if ( 'sha1' == $method ) + } elseif ( 'sha1' === $method ) { $method_bin = 'sha1sum'; + } else { + return false; + } $checksum = ''; exec( sprintf( '%s %s', escapeshellcmd( $method_bin ), escapeshellarg( $file ) ), $out ); if ( !empty( $out ) ) diff --git a/projects/plugins/vaultpress/vaultpress.php b/projects/plugins/vaultpress/vaultpress.php index 06526da788dbc..4dc080f8edeb6 100644 --- a/projects/plugins/vaultpress/vaultpress.php +++ b/projects/plugins/vaultpress/vaultpress.php @@ -1016,8 +1016,8 @@ function ui_delete_vp_settings_button() { function ui_logo() { if ( ! class_exists( 'Jetpack_Logo' ) ) { require_once VAULTPRESS__PLUGIN_DIR . 'class-jetpack-logo.php'; - $jetpack_logo = new Jetpack_Logo(); } + $jetpack_logo = new Jetpack_Logo(); return $jetpack_logo->output(); } diff --git a/projects/plugins/vaultpress/vp-scanner.php b/projects/plugins/vaultpress/vp-scanner.php index a71f56ce5bdef..6f800fbfb4cab 100644 --- a/projects/plugins/vaultpress/vp-scanner.php +++ b/projects/plugins/vaultpress/vp-scanner.php @@ -65,7 +65,7 @@ function _scan_files( $path, &$files, $offset, $limit, &$last_dir ) { } if ( count( $files ) >= $limit ) { closedir( $handle ); - return array( $_return_offset, $_return_dir ); + return array( $_return_offset ?? 0, $_return_dir ?? null ); } } closedir( $handle ); diff --git a/projects/plugins/wpcomsh/.phan/baseline.php b/projects/plugins/wpcomsh/.phan/baseline.php index f80a933b70c5d..c03ac9158a81c 100644 --- a/projects/plugins/wpcomsh/.phan/baseline.php +++ b/projects/plugins/wpcomsh/.phan/baseline.php @@ -22,7 +22,6 @@ // PhanDeprecatedFunction : 1 occurrence // PhanDeprecatedProperty : 1 occurrence // PhanPluginUseReturnValueInternalKnown : 1 occurrence - // PhanPossiblyUndeclaredVariable : 1 occurrence // PhanTypeObjectUnsetDeclaredProperty : 1 occurrence // PhanUndeclaredClassConstant : 1 occurrence // PhanUndeclaredClassStaticProperty : 1 occurrence @@ -41,7 +40,7 @@ 'footer-credit/theme-optimizations.php' => ['PhanUndeclaredConstant', 'PhanUndeclaredStaticMethod'], 'functions.php' => ['PhanUndeclaredClassStaticProperty'], 'imports/playground/class-sql-importer.php' => ['PhanUndeclaredConstant'], - 'safeguard/utils.php' => ['PhanPossiblyUndeclaredVariable', 'PhanTypeMismatchArgument'], + 'safeguard/utils.php' => ['PhanTypeMismatchArgument'], 'tests/AnyoneCanRegisterNoticeTest.php' => ['PhanTypeMismatchArgument', 'PhanTypeVoidArgument', 'PhanTypeVoidAssignment'], 'tests/FrontendNoticesTest.php' => ['PhanUndeclaredStaticMethod'], 'tests/PlanNoticesTest.php' => ['PhanDeprecatedProperty', 'PhanPluginUseReturnValueInternalKnown', 'PhanUndeclaredStaticMethod'], diff --git a/projects/plugins/wpcomsh/changelog/fix-phan-PhanPossiblyUndeclaredVariable b/projects/plugins/wpcomsh/changelog/fix-phan-PhanPossiblyUndeclaredVariable new file mode 100644 index 0000000000000..473f10d2c7859 --- /dev/null +++ b/projects/plugins/wpcomsh/changelog/fix-phan-PhanPossiblyUndeclaredVariable @@ -0,0 +1,4 @@ +Significance: patch +Type: fixed + +Phan: Address PhanPossiblyUndeclaredVariable violations. diff --git a/projects/plugins/wpcomsh/safeguard/utils.php b/projects/plugins/wpcomsh/safeguard/utils.php index b2d0e77f99443..d2337c8d35410 100644 --- a/projects/plugins/wpcomsh/safeguard/utils.php +++ b/projects/plugins/wpcomsh/safeguard/utils.php @@ -198,6 +198,7 @@ function get_plugin_data_from_package( $package ) { return new WP_Error( 'process_package_fails', 'Invalid plugin file.' ); } + $plugin_folder = false; $tmp_plugin_folder = uncompress_package( $package ); if ( is_wp_error( $tmp_plugin_folder ) ) { return $tmp_plugin_folder;