共生体 / silverstripe-phpstan
PHPStan for Silverstripe
4.0.0
2019-11-11 22:39 UTC
Requires
- php: ~7.1
- silverstripe/framework: ~4.3
- silverstripe/vendor-plugin: ^1.0
Requires (Dev)
- phpstan/phpstan: ~0.11.0
- phpstan/phpstan-phpunit: ~0.11.0
- phpunit/phpunit: ^7.5.14 || ^8.0
- squizlabs/php_codesniffer: ^3.0
Suggests
- phpstan/phpstan-shim: ~0.11.0
Replaces
README
PHPStan的一个扩展,允许它对SilverStripe功能进行推理。
特性
- 支持
DataObject::get()
,即它理解你有一个可迭代的SiteTree记录的DataList。 - 支持DataObject的
db
、has_one
、has_many
和many_many
魔术属性和方法,即它知道SiteTree::Title是一个字符串,SiteTree::ParentID是一个整数,以及SiteTree::Parent()是一个SiteTree记录。 - 支持
singleton('SiteTree')
和Injector::inst()->get('SiteTree')
,即它知道这些将返回"SiteTree"。如果你使用注入器覆盖这些,它也会知道你实际上使用的是哪个类。
此PHPStan模块能够对在启动时初始化SilverStripe配置系统的项目特定的扩展进行推理。所以如果你向Page
对象添加了一个添加额外db
字段的扩展,PHPStan将能够对其进行推理。
Composer安装
SilverStripe 3.X
composer require --dev symbiote/silverstripe-phpstan:1.0.0 phpstan/phpstan-shim:0.9.2
SilverStripe 4.X
composer require --dev symbiote/silverstripe-phpstan:2.0.0 phpstan/phpstan-shim:~0.11.0
注意:我们建议安装phpstan-shim,因为目前SilverStripe 3.X中,QueuedJobs模块对superclosure的依赖强制PHPStan的PHP-Parser依赖处于一个非常旧的版本。
要求
- SilverStripe 3.1+
文档
已知限制
- 对于扩展,无法推理出
owner
属性的类型。你必须使用getOwner()
。相关问题:[#1043](https://github.com/phpstan/phpstan/issues/1043)和[#1044](https://github.com/phpstan/phpstan/issues/1044)
致谢
- Ondřej Mirtes 因其在PHPStan库上的出色工作
- Grant Lucas 因其对库的贡献,通过升级到PHPStan 0.9