Skip to content

Commit

Permalink
phan: Add stubs for AMP and AMP for WP plugins (#37005)
Browse files Browse the repository at this point in the history
There's only one function specific to AMP for WP that we need, and it
seems unlikely anyone will want only that one stub and not any AMP
stubs, so let's combine them into one file.
  • Loading branch information
anomiex authored Apr 22, 2024
1 parent e9f0d96 commit 2e7b50a
Show file tree
Hide file tree
Showing 27 changed files with 291 additions and 29 deletions.
4 changes: 4 additions & 0 deletions .phan/config.base.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' )`.
* - akismet: Stubs from .phan/stubs/akismet-stubs.php.
* - amp: Stubs from .phan/stubs/amp-stubs.php.
* - full-site-editing: Stubs from .phan/stubs/full-site-editing-stubs.php.
* - photon-opencv: Stubs from .phan/stubs/photon-opencv-stubs.php.
* - woocommerce: Stubs from php-stubs/woocommerce.
Expand Down Expand Up @@ -59,6 +60,9 @@ function make_phan_config( $dir, $options = array() ) {
case 'akismet':
$stubs[] = "$root/.phan/stubs/akismet-stubs.php";
break;
case 'amp':
$stubs[] = "$root/.phan/stubs/amp-stubs.php";
break;
case 'full-site-editing':
$stubs[] = "$root/.phan/stubs/full-site-editing-stubs.php";
break;
Expand Down
152 changes: 152 additions & 0 deletions .phan/stubs/amp-stubs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
<?php
/**
* Stubs automatically generated from AMP 2.5.3 and AMP for WP 1.0.94
* using the definition file `tools/stubs/amp-stub-defs.php` in the Jetpack monorepo.
*
* Do not edit this directly! Run tools/stubs/update-stubs.sh to regenerate it.
*/

/**
* Whether this is in 'canonical mode'.
*
* Themes can register support for this with `add_theme_support( AMP_Theme_Support::SLUG )`:
*
* ```php
* add_theme_support( AMP_Theme_Support::SLUG );
* ```
*
* This will serve templates in AMP-first, allowing you to use AMP components in your theme templates.
* If you want to make available in transitional mode, where templates are served in AMP or non-AMP documents, do:
*
* ```php
* add_theme_support( AMP_Theme_Support::SLUG, array(
* 'paired' => true,
* ) );
* ```
*
* Transitional mode is also implied if you define a `template_dir`:
*
* ```php
* add_theme_support( AMP_Theme_Support::SLUG, array(
* 'template_dir' => 'amp',
* ) );
* ```
*
* If you want to have AMP-specific templates in addition to serving AMP-first, do:
*
* ```php
* add_theme_support( AMP_Theme_Support::SLUG, array(
* 'paired' => false,
* 'template_dir' => 'amp',
* ) );
* ```
*
* @see AMP_Theme_Support::read_theme_support()
* @return boolean Whether this is in AMP 'canonical' mode, that is whether it is AMP-first and there is not a separate (paired) AMP URL.
*/
function amp_is_canonical()
{
}
/**
* Determines whether the legacy AMP post templates are being used.
*
* @since 2.0
* @return bool
*/
function amp_is_legacy()
{
}
/**
* Determine whether AMP is available for the current URL.
*
* @since 2.0
*
* @return bool Whether there is an AMP version for the provided URL.
* @global string $pagenow
* @global WP_Query $wp_query
*/
function amp_is_available()
{
}
/**
* Retrieves the full AMP-specific permalink for the given post ID.
*
* On a site in Standard mode, this is the same as `get_permalink()`.
*
* @since 0.1
*
* @param int $post_id Post ID.
* @return string AMP permalink.
*/
function amp_get_permalink($post_id)
{
}
/**
* Determine whether the current request is for an AMP page.
*
* This function cannot be called before the parse_query action because it needs to be able
* to determine the queried object is able to be served as AMP. If 'amp' theme support is not
* present, this function returns true just if the query var is present. If theme support is
* present, then it returns true in transitional mode if an AMP template is available and the query
* var is present, or else in standard mode if just the template is available.
*
* @since 2.0 Formerly known as is_amp_endpoint().
*
* @return bool Whether it is the AMP endpoint.
* @global WP_Query $wp_query
*/
function amp_is_request()
{
}
/**
* Determine whether the current response being served as AMP.
*
* This function cannot be called before the parse_query action because it needs to be able
* to determine the queried object is able to be served as AMP. If 'amp' theme support is not
* present, this function returns true just if the query var is present. If theme support is
* present, then it returns true in transitional mode if an AMP template is available and the query
* var is present, or else in standard mode if just the template is available.
*
* @since 0.1
* @since 2.0 Renamed to AMP-prefixed version, amp_is_request().
* @deprecated Use amp_is_request() instead.
*
* @return bool Whether it is the AMP endpoint.
*/
function is_amp_endpoint()
{
}
/**
* Class AMP_Options_Manager
*
* @internal
*/
class AMP_Options_Manager
{
/**
* Get plugin option.
*
* @param string $option Plugin option name.
* @param bool $default Default value.
*
* @return mixed Option value.
*/
public static function get_option($option, $default = \false)
{
}
}
/**
* Registers a submenu page to access the AMP template editor panel in the Customizer.
*
* @internal
*/
function amp_add_customizer_link()
{
}
// AMP endpoint Verifier
/**
* @phan-return mixed Dummy doc for stub.
*/
function ampforwp_is_amp_endpoint()
{
}
4 changes: 2 additions & 2 deletions projects/packages/blocks/.phan/baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
// # Issue statistics:
// PhanTypeMismatchArgument : 2 occurrences
// PhanUndeclaredClassMethod : 2 occurrences
// PhanDeprecatedFunction : 1 occurrence
// PhanPluginDuplicateConditionalNullCoalescing : 1 occurrence
// PhanTypeMismatchArgumentNullableInternal : 1 occurrence
// PhanUndeclaredClassInCallable : 1 occurrence
// PhanUndeclaredClassReference : 1 occurrence
// PhanUndeclaredFunction : 1 occurrence

// Currently, file_suppressions and directory_suppressions are the only supported suppressions
'file_suppressions' => [
'src/class-blocks.php' => ['PhanPluginDuplicateConditionalNullCoalescing', 'PhanTypeMismatchArgumentNullableInternal', 'PhanUndeclaredClassInCallable', 'PhanUndeclaredClassMethod', 'PhanUndeclaredClassReference', 'PhanUndeclaredFunction'],
'src/class-blocks.php' => ['PhanDeprecatedFunction', 'PhanPluginDuplicateConditionalNullCoalescing', 'PhanTypeMismatchArgumentNullableInternal', 'PhanUndeclaredClassInCallable', 'PhanUndeclaredClassMethod', 'PhanUndeclaredClassReference'],
'tests/php/test-blocks.php' => ['PhanTypeMismatchArgument'],
],
// 'directory_suppressions' => ['src/directory_name' => ['PhanIssueName1', 'PhanIssueName2']] can be manually added if needed.
Expand Down
2 changes: 1 addition & 1 deletion projects/packages/blocks/.phan/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
// Require base config.
require __DIR__ . '/../../../../.phan/config.base.php';

return make_phan_config( dirname( __DIR__ ) );
return make_phan_config( dirname( __DIR__ ), array( '+stubs' => array( 'amp' ) ) );
5 changes: 5 additions & 0 deletions projects/packages/blocks/changelog/add-phan-amp-stubs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Update Phan config to use AMP stubs. No change to functionality.


4 changes: 2 additions & 2 deletions projects/packages/lazy-images/.phan/baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
return [
// # Issue statistics:
// PhanTypeMismatchArgument : 2 occurrences
// PhanDeprecatedFunction : 1 occurrence
// PhanParamTooMany : 1 occurrence
// PhanTypeMismatchPropertyProbablyReal : 1 occurrence
// PhanUndeclaredFunction : 1 occurrence

// Currently, file_suppressions and directory_suppressions are the only supported suppressions
'file_suppressions' => [
'src/lazy-images.php' => ['PhanTypeMismatchPropertyProbablyReal', 'PhanUndeclaredFunction'],
'src/lazy-images.php' => ['PhanDeprecatedFunction', 'PhanTypeMismatchPropertyProbablyReal'],
'tests/php/test_class.lazy-images.php' => ['PhanParamTooMany', 'PhanTypeMismatchArgument'],
],
// 'directory_suppressions' => ['src/directory_name' => ['PhanIssueName1', 'PhanIssueName2']] can be manually added if needed.
Expand Down
2 changes: 1 addition & 1 deletion projects/packages/lazy-images/.phan/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
// Require base config.
require __DIR__ . '/../../../../.phan/config.base.php';

return make_phan_config( dirname( __DIR__ ) );
return make_phan_config( dirname( __DIR__ ), array( '+stubs' => array( 'amp' ) ) );
5 changes: 5 additions & 0 deletions projects/packages/lazy-images/changelog/add-phan-amp-stubs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Update Phan config to use AMP stubs. No change to functionality.


3 changes: 1 addition & 2 deletions projects/packages/stats/.phan/baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
// PhanUnextractableAnnotationSuffix : 5 occurrences
// PhanTypeVoidAssignment : 4 occurrences
// PhanPluginDuplicateConditionalNullCoalescing : 2 occurrences
// PhanUndeclaredFunction : 2 occurrences
// PhanDeprecatedFunction : 1 occurrence
// PhanTypeMismatchProperty : 1 occurrence
// PhanTypeMismatchReturn : 1 occurrence
Expand All @@ -23,7 +22,7 @@
// Currently, file_suppressions and directory_suppressions are the only supported suppressions
'file_suppressions' => [
'src/class-options.php' => ['PhanUnextractableAnnotationSuffix'],
'src/class-tracking-pixel.php' => ['PhanPluginDuplicateConditionalNullCoalescing', 'PhanUndeclaredFunction', 'PhanUnextractableAnnotationSuffix'],
'src/class-tracking-pixel.php' => ['PhanPluginDuplicateConditionalNullCoalescing', 'PhanUnextractableAnnotationSuffix'],
'src/class-wpcom-stats.php' => ['PhanTypeMismatchReturn', 'PhanUnextractableAnnotationSuffix'],
'tests/php/test-main.php' => ['PhanParamTooMany', 'PhanTypeVoidAssignment'],
'tests/php/test-options.php' => ['PhanTypeVoidAssignment'],
Expand Down
2 changes: 1 addition & 1 deletion projects/packages/stats/.phan/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
// Require base config.
require __DIR__ . '/../../../../.phan/config.base.php';

return make_phan_config( dirname( __DIR__ ) );
return make_phan_config( dirname( __DIR__ ), array( '+stubs' => array( 'amp' ) ) );
5 changes: 5 additions & 0 deletions projects/packages/stats/changelog/add-phan-amp-stubs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Update Phan config to use AMP stubs. No change to functionality.


2 changes: 1 addition & 1 deletion projects/packages/stats/src/class-package-version.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/
class Package_Version {

const PACKAGE_VERSION = '0.12.1';
const PACKAGE_VERSION = '0.12.2-alpha';

const PACKAGE_SLUG = 'stats';

Expand Down
4 changes: 2 additions & 2 deletions projects/packages/sync/.phan/baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
// PhanTypeMismatchReturnNullable : 2 occurrences
// PhanTypePossiblyInvalidDimOffset : 2 occurrences
// PhanTypeSuspiciousStringExpression : 2 occurrences
// PhanUndeclaredFunction : 2 occurrences
// PhanDeprecatedFunction : 1 occurrence
// PhanNoopNew : 1 occurrence
// PhanParamTooManyCallable : 1 occurrence
Expand All @@ -50,6 +49,7 @@
// PhanTypeMismatchDefault : 1 occurrence
// PhanTypeMismatchProperty : 1 occurrence
// PhanTypeMismatchPropertyProbablyReal : 1 occurrence
// PhanUndeclaredFunction : 1 occurrence
// PhanUndeclaredMethodInCallable : 1 occurrence
// PhanUndeclaredStaticMethod : 1 occurrence
// PhanUndeclaredTypeParameter : 1 occurrence
Expand Down Expand Up @@ -83,7 +83,7 @@
'src/modules/class-network-options.php' => ['PhanParamSignatureMismatch', 'PhanTypeMismatchReturnProbablyReal'],
'src/modules/class-options.php' => ['PhanParamSignatureMismatch', 'PhanTypeMismatchReturnProbablyReal', 'PhanUndeclaredFunction'],
'src/modules/class-plugins.php' => ['PhanPluginDuplicateConditionalNullCoalescing', 'PhanUndeclaredMethod'],
'src/modules/class-posts.php' => ['PhanPluginDuplicateConditionalNullCoalescing', 'PhanPluginUseReturnValueInternalKnown', 'PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentNullable', 'PhanTypeMismatchReturnProbablyReal', 'PhanUndeclaredFunction'],
'src/modules/class-posts.php' => ['PhanPluginDuplicateConditionalNullCoalescing', 'PhanPluginUseReturnValueInternalKnown', 'PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentNullable', 'PhanTypeMismatchReturnProbablyReal'],
'src/modules/class-protect.php' => ['PhanUndeclaredClassMethod'],
'src/modules/class-term-relationships.php' => ['PhanParamSignatureMismatch', 'PhanTypeMismatchArgument'],
'src/modules/class-terms.php' => ['PhanAccessMethodInternal', 'PhanParamSignatureMismatch'],
Expand Down
2 changes: 1 addition & 1 deletion projects/packages/sync/.phan/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
// Require base config.
require __DIR__ . '/../../../../.phan/config.base.php';

return make_phan_config( dirname( __DIR__ ), array( '+stubs' => array( 'woocommerce', 'woocommerce-internal' ) ) );
return make_phan_config( dirname( __DIR__ ), array( '+stubs' => array( 'amp', 'woocommerce', 'woocommerce-internal' ) ) );
5 changes: 5 additions & 0 deletions projects/packages/sync/changelog/add-phan-amp-stubs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Update Phan config to use AMP stubs. No change to functionality.


6 changes: 3 additions & 3 deletions projects/plugins/boost/.phan/baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
// PhanTypeMissingReturn : 10+ occurrences
// PhanTypeArraySuspicious : 9 occurrences
// PhanTypeMismatchArgument : 9 occurrences
// PhanUndeclaredFunction : 8 occurrences
// PhanParamTooMany : 7 occurrences
// PhanPossiblyUndeclaredVariable : 6 occurrences
// PhanUndeclaredClassMethod : 6 occurrences
// PhanUndeclaredFunction : 6 occurrences
// PhanUndeclaredConstant : 5 occurrences
// PhanCommentParamOnEmptyParamList : 3 occurrences
// PhanPluginUseReturnValueInternalKnown : 3 occurrences
Expand Down Expand Up @@ -101,10 +101,10 @@
'app/modules/optimizations/page-cache/pre-wordpress/Logger.php' => ['PhanCoalescingNeverNull', 'PhanPluginDuplicateConditionalNullCoalescing'],
'app/modules/optimizations/page-cache/pre-wordpress/Request.php' => ['PhanPluginDuplicateConditionalNullCoalescing', 'PhanTypeMismatchPropertyDefault'],
'app/modules/optimizations/page-cache/pre-wordpress/storage/File_Storage.php' => ['PhanTypeMismatchArgument'],
'app/modules/optimizations/render-blocking-js/class-render-blocking-js.php' => ['PhanTypeMismatchProperty', 'PhanTypeMismatchPropertyDefault', 'PhanTypeMissingReturn', 'PhanUndeclaredFunction'],
'app/modules/optimizations/render-blocking-js/class-render-blocking-js.php' => ['PhanTypeMismatchProperty', 'PhanTypeMismatchPropertyDefault', 'PhanTypeMissingReturn'],
'app/modules/performance-history/Performance_History.php' => ['PhanTypeMissingReturn'],
'app/rest-api/permissions/Nonce.php' => ['PhanParamTooMany'],
'compatibility/amp.php' => ['PhanUndeclaredClassInCallable', 'PhanUndeclaredFunction', 'PhanUndeclaredTypeParameter', 'PhanUndeclaredTypeProperty'],
'compatibility/amp.php' => ['PhanUndeclaredClassInCallable', 'PhanUndeclaredTypeParameter', 'PhanUndeclaredTypeProperty'],
'compatibility/elementor.php' => ['PhanUndeclaredClassConstant'],
'compatibility/jetpack.php' => ['PhanUndeclaredClassMethod'],
'compatibility/lib/class-sync-jetpack-module-status.php' => ['PhanParamTooMany', 'PhanUndeclaredClassMethod'],
Expand Down
2 changes: 1 addition & 1 deletion projects/plugins/boost/.phan/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
// Require base config.
require __DIR__ . '/../../../../.phan/config.base.php';

return make_phan_config( dirname( __DIR__ ), array( '+stubs' => array( 'woocommerce' ) ) );
return make_phan_config( dirname( __DIR__ ), array( '+stubs' => array( 'amp', 'woocommerce' ) ) );
5 changes: 5 additions & 0 deletions projects/plugins/boost/changelog/add-phan-amp-stubs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Update Phan config to use AMP stubs. No change to functionality.


Loading

0 comments on commit 2e7b50a

Please sign in to comment.