如何解决phpcs - 在 PHP 8 中提升构造函数时如何允许使用相同的行大括号
这是我关于 StackOverflow 的第一个问题。我为此感到非常高兴! ??
我想知道是否有一些 phpcs
配置可以覆盖相同的大括号规则。例如,当使用PHP 8 new constructor promotion feature时,在某些情况下我们不需要构造函数中的任何内容。因此,如果 phpcs
可以允许此代码,那就太好了:
/**
* UserService constructor
*
* @param UserRepository $userRepository
* @param BillingService $billingService
*/
public function __construct(
protected UserRepository $userRepository,protected BillingService $billingService
) {}
甚至那个:
/**
* BillingService constructor
*
* @param BillingRepository $billingRepository
*/
public function __construct(protected BillingRepository $billingRepository) {}
但它会引发警告,例如在 VS Code 中,“右大括号必须单独在一行上”。我不想禁用规则,只是在使用构造函数提升时自动允许异常。
phpcs.xml.dist
看起来像这样:
<?xml version="1.0" encoding="UTF-8"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd">
<rule ref="PSR1"/>
<rule ref="PSR2">
<exclude name="PSR1.Methods.CamelCapsMethodName"/>
</rule>
</ruleset>
有人知道如何实现吗?
感谢您的时间。 :)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。