我正在寻找一种自动化编码标准的方法,我决定在phpcs.xml文件中使用SlevomatCodingStandard.TypeHints.TypeHintDeclaration
。不幸的是,我们遇到了一个错误报告问题:
38 | ERROR | [ ] @var annotation of property
| | VC4AConvertUploadsToS3::$missing_local_files
| | does not specify type hint for its items.
45 | ERROR | [ ] @var annotation of property
| | VC4AConvertUploadsToS3::$missing_s3_files does
| | not specify type hint for its items.
52 | ERROR | [ ] @var annotation of property
| | VC4AConvertUploadsToS3::$updated_s3_links does
| | not specify type hint for its items.
66 | ERROR | [ ] @var annotation of property
| | VC4AConvertUploadsToS3::$s3_settings does not
| | specify type hint for its items.
112 | ERROR | [ ] Method VC4AConvertUploadsToS3::setup_crons()
| | does not have return type hint nor @return
| | annotation for its return value.
149 | ERROR | [ ] @return annotation of method
| | VC4AConvertUploadsToS3::get_cron_actions() does
| | not specify type hint for items of its traversable
| | return value.
202 | ERROR | [ ] @return annotation of method
| | VC4AConvertUploadsToS3::get_cron_intervals()
| | does not specify type hint for items of its
| | traversable return value.
266 | ERROR | [ ] @param annotation of method
| | VC4AConvertUploadsToS3::error_reporting() does
| | not specify type hint for items of its traversable
| | parameter $uploads.
334 | ERROR | [ ] @param annotation of method
| | VC4AConvertUploadsToS3::update_s3_link() does
| | not specify type hint for items of its traversable
| | parameter $upload.
336 | ERROR | [x] Method VC4AConvertUploadsToS3::update_s3_link()
| | does not have void return type hint.
我只想为方法添加严格的返回类型,但对于我们使用WordPress-Docs
标准的DocBlocks。
有没有办法禁用除最后一个错误之外的其余错误?
我试过的是:
<rule ref="SlevomatCodingStandard.TypeHints.TypeHintDeclaration">
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingParameterTypeHint"/>
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.enableEachParameterAndReturnInspection"/>
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.normalizedTraversableTypeHints"/>
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.normalizedUsefulAnnotations"/>
</rule>
显然,这没有任何效果。有什么建议吗?或者,只添加特定规则的正确方式是什么?
或者可以换一种方式吗?只需在规则集中添加特定规则而不修改代码库?
显然,我应该使用常量值而不是类数据成员名称:
<!-- Strict type return for methods -->
<rule ref="SlevomatCodingStandard.TypeHints.TypeHintDeclaration">
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingTraversableParameterTypeHintSpecification"/>
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingTraversablePropertyTypeHintSpecification"/>
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingTraversableReturnTypeHintSpecification"/>
</rule>
来源:https://github.com/slevomat/coding-standard/issues/570#issuecomment-448647567