From 236ac361ba37334119adc03febe752a8aa9682ce Mon Sep 17 00:00:00 2001 From: Brad Jorsch Date: Wed, 17 Apr 2024 12:01:14 -0400 Subject: [PATCH] phan: Add stubs for the WordPress.com Editing Toolkit plugin (#36957) A few functions from this plugin are called from Jetpack and the jetpack-mu-wpcom package. --- .phan/config.base.php | 4 ++ .phan/stubs/full-site-editing-stubs.php | 55 +++++++++++++++++++ .../jetpack-mu-wpcom/.phan/baseline.php | 2 +- .../jetpack-mu-wpcom/.phan/config.php | 1 + .../add-phan-full-site-editing-stubs | 5 ++ projects/plugins/jetpack/.phan/baseline.php | 5 +- projects/plugins/jetpack/.phan/config.php | 2 +- .../add-phan-full-site-editing-stubs | 5 ++ tools/stubs/full-site-editing-stub-defs.php | 39 +++++++++++++ tools/stubs/update-stubs.sh | 8 +++ 10 files changed, 121 insertions(+), 5 deletions(-) create mode 100644 .phan/stubs/full-site-editing-stubs.php create mode 100644 projects/packages/jetpack-mu-wpcom/changelog/add-phan-full-site-editing-stubs create mode 100644 projects/plugins/jetpack/changelog/add-phan-full-site-editing-stubs create mode 100644 tools/stubs/full-site-editing-stub-defs.php diff --git a/.phan/config.base.php b/.phan/config.base.php index 03877889445fe..561d3191971c4 100644 --- a/.phan/config.base.php +++ b/.phan/config.base.php @@ -23,6 +23,7 @@ * - parse_file_list: (array) Files to parse but not analyze. Equivalent to listing in both 'file_list' and 'exclude_analysis_directory_list'. * - stubs: (array) Predefined stubs to load. Default is `array( 'wordpress', 'wp-cli', 'wpcom' )`. * - akismet: Stubs from .phan/stubs/akismet-stubs.php. + * - full-site-editing: Stubs from .phan/stubs/full-site-editing-stubs.php. * - woocommerce: Stubs from php-stubs/woocommerce. * - woocommerce-internal: Stubs from .phan/stubs/woocommerce-internal-stubs.php. * - woocommerce-packages: Stubs from php-stubs/woocommerce. @@ -57,6 +58,9 @@ function make_phan_config( $dir, $options = array() ) { case 'akismet': $stubs[] = "$root/.phan/stubs/akismet-stubs.php"; break; + case 'full-site-editing': + $stubs[] = "$root/.phan/stubs/full-site-editing-stubs.php"; + break; case 'woocommerce': $stubs[] = "$root/vendor/php-stubs/woocommerce-stubs/woocommerce-stubs.php"; break; diff --git a/.phan/stubs/full-site-editing-stubs.php b/.phan/stubs/full-site-editing-stubs.php new file mode 100644 index 0000000000000..c480491d2922f --- /dev/null +++ b/.phan/stubs/full-site-editing-stubs.php @@ -0,0 +1,55 @@ + array( 'full-site-editing' ), 'parse_file_list' => array( "$root/projects/packages/stats-admin/src/class-dashboard.php", "$root/projects/plugins/jetpack/class-jetpack-stats-dashboard-widget.php", diff --git a/projects/packages/jetpack-mu-wpcom/changelog/add-phan-full-site-editing-stubs b/projects/packages/jetpack-mu-wpcom/changelog/add-phan-full-site-editing-stubs new file mode 100644 index 0000000000000..91dcca637d2e1 --- /dev/null +++ b/projects/packages/jetpack-mu-wpcom/changelog/add-phan-full-site-editing-stubs @@ -0,0 +1,5 @@ +Significance: patch +Type: added +Comment: Update Phan config to use new WordPress.com Editing Toolkit stubs. No change to functionality. + + diff --git a/projects/plugins/jetpack/.phan/baseline.php b/projects/plugins/jetpack/.phan/baseline.php index 0bbd7a3766a7a..992cb51900810 100644 --- a/projects/plugins/jetpack/.phan/baseline.php +++ b/projects/plugins/jetpack/.phan/baseline.php @@ -59,7 +59,6 @@ // PhanTypeInvalidLeftOperandOfNumericOp : 10+ occurrences // PhanTypeMismatchReturnNullable : 10+ occurrences // PhanUndeclaredClassProperty : 10+ occurrences - // PhanUndeclaredClassReference : 10+ occurrences // PhanUndeclaredConstant : 10+ occurrences // PhanUndeclaredTypeReturnType : 10+ occurrences // PhanCommentParamWithoutRealParam : 9 occurrences @@ -72,6 +71,7 @@ // PhanTypeMismatchArgumentInternalReal : 7 occurrences // PhanUndeclaredTypeParameter : 7 occurrences // PhanCommentAbstractOnInheritedMethod : 6 occurrences + // PhanUndeclaredClassReference : 6 occurrences // PhanUndeclaredTypeProperty : 6 occurrences // PhanUndeclaredVariableDim : 6 occurrences // PhanUnextractableAnnotationElementName : 6 occurrences @@ -89,7 +89,6 @@ // PhanTypeInvalidRightOperandOfBitwiseOp : 4 occurrences // PhanTypeInvalidRightOperandOfNumericOp : 4 occurrences // PhanUndeclaredClassInCallable : 4 occurrences - // PhanUndeclaredClassReference : 4 occurrences // PhanDeprecatedFunctionInternal : 3 occurrences // PhanDeprecatedTrait : 3 occurrences // PhanTypeConversionFromArray : 3 occurrences @@ -588,7 +587,7 @@ 'sal/class.json-api-post-base.php' => ['PhanPluginDuplicateConditionalNullCoalescing', 'PhanRedundantCondition', 'PhanTypeMismatchArgument', 'PhanTypeMismatchReturnNullable', 'PhanTypeMismatchReturnProbablyReal', 'PhanTypePossiblyInvalidDimOffset', 'PhanTypeSuspiciousNonTraversableForeach', 'PhanUndeclaredFunction'], 'sal/class.json-api-site-base.php' => ['PhanParamTooMany', 'PhanRedundantCondition', 'PhanTypeMismatchArgument', 'PhanTypeMismatchReturnProbablyReal', 'PhanUndeclaredFunction'], 'sal/class.json-api-site-jetpack-base.php' => ['PhanRedundantCondition', 'PhanTypeMismatchReturnProbablyReal'], - 'sal/class.json-api-site-jetpack.php' => ['PhanParamSignatureMismatch', 'PhanUndeclaredFunction'], + 'sal/class.json-api-site-jetpack.php' => ['PhanParamSignatureMismatch'], 'sal/class.json-api-token.php' => ['PhanPluginDuplicateConditionalNullCoalescing', 'PhanSuspiciousValueComparison', 'PhanTypeMismatchArgumentProbablyReal', 'PhanTypeMismatchReturn', 'PhanUndeclaredVariable'], 'src/class-jetpack-crm-data.php' => ['PhanUndeclaredFunction'], 'src/class-jetpack-modules-overrides.php' => ['PhanRedundantCondition'], diff --git a/projects/plugins/jetpack/.phan/config.php b/projects/plugins/jetpack/.phan/config.php index f09801d4089cb..27b909e3b8cf8 100644 --- a/projects/plugins/jetpack/.phan/config.php +++ b/projects/plugins/jetpack/.phan/config.php @@ -13,7 +13,7 @@ return make_phan_config( dirname( __DIR__ ), array( - '+stubs' => array( 'akismet', 'woocommerce', 'woocommerce-internal', 'woocommerce-packages' ), + '+stubs' => array( 'akismet', 'full-site-editing', 'woocommerce', 'woocommerce-internal', 'woocommerce-packages' ), 'exclude_file_list' => array( // Mocks of core classes. 'tests/php/_inc/lib/mocks/class-simplepie-file.php', diff --git a/projects/plugins/jetpack/changelog/add-phan-full-site-editing-stubs b/projects/plugins/jetpack/changelog/add-phan-full-site-editing-stubs new file mode 100644 index 0000000000000..67a1a71418be2 --- /dev/null +++ b/projects/plugins/jetpack/changelog/add-phan-full-site-editing-stubs @@ -0,0 +1,5 @@ +Significance: patch +Type: other +Comment: Update Phan config to use new WordPress.com Editing Toolkit stubs. No change to functionality. + + diff --git a/tools/stubs/full-site-editing-stub-defs.php b/tools/stubs/full-site-editing-stub-defs.php new file mode 100644 index 0000000000000..07841d8c041d2 --- /dev/null +++ b/tools/stubs/full-site-editing-stub-defs.php @@ -0,0 +1,39 @@ + << "$work_dir/full-site-editing/", + 'files' => array( + 'wpcom-global-styles/index.php' => array( + 'function' => array( 'wpcom_global_styles_in_use', 'wpcom_should_limit_global_styles' ), + ), + 'dotcom-fse/helpers.php' => array( + 'function' => array( 'A8C\FSE\is_full_site_editing_active', 'A8C\FSE\is_site_eligible_for_full_site_editing' ), + ), + ), +); diff --git a/tools/stubs/update-stubs.sh b/tools/stubs/update-stubs.sh index 54503b314dd4c..2aa5a9cee421f 100755 --- a/tools/stubs/update-stubs.sh +++ b/tools/stubs/update-stubs.sh @@ -81,6 +81,14 @@ echo info 'Extracting Akismet stubs' "$BASE/projects/packages/stub-generator/bin/jetpack-stub-generator" --output "$BASE/.phan/stubs/akismet-stubs.php" "$BASE/tools/stubs/akismet-stub-defs.php" +echo +info 'Downloading WordPress.com Editing Toolkit' +fetch_plugin full-site-editing + +echo +info 'Extracting WordPress.com Editing Toolkit stubs' +"$BASE/projects/packages/stub-generator/bin/jetpack-stub-generator" --output "$BASE/.phan/stubs/full-site-editing-stubs.php" "$BASE/tools/stubs/full-site-editing-stub-defs.php" + echo info 'Downloading WooCommerce' fetch_repo woocommerce/woocommerce