承接 jcnventura/pharborist 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

jcnventura/pharborist

Composer 安装命令:

composer require jcnventura/pharborist

包简介

Pharborist builds a syntax tree for PHP that can be traversed and manipulated.

README 文档

README

Pharborist logo

A PHP library to query and transform PHP source code via tree operations.

Roadmap

  • Tests with 100% code coverage
  • Integration with a third party library for PHPDoc comments
  • API to ease querying and transforming of the syntax tree
  • Build a PHP source code formatter using the library (Partially completed).
  • Build a PHP code check using the library

Below is an example of how the API might look once its more developed:

// Add use declaration if it does not already exist. Use UtilityString alias if conflict
$alias = $tree->ensureUseDeclaration('Drupal\Component\Utility\String', 'UtilityString');
// Find all calls to check_plain and rename them to use String::checkPlain
$function_calls = $tree->find(Filter::functionCall('check_plain'));
foreach ($function_calls as $call) {
  $class_method_call = ClassMethodCallNode::create($alias, 'check_plain', $call->getArgumentList());
  $call->replaceWith($class_method_call);
}

Usage

require_once 'vendor/autoload.php';

use Pharborist\Parser;
use Pharborist\Namespaces\NamespaceNode;
use Pharborist\Filter;

$filename = $argv[1];
$tree = Parser::parseFile($filename);

// check there only one namespace declaration
$namespaces = $tree->children(Filter::isInstanceOf('\Pharborist\Namespaces\NamespaceNode'));
if ($namespaces->count() > 1) {
  die('More then one namespace at line ' . $namespaces[1]->getLineNumber() . PHP_EOL);
}

Build Status

统计信息

  • 总下载量: 119.27k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 10
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-2.0-or-later
  • 更新时间: 2020-11-22