Skip to content

Commit

Permalink
Fix obviously wrong class name references (#36769)
Browse files Browse the repository at this point in the history
Almost all are phpdoc comments where the class was missing a `use` or
leading `\`. More specifically, I searched for cases where Phan was
complaining about classes named like `\Automattic\...\Automattic\`, or
`\WP_...`, or `Exception` classes, and fixed all the obvious ones.

Then I also searched for "undeclared {class|type} \[a-z]" and fixed the
obvious ones out of that too (e.g. "obj", "number", and various typos).

Note that having the correct typing allows Phan to complain about
possibly-real issues in some cases. Those will have to be reviewed
later.
  • Loading branch information
anomiex authored Apr 8, 2024
1 parent 64d328d commit b1fe483
Show file tree
Hide file tree
Showing 211 changed files with 792 additions and 563 deletions.
3 changes: 1 addition & 2 deletions projects/packages/abtest/.phan/baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@
return [
// # Issue statistics:
// PhanUndeclaredProperty : 10+ occurrences
// PhanUndeclaredTypeReturnType : 2 occurrences
// PhanDeprecatedFunction : 1 occurrence
// PhanTypeMismatchArgumentProbablyReal : 1 occurrence

// Currently, file_suppressions and directory_suppressions are the only supported suppressions
'file_suppressions' => [
'src/class-abtest.php' => ['PhanTypeMismatchArgumentProbablyReal', 'PhanUndeclaredTypeReturnType'],
'src/class-abtest.php' => ['PhanTypeMismatchArgumentProbablyReal'],
'tests/php/test-abtest.php' => ['PhanDeprecatedFunction', 'PhanUndeclaredProperty'],
],
// 'directory_suppressions' => ['src/directory_name' => ['PhanIssueName1', 'PhanIssueName2']] can be manually added if needed.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: fixed
Comment: Fix phpdoc class references. Should be no change to functionality.


4 changes: 2 additions & 2 deletions projects/packages/abtest/src/class-abtest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function get_variation( $test_name ) {
* @access protected
*
* @param string $test_name Name of the A/B test.
* @return mixed|Automattic\Jetpack\Error A/B test variation, or Automattic\Jetpack\Error on failure.
* @return mixed|\Automattic\Jetpack\Error A/B test variation, or Automattic\Jetpack\Error on failure.
*/
protected function fetch_variation( $test_name ) {
// Make sure test name exists.
Expand Down Expand Up @@ -93,7 +93,7 @@ protected function fetch_variation( $test_name ) {
* @access protected
*
* @param string $test_name Name of the A/B test.
* @return mixed|Automattic\Jetpack\Error A/B test variation, or Automattic\Jetpack\Error on failure.
* @return mixed|\Automattic\Jetpack\Error A/B test variation, or Automattic\Jetpack\Error on failure.
*/
protected function request_variation( $test_name ) {
return Client::wpcom_json_api_request_as_blog( sprintf( '/abtest/%s', $test_name ), '2', array(), null, 'wpcom' );
Expand Down
9 changes: 4 additions & 5 deletions projects/packages/analyzer/.phan/baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// # Issue statistics:
// PhanUndeclaredProperty : 30+ occurrences
// PhanTypeMismatchArgument : 10+ occurrences
// PhanUndeclaredClassMethod : 10+ occurrences
// PhanUndeclaredClassMethod : 9 occurrences
// PhanPossiblyUndeclaredVariable : 7 occurrences
// PhanParamSignatureMismatch : 6 occurrences
// PhanPluginDuplicateConditionalNullCoalescing : 6 occurrences
Expand All @@ -24,7 +24,6 @@
// PhanNonClassMethodCall : 2 occurrences
// PhanPluginDuplicateCatchStatementBody : 2 occurrences
// PhanTypeMismatchDeclaredParam : 2 occurrences
// PhanUndeclaredClassCatch : 2 occurrences
// PhanUndeclaredClassStaticProperty : 2 occurrences
// PhanUnextractableAnnotationElementName : 2 occurrences
// PhanUnextractableAnnotationSuffix : 2 occurrences
Expand All @@ -36,8 +35,8 @@
// Currently, file_suppressions and directory_suppressions are the only supported suppressions
'file_suppressions' => [
'data/example-external.php' => ['PhanUndeclaredClassMethod', 'PhanUndeclaredClassStaticProperty', 'PhanUndeclaredFunction'],
'scripts/core-calls.php' => ['PhanPluginDuplicateConditionalNullCoalescing', 'PhanTypeMismatchDeclaredParam', 'PhanUndeclaredClassCatch', 'PhanUndeclaredClassMethod', 'PhanUndeclaredTypeParameter'],
'scripts/core-definitions.php' => ['PhanPluginDuplicateConditionalNullCoalescing', 'PhanTypeMismatchDeclaredParam', 'PhanUndeclaredClassCatch', 'PhanUndeclaredClassMethod', 'PhanUndeclaredTypeParameter'],
'scripts/core-calls.php' => ['PhanPluginDuplicateConditionalNullCoalescing', 'PhanTypeMismatchDeclaredParam', 'PhanUndeclaredClassMethod', 'PhanUndeclaredTypeParameter'],
'scripts/core-definitions.php' => ['PhanPluginDuplicateConditionalNullCoalescing', 'PhanTypeMismatchDeclaredParam', 'PhanUndeclaredClassMethod', 'PhanUndeclaredTypeParameter'],
'scripts/example.php' => ['PhanTypeMismatchArgumentProbablyReal'],
'scripts/jetpack-slurper.php' => ['PhanDeprecatedEncapsVar'],
'scripts/jetpack-svn.php' => ['PhanPluginDuplicateConditionalNullCoalescing', 'PhanTypeArraySuspiciousNullable'],
Expand All @@ -55,7 +54,7 @@
'src/api/class-controller.php' => ['PhanUndeclaredMethod'],
'src/api/class-model.php' => ['PhanTypeArraySuspiciousNullable'],
'src/api/class-plugin-downloader.php' => ['PhanPluginDuplicateExpressionAssignmentOperation', 'PhanUndeclaredProperty'],
'src/class-declarations.php' => ['PhanPluginDuplicateCatchStatementBody', 'PhanUndeclaredClassMethod'],
'src/class-declarations.php' => ['PhanPluginDuplicateCatchStatementBody'],
'src/class-differences.php' => ['PhanNonClassMethodCall', 'PhanPossiblyUndeclaredVariable', 'PhanTypeMismatchArgumentNullable'],
'src/class-invocations.php' => ['PhanPluginDuplicateCatchStatementBody'],
'src/class-utils.php' => ['PhanTypeMismatchArgument', 'PhanUndeclaredClassMethod', 'PhanUndeclaredMethod', 'PhanUndeclaredProperty', 'PhanUndeclaredTypeParameter', 'PhanUnextractableAnnotationElementName', 'PhanUnextractableAnnotationSuffix'],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: fixed
Comment: Fix phpdoc class references. Should be no change to functionality.


1 change: 1 addition & 0 deletions projects/packages/analyzer/scripts/core-calls.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace Automattic\Jetpack\Analyzer;

use Composer\Script\Event;
use Exception;

/**
* This class holds the callback for the WordPress API function analyzer.
Expand Down
1 change: 1 addition & 0 deletions projects/packages/analyzer/scripts/core-definitions.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace Automattic\Jetpack\Analyzer;

use Composer\Script\Event;
use Exception;

/**
* This class holds the callback for the WordPress API function definition finder.
Expand Down
1 change: 1 addition & 0 deletions projects/packages/analyzer/src/class-declarations.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Automattic\Jetpack\Analyzer;

use Exception;
use PhpParser\NodeTraverser;
use PhpParser\NodeVisitor\NameResolver;
use PhpParser\ParserFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,10 @@
// PhanTypeMismatchArgumentProbablyReal : 15+ occurrences
// PhanTypeMismatchArgumentInternal : 3 occurrences
// PhanTypeMismatchForeach : 2 occurrences
// PhanUndeclaredClassMethod : 1 occurrence
// PhanUndeclaredTypeThrowsType : 1 occurrence

// Currently, file_suppressions and directory_suppressions are the only supported suppressions
'file_suppressions' => [
'src/class-helper-script-manager-impl.php' => ['PhanTypeMismatchArgumentInternal', 'PhanTypeMismatchForeach'],
'tests/php/test-class-helper-script-manager-impl.php' => ['PhanUndeclaredClassMethod', 'PhanUndeclaredTypeThrowsType'],
'tests/php/test-class-throw-on-errors.php' => ['PhanTypeMismatchArgumentInternal', 'PhanTypeMismatchArgumentProbablyReal'],
],
// 'directory_suppressions' => ['src/directory_name' => ['PhanIssueName1', 'PhanIssueName2']] can be manually added if needed.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: fixed
Comment: Fix phpdoc class references. Should be no change to functionality.


Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// are installed, or in some other cases).
namespace Automattic\Jetpack\Backup\V0004;

use Exception;
use WorDBless\BaseTestCase;
use WP_Error;
use function get_site_url;
Expand Down
7 changes: 2 additions & 5 deletions projects/packages/backup/.phan/baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,14 @@
// PhanTypeMismatchReturnProbablyReal : 15+ occurrences
// PhanTypeMismatchArgumentProbablyReal : 8 occurrences
// PhanTypeMismatchReturn : 6 occurrences
// PhanUndeclaredClassMethod : 6 occurrences
// PhanUndeclaredClassMethod : 5 occurrences
// PhanUndeclaredClassReference : 5 occurrences
// PhanTypeMismatchArgument : 3 occurrences
// PhanTypeArraySuspicious : 2 occurrences
// PhanUndeclaredStaticMethod : 2 occurrences
// PhanPossiblyUndeclaredVariable : 1 occurrence
// PhanUndeclaredTypeParameter : 1 occurrence

// Currently, file_suppressions and directory_suppressions are the only supported suppressions
'file_suppressions' => [
'src/class-jetpack-backup.php' => ['PhanPossiblyUndeclaredVariable', 'PhanTypeArraySuspicious', 'PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentProbablyReal', 'PhanTypeMismatchReturn', 'PhanTypeMismatchReturnProbablyReal', 'PhanUndeclaredClassMethod', 'PhanUndeclaredStaticMethod', 'PhanUndeclaredTypeParameter'],
'src/class-jetpack-backup.php' => ['PhanPossiblyUndeclaredVariable', 'PhanTypeMismatchArgumentProbablyReal', 'PhanTypeMismatchReturn', 'PhanTypeMismatchReturnProbablyReal', 'PhanUndeclaredClassMethod', 'PhanUndeclaredStaticMethod'],
'src/class-rest-controller.php' => ['PhanTypeMismatchArgumentProbablyReal', 'PhanTypeMismatchReturn', 'PhanTypeMismatchReturnProbablyReal', 'PhanUndeclaredClassMethod', 'PhanUndeclaredClassReference'],
],
// 'directory_suppressions' => ['src/directory_name' => ['PhanIssueName1', 'PhanIssueName2']] can be manually added if needed.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: fixed
Comment: Fix phpdoc class references. Should be no change to functionality.


2 changes: 1 addition & 1 deletion projects/packages/backup/src/class-jetpack-backup.php
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ public static function get_storage_addon_upsell_slug( $bytes_used, $bytes_availa
/**
* Get the best addon offer for this site, including pricing details
*
* @param WP_Request $request Object including storage usage.
* @param \WP_REST_Request $request Object including storage usage.
*
* @return string|WP_Error A JSON object with the suggested storage addon details if the request was successful,
* or a WP_Error otherwise.
Expand Down
15 changes: 6 additions & 9 deletions projects/packages/blaze/.phan/baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,20 @@
*/
return [
// # Issue statistics:
// PhanUndeclaredTypeParameter : 25+ occurrences
// PhanUndeclaredClassMethod : 7 occurrences
// PhanUndeclaredFunction : 7 occurrences
// PhanTypeArraySuspicious : 5 occurrences
// PhanUndeclaredClassProperty : 4 occurrences
// PhanTypeMismatchArgument : 3 occurrences
// PhanTypeArrayUnsetSuspicious : 2 occurrences
// PhanTypeMismatchArgument : 2 occurrences
// PhanTypeMismatchArgumentProbablyReal : 2 occurrences
// PhanTypeMismatchReturn : 2 occurrences
// PhanParamTooMany : 1 occurrence
// PhanTypeMismatchReturn : 1 occurrence
// PhanTypeMismatchReturnProbablyReal : 1 occurrence
// PhanTypeNoAccessiblePropertiesForeach : 1 occurrence
// PhanUndeclaredClassInstanceof : 1 occurrence
// PhanUndeclaredClassMethod : 1 occurrence

// Currently, file_suppressions and directory_suppressions are the only supported suppressions
'file_suppressions' => [
'src/class-blaze.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentProbablyReal', 'PhanUndeclaredClassProperty', 'PhanUndeclaredFunction', 'PhanUndeclaredTypeParameter'],
'src/class-dashboard-rest-controller.php' => ['PhanTypeArraySuspicious', 'PhanTypeArrayUnsetSuspicious', 'PhanTypeMismatchArgument', 'PhanTypeMismatchReturn', 'PhanTypeMismatchReturnProbablyReal', 'PhanUndeclaredClassInstanceof', 'PhanUndeclaredClassMethod', 'PhanUndeclaredFunction', 'PhanUndeclaredTypeParameter'],
'src/class-blaze.php' => ['PhanTypeMismatchArgumentProbablyReal', 'PhanUndeclaredFunction'],
'src/class-dashboard-rest-controller.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchReturn', 'PhanTypeMismatchReturnProbablyReal', 'PhanTypeNoAccessiblePropertiesForeach', 'PhanUndeclaredClassInstanceof', 'PhanUndeclaredClassMethod', 'PhanUndeclaredFunction'],
'src/class-rest-controller.php' => ['PhanParamTooMany'],
],
// 'directory_suppressions' => ['src/directory_name' => ['PhanIssueName1', 'PhanIssueName2']] can be manually added if needed.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: fixed
Comment: Fix phpdoc class references. Should be no change to functionality.


1 change: 1 addition & 0 deletions projects/packages/blaze/src/class-blaze.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Automattic\Jetpack\Status as Jetpack_Status;
use Automattic\Jetpack\Status\Host;
use Automattic\Jetpack\Sync\Settings as Sync_Settings;
use WP_Post;

/**
* Class for promoting posts.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Automattic\Jetpack\Status\Host;
use WC_Product;
use WP_Error;
use WP_REST_Request;
use WP_REST_Server;

/**
Expand Down
6 changes: 2 additions & 4 deletions projects/packages/blocks/.phan/baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,18 @@
*/
return [
// # Issue statistics:
// PhanUndeclaredClassProperty : 7 occurrences
// PhanTypeMismatchArgument : 2 occurrences
// PhanUndeclaredClassMethod : 2 occurrences
// PhanPluginDuplicateConditionalNullCoalescing : 1 occurrence
// PhanTypeMismatchArgumentNullableInternal : 1 occurrence
// PhanUndeclaredClassInCallable : 1 occurrence
// PhanUndeclaredClassReference : 1 occurrence
// PhanUndeclaredFunction : 1 occurrence
// PhanUndeclaredTypeReturnType : 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', 'PhanUndeclaredTypeReturnType'],
'tests/php/test-blocks.php' => ['PhanTypeMismatchArgument', 'PhanUndeclaredClassProperty'],
'src/class-blocks.php' => ['PhanPluginDuplicateConditionalNullCoalescing', 'PhanTypeMismatchArgumentNullableInternal', 'PhanUndeclaredClassInCallable', 'PhanUndeclaredClassMethod', 'PhanUndeclaredClassReference', 'PhanUndeclaredFunction'],
'tests/php/test-blocks.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)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: fixed
Comment: Fix phpdoc class references. Should be no change to functionality.


2 changes: 1 addition & 1 deletion projects/packages/blocks/src/class-blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Blocks {
* @type bool $plan_check Should we check for a specific plan before registering the block.
* }
*
* @return WP_Block_Type|false The registered block type on success, or false on failure.
* @return \WP_Block_Type|false The registered block type on success, or false on failure.
*/
public static function jetpack_register_block( $slug, $args = array() ) {
// Slug doesn't start with `jetpack/`, isn't an absolute path, or doesn't contain a slash
Expand Down
4 changes: 1 addition & 3 deletions projects/packages/boost-speed-score/.phan/baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
// PhanTypeExpectedObjectPropAccess : 4 occurrences
// PhanTypeMismatchArgumentNullable : 2 occurrences
// PhanTypeMismatchProperty : 2 occurrences
// PhanUndeclaredTypeParameter : 2 occurrences
// PhanUndeclaredTypeProperty : 2 occurrences
// PhanRedefineFunction : 1 occurrence
// PhanTypeMismatchPropertyDefault : 1 occurrence
// PhanTypeMismatchPropertyProbablyReal : 1 occurrence
Expand All @@ -23,7 +21,7 @@
// Currently, file_suppressions and directory_suppressions are the only supported suppressions
'file_suppressions' => [
'src/class-jetpack-boost-modules.php' => ['PhanTypeMismatchPropertyDefault'],
'src/class-speed-score-graph-history-request.php' => ['PhanTypeMismatchProperty', 'PhanUndeclaredTypeParameter', 'PhanUndeclaredTypeProperty'],
'src/class-speed-score-graph-history-request.php' => ['PhanTypeMismatchProperty'],
'src/class-speed-score-request.php' => ['PhanTypeMismatchProperty', 'PhanTypeMismatchPropertyProbablyReal'],
'src/class-speed-score.php' => ['PhanTypeMismatchArgumentNullable', 'PhanTypeMismatchReturnNullable'],
'tests/bootstrap.php' => ['PhanRedefineFunction', 'PhanTypeMismatchReturnProbablyReal'],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: fixed
Comment: Fix phpdoc class references. Should be no change to functionality.


Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ class Speed_Score_Graph_History_Request extends Cacheable {
/**
* The timestamp start windown in ms.
*
* @var number $start timestamp start windown in ms.
* @var int|float $start timestamp start windown in ms.
*/
private $start;

/**
* The timestamp end windown in ms.
*
* @var number $end timestamp end windown in ms.
* @var int|float $end timestamp end windown in ms.
*/
private $end;

Expand Down Expand Up @@ -57,9 +57,9 @@ class Speed_Score_Graph_History_Request extends Cacheable {
/**
* Constructor.
*
* @param number $start timestamp start windown in ms.
* @param number $end timestamp end windown in ms.
* @param array $error Speed Scores error.
* @param int|float $start timestamp start windown in ms.
* @param int|float $end timestamp end windown in ms.
* @param array $error Speed Scores error.
*/
public function __construct( $start, $end, $error ) {
$this->start = $start;
Expand Down
Loading

0 comments on commit b1fe483

Please sign in to comment.