angelxmoreno / get-set-annotations
GetSetTrait 的辅助工具
v2.0.0
2022-09-20 01:49 UTC
Requires
- php: >=7.1
- hanneskod/classtools: ^1.2
- symfony/finder: ^5.4
Requires (Dev)
- kahlan/kahlan: ^4.0
- squizlabs/php_codesniffer: ^3.2
README
一个用于报告由于使用魔法方法而缺少 getter/setter 方法的 CLI 脚本。
为什么有这个项目?
我非常喜欢使用由 mikebarlow 提供的 GetSetTrait。使用魔法获取器和设置器的一个问题是,大多数 IDE 会丢失关于类方法的了解。这可以通过向类文档块中添加适当的 @method
条目来轻松解决。这有时可能很耗时且容易出错。
我创建了这个 CLI 脚本来生成缺少定义的获取器和设置器的类的 @method
条目。虽然它是为了支持 GetSetTrait 而创建的,但它可以用于任何魔法获取器和设置器的实现
安装
composer require --dev angelxmoreno/get-set-annotations
用法
./bin/get-set-scan [directory]
这会打印出类似于以下报告的内容
Classname : Axm\GetSetAnnotations\ClassInfo
Path : /Users/amoreno/Projects/AmzRouter/get-set-methods-annotation/src/ClassInfo.php
DocBlock :
* @method void setPath(string $path)
* @method void setFqn(string $fqn)
* @method void setProperties(PropertyInfo[] $properties)
* @method void setHasMissingMethods(bool $has_missing_methods)
* @method bool getHasMissingMethods()
测试
测试可以通过两种不同的方式运行:本地和通过 Docker 容器。
本地
composer tests:check composer tests:coverage
使用内置的 Docker 镜像
composer docker:tests:check composer docker:tests:coverage
当前测试覆盖率
Coverage Summary
----------------
Lines %
\ 45 / 71 63.38%
└── Axm\ 45 / 71 63.38%
└── GetSetAnnotations\ 45 / 71 63.38%
├── Analyser 7 / 7 100.00%
│ ├── Analyser::buildClassInfosInPath() 6 / 6 100.00%
│ └── Analyser::path() 1 / 1 100.00%
├── CamelCase 2 / 3 66.67%
│ └── CamelCase::convert() 2 / 3 66.67%
├── ClassInfo 22 / 29 75.86%
│ ├── ClassInfo::__construct() 5 / 5 100.00%
│ ├── ClassInfo::buildCurrentDocMethods() 2 / 2 100.00%
│ ├── ClassInfo::buildMissingMethodsDoc() 0 / 7 0.00%
│ ├── ClassInfo::buildPropertyInfoArray() 11 / 11 100.00%
│ ├── ClassInfo::getFqn() 1 / 1 100.00%
│ ├── ClassInfo::getPath() 1 / 1 100.00%
│ ├── ClassInfo::getProperties() 1 / 1 100.00%
│ └── ClassInfo::hasMissingMethods() 1 / 1 100.00%
├── PropertyInfo 14 / 14 100.00%
│ ├── PropertyInfo::__construct() 8 / 8 100.00%
│ ├── PropertyInfo::getGetterFuncName() 1 / 1 100.00%
│ ├── PropertyInfo::getName() 1 / 1 100.00%
│ ├── PropertyInfo::getSetterFuncName() 1 / 1 100.00%
│ ├── PropertyInfo::getType() 1 / 1 100.00%
│ ├── PropertyInfo::isMissingGetterMethod() 1 / 1 100.00%
│ └── PropertyInfo::isMissingSetterMethod() 1 / 1 100.00%
└── Writer 0 / 18 0.00%
├── Writer::__construct() 0 / 4 0.00%
├── Writer::outCli() 0 / 3 0.00%
├── Writer::toCli() 0 / 6 0.00%
└── Writer::writeToFile() 0 / 5 0.00%
Total: 63.38% (45/71)
Coverage collected in 0.069 seconds
许可证
版权所有 2022 Angel S. Moreno (angelxmoreno)。保留所有权利。
根据 MIT 许可证授权。包含在此存储库中的源代码的再分发必须保留每个文件中找到的版权声明。