automattic/jetpack-analyzer

分析 Jetpack 版本之间的差异

安装: 5

依赖项: 0

建议者: 0

安全性: 0

星标: 3

关注者: 3

分支: 1

类型:jetpack-library

v2.0.0 2024-02-07 20:37 UTC

README

分析公共类、方法、变量和函数,以在版本之间查找破坏性更改

运行

composer run example

API

声明

此类表示从一个或多个文件中积累的公共声明列表。

公共声明包括

  • 类方法(静态和实例)
  • 公共类属性
  • 函数

Declarations可以通过使用$declarations->scan($dir, $exclude = array())扫描文件和目录来找到每个声明。

您可以将这些声明printloadsave为CSV。

您还可以使用->find_differences($previous_declarations)生成旧代码库和新代码库之间的差异列表,例如Jetpack 7.4和Jetpack 7.5,它返回一个Automattic\Jetpack\Analyzer\Differences的实例。

$declarations = new Automattic\Jetpack\Analyzer\Declarations();

// single file
$declarations->scan( $base_path . '/class.jetpack.php' );

// OR recursively scan a directory
$exclude = array( '.git', 'vendor', 'tests', 'docker', 'bin', 'scss', 'images', 'docs', 'languages', 'node_modules' );
$declarations->scan( $base_path, $exclude );

// print the declarations
$declarations->print();

// save the declarations as CSV
$declarations->save( 'path/to/jetpack-trunk.csv' );

// load some other declarations
$jp74_declarations->load( 'path/to/jetpack-branch-7.4.csv' );

您可以将Declarations的实例用作输入到(new Differences())->find($new_codebase, $old_codebase)

支持的声明

  • 类属性(静态或实例)
  • 类方法(静态或实例)
  • 函数

差异

差异列表可用于检查对一组调用的兼容性。

这是通过解析任何外部文件查找调用来执行的。如果这些调用与两个Jetpack版本之间已更改的任何函数、方法、类或属性匹配,则将生成一个警告或错误列表。

// load declarations from a file, or scan using ->scan()
$trunk_declarations->load( 'path/to/codebase-1.0.csv' );
$other_declarations->load( 'path/to/codebase-2.0.csv' );
// OR
$trunk_declarations->scan( 'path/to/trunk_branch', array( '.git', 'node_modules' ) );
$other_declarations->scan( 'path/to/other_branch', array( '.git', 'node_modules' ) );

$differences = new Automattic\Jetpack\Analyzer\Differences();
$differences->find( $trunk_declarations, $jp74_declarations );
$differences->print();

支持的差异

  • 类缺失
  • 类移动到另一个文件
  • 类属性缺失
  • 类属性移动到另一个文件
  • 类方法缺失
  • 类方法移动到另一个文件
  • 函数缺失
  • 函数移动到另一个文件

调用

每种相关类型的调用列表

  • 函数调用
  • 静态和实例方法调用
  • 通过new实例化
  • 对类属性的引用

这是所有这些类型的调用。要仅查找已缺失/更改的函数的调用,请查看下面的警告。

$invocations = new Automattic\Jetpack\Analyzer\Invocations();
$invocations->scan( 'path/to/example.php' ); // can be a file or directory
// OR
$invocations->scan( 'path/to/repo', array( '.git', '.gitmodules', 'assets' ) );

$invocations->print();

支持的调用

  • new Class
  • 分配/读取静态Class属性
  • 调用静态Class方法
  • 调用Function

警告

由比较Invocations对象和Differences对象生成的警告列表。

// assumes `$differences` and `$invocations` have already been generated as per above
$warnings = new Automattic\Jetpack\Analyzer\Warnings();
$warnings->generate( $invocations, $differences );
$warnings->print();

支持的警告

  • new Class
  • 分配/读取静态Class属性
  • 调用静态Class方法
  • 调用Function