paglliac/dependency-analysis
Composer 安装命令:
composer require paglliac/dependency-analysis
包简介
Library for static analysis modules dependencies in php projects
README 文档
README
PHP DA is tool for check and support dependencies inside your project clear.
For example:
- You have project with 3 root namespaces: Domain, Application, Infrastructure
- You want to be sure dependencies in your project defined as graph
[
'dependencies' => [
'\Domain' => null,
'\Application' => ['\Domain'],
'\Infrastructure' => ['\Domain', '\Application']
]
];
That means all classes from Domain namespace should use only classes from this namespace, and possibly vendor (it s configured).
All classes from Application can use classes from Domain and Application namespaces, but not from Infrastructure, etc
If some classes using dependencies not satisfied defined dependency graph, you give errors in report:
Have been analyzed 4 files
You have dependency problems in 2 files in your project:
Class \Application\TrackingService have errors:
- Class \Application\TrackingService using class \Infrastructure\ShipImplementation which not satisfy dependency graph
Class \Domain\Cargo have errors:
- Class \Domain\Cargo using class \Application\TrackingService which not satisfy dependency graph
- Class \Domain\Cargo using class \Infrastructure\ShipImplementation which not satisfy dependency graph
Use cases
It can be useful in some cases for example:
- You want to extract part of your application in separate service, you define valid dependencies and run php-da for investigate workload
- You want to support low coupling in your application, you define valid dependencies and run php-da on your CI server for every MR, only for changed files
- You want to make visible structure changes of your application for all developers, now it is visible in php-da config
Quick start
Install library using composer
composer require paglliac/dependency-analysis
Configuration
Add configuration file config.php to root of your project :
return [ /** * REQUIRED * Dependencies Graph * * Description of valid dependencies in project * * This config means * * Package (every class in namespace) \Domain can use only classes from namespace \Domain or vendor dependencies * Package \Application can use only classes from namespaces \Domain, \Application or vendor dependencies * Package \Infrastructure can use only classes from namespaces \Domain, \Application, \Infrastructure or vendor dependencies */ 'dependencies' => [ '\Domain' => null, '\Application' => ['\Domain'], '\Infrastructure' => ['\Domain', '\Application'] ], /** * REQUIRED * Source path where dependencies will be analyzed */ 'path' => __DIR__, /** * OPTIONAL * * Make available to use vendor dependencies in whole project * * true - all project classes can use vendor dependencies * false - all project can not use vendor dependencies */ 'skip_vendor_dir' => true, /** * OPTIONAL * Flag that define how to do when some files placed in namespaces not presented in Dependencies Graph * * true - mark class as having incorrect dependencies * false - skip this file * * For example, in directory we have namespace \SomeNamespace with class \SomeNamespace\SomeClass * if flag is true, it will be marked as incorrect file, if flag is true, this file wil be marked as correct */ 'fail_on_non_presented_namespace' => false, /** * OPTIONAL * Flag for php parser, correct values: * * PhpParser\ParserFactory::PREFER_PHP7 - 1 (default) * PhpParser\ParserFactory::PREFER_PHP5 - 2 * PhpParser\ParserFactory::ONLY_PHP7 - 3 * PhpParser\ParserFactory::ONLY_PHP5 - 4 */ 'php_version' => PhpParser\ParserFactory::PREFER_PHP7, /** * OPTIONAL * * List of allowed files extensions, all files with other extensions will be skipped from analysis * * Default - ['php'] */ 'allowed_extensions' => ['php'] ];
Running
Run dependency validation:
/vendor/bin/php-da -c config.php [files filter]
Options:
-cor--configis required option with the relative path to config file
Arguments:
[files filter]list of files for analysis, it's useful to use in CI combine with --diff
Example of output
Have been analyzed 4 files
You have dependency problems in 2 files in your project:
Class \Application\TrackingService have errors:
- Class \Application\TrackingService using class \Infrastructure\ShipImplementation which not satisfy dependency graph
Class \Domain\Cargo have errors:
- Class \Domain\Cargo using class \Application\TrackingService which not satisfy dependency graph
- Class \Domain\Cargo using class \Infrastructure\ShipImplementation which not satisfy dependency graph
paglliac/dependency-analysis 适用场景与选型建议
paglliac/dependency-analysis 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 40 次下载、GitHub Stars 达 13, 最近一次更新时间为 2021 年 07 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 paglliac/dependency-analysis 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 paglliac/dependency-analysis 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 40
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 13
- 点击次数: 6
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-07-20