Skip to content

Commit

Permalink
Updating phan baselines and suppressing or fixing Phan issues where n…
Browse files Browse the repository at this point in the history
…eeded or possible
  • Loading branch information
coder-karen committed Aug 29, 2024
1 parent a173eed commit ae357be
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 29 deletions.
7 changes: 5 additions & 2 deletions projects/packages/classic-theme-helper/.phan/baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@
return [
// # Issue statistics:
// PhanTypeMismatchArgumentInternal : 10+ occurrences
// PhanUndeclaredClassMethod : 9 occurrences
// PhanTypePossiblyInvalidDimOffset : 8 occurrences
// PhanUndeclaredClassMethod : 7 occurrences
// PhanUndeclaredClassReference : 4 occurrences
// PhanTypeMismatchArgumentProbablyReal : 3 occurrences
// PhanTypeSuspiciousNonTraversableForeach : 3 occurrences
// PhanTypeInvalidDimOffset : 2 occurrences
// PhanTypeMismatchArgument : 2 occurrences
// PhanTypeComparisonToArray : 1 occurrence
// PhanTypeMismatchArgumentProbablyReal : 1 occurrence
// PhanTypeMismatchProperty : 1 occurrence
// PhanUndeclaredTypeProperty : 1 occurrence

Expand All @@ -26,6 +27,8 @@
'src/class-featured-content.php' => ['PhanTypeComparisonToArray', 'PhanTypeInvalidDimOffset', 'PhanTypeMismatchArgument', 'PhanTypeMismatchProperty', 'PhanTypePossiblyInvalidDimOffset'],
'src/class-social-links.php' => ['PhanUndeclaredClassMethod', 'PhanUndeclaredClassReference', 'PhanUndeclaredTypeProperty'],
'src/content-options/featured-images-fallback.php' => ['PhanTypePossiblyInvalidDimOffset'],
'src/custom-content-types.php' => ['PhanUndeclaredClassMethod'],
'src/custom-post-types/class-jetpack-portfolio.php' => ['PhanTypeMismatchArgumentProbablyReal', 'PhanTypeSuspiciousNonTraversableForeach'],
],
// '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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ function jetpack_load_custom_post_types() {
* Make module configurable.
*/
function jetpack_custom_post_types_loaded() {
Jetpack::enable_module_configurable( __FILE__ );
if ( class_exists( 'Jetpack' ) ) {
Jetpack::enable_module_configurable( __FILE__ );
}
}
add_action( 'jetpack_modules_loaded', 'jetpack_custom_post_types_loaded' );
}
Expand All @@ -58,12 +60,14 @@ function jetpack_cpt_settings_api_init() {
* Settings Description
*/
function jetpack_cpt_section_callback() {
?>
<p>
<?php esc_html_e( 'Use these settings to display different types of content on your site.', 'jetpack-classic-theme-helper' ); ?>
<a target="_blank" rel="noopener noreferrer" href="<?php echo esc_url( Redirect::get_url( 'jetpack-support-custom-content-types' ) ); ?>"><?php esc_html_e( 'Learn More', 'jetpack-classic-theme-helper' ); ?></a>
</p>
<?php
if ( class_exists( 'Redirect' ) ) {
?>
<p>
<?php esc_html_e( 'Use these settings to display different types of content on your site.', 'jetpack-classic-theme-helper' ); ?>
<a target="_blank" rel="noopener noreferrer" href="<?php echo esc_url( Redirect::get_url( 'jetpack-support-custom-content-types' ) ); ?>"><?php esc_html_e( 'Learn More', 'jetpack-classic-theme-helper' ); ?></a>
</p>
<?php
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
namespace Automattic\Jetpack\Classic_Theme_Helper;

use Jetpack_Options;
use WP_Customize_Image_Control;
use WP_Customize_Manager;
use WP_Query;

if ( ! class_exists( __NAMESPACE__ . '\Jetpack_Portfolio' ) ) {
Expand Down Expand Up @@ -68,7 +70,7 @@ public function maybe_register_cpt() {
if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
$setting = get_option( self::OPTION_NAME, '0' );
} else {
$setting = Jetpack_Options::get_option_and_ensure_autoload( self::OPTION_NAME, '0' );
$setting = class_exists( 'Jetpack_Options' ) ? Jetpack_Options::get_option_and_ensure_autoload( self::OPTION_NAME, '0' ) : '0'; // @phan-suppress-current-line PhanUndeclaredClassMethod -- We check if the class exists first.
}

// Bail early if Portfolio option is not set and the theme doesn't declare support.
Expand Down Expand Up @@ -208,7 +210,9 @@ public function setting_html() {
* Bump Portfolio > New Activation stat.
*/
public function new_activation_stat_bump() {
bump_stats_extras( 'portfolios', 'new-activation' );
if ( function_exists( 'bump_stats_extras' ) ) {
bump_stats_extras( 'portfolios', 'new-activation' ); // @phan-suppress-current-line PhanUndeclaredFunction -- only calling if it exists.
}
}

/**
Expand All @@ -219,19 +223,28 @@ public function new_activation_stat_bump() {
*/
public function update_option_stat_bump( $old, $new ) {
if ( empty( $old ) && ! empty( $new ) ) {
bump_stats_extras( 'portfolios', 'option-on' );
if ( function_exists( 'bump_stats_extras' ) ) {

bump_stats_extras( 'portfolios', 'option-on' ); // @phan-suppress-current-line PhanUndeclaredFunction -- only calling if it exists.
}
}

if ( ! empty( $old ) && empty( $new ) ) {
bump_stats_extras( 'portfolios', 'option-off' );
if ( function_exists( 'bump_stats_extras' ) ) {

bump_stats_extras( 'portfolios', 'option-off' ); // @phan-suppress-current-line PhanUndeclaredFunction -- only calling if it exists.
}
}
}

/**
* Bump Portfolio > Published Projects stat when projects are published.
*/
public function new_project_stat_bump() {
bump_stats_extras( 'portfolios', 'published-projects' );
if ( function_exists( 'bump_stats_extras' ) ) {

bump_stats_extras( 'portfolios', 'published-projects' ); // @phan-suppress-current-line PhanUndeclaredFunction -- only calling if it exists.
}
}

/**
Expand Down Expand Up @@ -1025,7 +1038,7 @@ private static function get_project_type( $post_id ) {

// If no types, return empty string.
if ( empty( $project_types ) || is_wp_error( $project_types ) ) {
return;
return '';
}

$html = '<div class="project-types"><span>' . __( 'Types:', 'jetpack-classic-theme-helper' ) . '</span>';
Expand Down Expand Up @@ -1058,7 +1071,7 @@ private static function get_project_tags( $post_id ) {

// If no tags, return empty string.
if ( empty( $project_tags ) || is_wp_error( $project_tags ) ) {
return false;
return '';
}

$html = '<div class="project-tags"><span>' . __( 'Tags:', 'jetpack-classic-theme-helper' ) . '</span>';
Expand Down Expand Up @@ -1089,7 +1102,7 @@ private static function get_project_author() {
$html .= sprintf(
/* translators: %1$s is link to author posts, %2$s is author display name */
__( '<span>Author:</span> <a href="%1$s">%2$s</a>', 'jetpack-classic-theme-helper' ),
esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
esc_url( get_author_posts_url( (int) get_the_author_meta( 'ID' ) ) ),
esc_html( get_the_author() )
);
$html .= '</div>';
Expand Down
19 changes: 7 additions & 12 deletions projects/plugins/jetpack/.phan/baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,32 @@
// PhanRedundantCondition : 70+ occurrences
// PhanPossiblyUndeclaredVariable : 60+ occurrences
// PhanTypeArraySuspiciousNullable : 60+ occurrences
// PhanRedefineFunction : 50+ occurrences
// PhanRedefineFunction : 55+ occurrences
// PhanTypeMismatchArgumentNullable : 50+ occurrences
// PhanTypeExpectedObjectPropAccess : 45+ occurrences
// PhanParamTooMany : 40+ occurrences
// PhanPluginDuplicateAdjacentStatement : 40+ occurrences
// PhanTypeExpectedObjectPropAccess : 40+ occurrences
// PhanTypeMismatchArgumentInternal : 40+ occurrences
// PhanUndeclaredProperty : 35+ occurrences
// PhanParamSignatureMismatch : 25+ occurrences
// PhanPluginSimplifyExpressionBool : 25+ occurrences
// PhanTypeMismatchDefault : 25+ occurrences
// PhanTypeMismatchPropertyProbablyReal : 25+ occurrences
// PhanTypeMissingReturn : 25+ occurrences
// PhanTypeSuspiciousNonTraversableForeach : 25+ occurrences
// PhanDeprecatedProperty : 20+ occurrences
// PhanPluginSimplifyExpressionBool : 20+ occurrences
// PhanTypeArraySuspicious : 20+ occurrences
// PhanTypeMismatchDimFetch : 20+ occurrences
// PhanPluginMixedKeyNoKey : 15+ occurrences
// PhanSuspiciousMagicConstant : 15+ occurrences
// PhanTypeExpectedObjectPropAccessButGotNull : 15+ occurrences
// PhanTypeMismatchArgumentNullableInternal : 15+ occurrences
// PhanTypeMismatchPropertyDefault : 15+ occurrences
// PhanUndeclaredMethod : 15+ occurrences
// PhanPluginDuplicateExpressionAssignmentOperation : 10+ occurrences
// PhanRedefineClass : 10+ occurrences
// PhanRedundantConditionInLoop : 10+ occurrences
// PhanTypeInvalidDimOffset : 10+ occurrences
// PhanTypeMismatchArgumentNullableInternal : 10+ occurrences
// PhanTypeMismatchProperty : 10+ occurrences
// PhanTypeMismatchReturnNullable : 10+ occurrences
// PhanUndeclaredFunction : 10+ occurrences
Expand All @@ -56,12 +56,12 @@
// PhanTypeMismatchArgumentInternalReal : 7 occurrences
// PhanCommentAbstractOnInheritedMethod : 6 occurrences
// PhanDeprecatedClass : 5 occurrences
// PhanImpossibleCondition : 5 occurrences
// PhanNonClassMethodCall : 5 occurrences
// PhanTypeArraySuspiciousNull : 5 occurrences
// PhanTypeMismatchDimAssignment : 5 occurrences
// PhanTypeSuspiciousStringExpression : 5 occurrences
// PhanAccessMethodInternal : 4 occurrences
// PhanImpossibleCondition : 4 occurrences
// PhanTypeInvalidLeftOperandOfAdd : 4 occurrences
// PhanTypeInvalidLeftOperandOfBitwiseOp : 4 occurrences
// PhanTypeInvalidRightOperandOfBitwiseOp : 4 occurrences
Expand All @@ -71,29 +71,23 @@
// PhanImpossibleTypeComparison : 3 occurrences
// PhanPluginUnreachableCode : 3 occurrences
// PhanStaticPropIsStaticType : 3 occurrences
// PhanTypeConversionFromArray : 3 occurrences
// PhanTypeMismatchArgumentReal : 3 occurrences
// PhanTypeObjectUnsetDeclaredProperty : 3 occurrences
// PhanUndeclaredMethodInCallable : 3 occurrences
// PhanCompatibleNegativeStringOffset : 2 occurrences
// PhanImpossibleConditionInLoop : 2 occurrences
// PhanParamTooManyCallable : 2 occurrences
// PhanPluginDuplicateSwitchCaseLooseEquality : 2 occurrences
// PhanRedefineFunctionInternal : 2 occurrences
// PhanStaticCallToNonStatic : 2 occurrences
// PhanTypeMismatchArgumentInternalProbablyReal : 2 occurrences
// PhanUndeclaredClassInCallable : 2 occurrences
// PhanUndeclaredClassMethod : 2 occurrences
// PhanDeprecatedPartiallySupportedCallable : 1 occurrence
// PhanEmptyFQSENInCallable : 1 occurrence
// PhanEmptyForeach : 1 occurrence
// PhanInfiniteRecursion : 1 occurrence
// PhanPluginDuplicateSwitchCase : 1 occurrence
// PhanPluginInvalidPregRegex : 1 occurrence
// PhanPluginRedundantAssignmentInLoop : 1 occurrence
// PhanPluginUseReturnValueInternalKnown : 1 occurrence
// PhanTypeComparisonFromArray : 1 occurrence
// PhanTypeInvalidRightOperandOfNumericOp : 1 occurrence
// PhanTypeConversionFromArray : 1 occurrence
// PhanTypeVoidArgument : 1 occurrence
// PhanUndeclaredConstant : 1 occurrence
// PhanUndeclaredExtendedClass : 1 occurrence
Expand Down Expand Up @@ -329,6 +323,7 @@
'modules/comments/comments.php' => ['PhanPluginDuplicateConditionalNullCoalescing', 'PhanRedundantCondition', 'PhanTypeExpectedObjectPropAccess', 'PhanTypeMismatchArgument', 'PhanUndeclaredFunction'],
'modules/comments/subscription-modal-on-comment/class-jetpack-subscription-modal-on-comment.php' => ['PhanTypeMismatchReturnNullable'],
'modules/copy-post.php' => ['PhanNoopNew'],
'modules/custom-content-types.php' => ['PhanRedefineFunction'],
'modules/custom-post-types/nova.php' => ['PhanTypeExpectedObjectPropAccess', 'PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentNullable', 'PhanTypeMismatchArgumentProbablyReal', 'PhanTypeSuspiciousNonTraversableForeach'],
'modules/custom-post-types/portfolios.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentProbablyReal', 'PhanTypeMismatchReturn', 'PhanTypeMismatchReturnProbablyReal', 'PhanTypeSuspiciousNonTraversableForeach'],
'modules/custom-post-types/testimonial.php' => ['PhanTypeMismatchArgumentProbablyReal'],
Expand Down

0 comments on commit ae357be

Please sign in to comment.