insolita/yii2-codestat
Composer 安装命令:
composer require insolita/yii2-codestat
包简介
Statistic of code usage inspired by Laravel Stats
关键字:
README 文档
README
Based on phploc/phploc
Installation
Either run
composer require --dev insolita/yii2-codestat:~2.0
or add
"insolita/yii2-codestat": "~2.0"
in require-dev section of your composer.json file.
Basic Usage
Add in console configuration file, in section modules
php
'modules'=>[
....
'codestat'=>[
'class'=>\insolita\codestat\CodeStatModule::class,
'scanTargets' => ['@backend/','@common/','@frontend/','@console/'],
'exceptTargets' => ['*config*','vendor*','*web/','*runtime/','*views/','*tests/'],
]
],
scanTargets - array of path, or path aliases that will be scanned recursively exceptTargets - array of path patterns for excluding
For checking whole list of files that will be processed, run
./yii codestat/default/list-files
For statistic summary output run
./yii codestat
For statistic summary output with show bad resolved files
./yii codestat 1
Show full phploc report per each defined group
./yii codestat/default/advanced
./yii codestat/default/advanced WebControllers
./yii codestat/default/advanced WebControllers,RestControllers,ConsoleControllers
Show full phploc report for all matched files
./yii codestat/default/common
Show full phploc report for custom directory
./yii codestat/default/directory @common/models
Show full phploc report for custom file
./yii codestat/default/file @common/lib/MySuperClass.php
List available metrics with codes
./yii codestat/default/list-metrics
Advanced Usage
Custom Class Grouping Rules
You can extend or overwrite property 'groupRules', with supported formats
'Group Name' => 'BaseParentClass'
where 'BaseParentClass' should by verified with (\ReflectionClass)->isSubclassOf()
or
'Group Name' => function(\ReflectionClass $reflection){
//Should return true if class valid for this group, otherwise false;
}
Final example
php
'modules'=>[
....
'codestat'=>[
'class'=>\insolita\codestat\CodeStatModule::class,
'groupRules' => [
'Jobs' => 'yii\queue\JobInterface',
'Handlers' => 'trntv\bus\interfaces\Handler::class',
'DTO' => function (\ReflectionClass $reflection) {
return mb_strpos($reflection->getFileName(), 'Dto')!==false;
},
'All Tests' => function (\ReflectionClass $reflection) {
return $reflection->isSubclassOf('\Codeception\Test\Unit')
|| StringHelper::endsWith($reflection->getName(), 'Cest');
},
] + CodeStatModule::defaultRules(),
],
]
],
Important! The order of the rules in the list matters, the base classes (\yii\base\Component and \yii\base\Object) should be at the end of the list!
Custom code metrics
Code metrics provided by https://github.com/sebastianbergmann/phploc, has lot of variants, you can define own combination
For actions advanced/common/directory/file you should set metrics property with array of necessary metric names
php
'modules'=>[
....
'codestat'=>[
'class'=>\insolita\codestat\CodeStatModule::class,
'metrics'=>['loc','lloc','classCcnAvg', 'classLlocAvg', 'methodCcnAvg']
]
]
For summary action you should provide property 'analyseCallback' in module like as
'analyseCallback = function($group){ /**@var insolita\codestat\lib\collection\Group $group **/ $metrics=$customAnalyzer->analyze($group->getFiles()); return ['totalFiles'=>count($group->getFiles()), 'metric1'=>$metrics[some], ...etc]; }
It should return associative array with 'metric name' => 'metric value' data and will replace internal https://github
.com/Insolita/yii2-codestat/blob/7d0fc3351718b2052624ea091ff8f154fe471aeb/src/lib/CodestatService.php#L154
And also table summary convention - if metric name contains slash "/", for summary row will be counted average value, otherwise sum
insolita/yii2-codestat 适用场景与选型建议
insolita/yii2-codestat 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 159 次下载、GitHub Stars 达 34, 最近一次更新时间为 2017 年 10 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「code」 「statistic」 「yii2」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 insolita/yii2-codestat 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 insolita/yii2-codestat 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 insolita/yii2-codestat 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Memio's PrettyPrinter, used to generate PHP code from given Model
A custom URL rule class for Yii 2 which allows to create translated URL rules
Matomo statistics for Contao 4
Promotional Codes Generator for Laravel 5.1
A statistic system for appui
Zend Captcha bundle
统计信息
- 总下载量: 159
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 34
- 点击次数: 4
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-10-19
