This is my first question on StackOverflow. I'm very happy for that!
I would like to know if there's some phpcs
configuration that can override the same line braces rule. For example, when using PHP 8 new constructor promotion feature, in some cases we don't need any content in the constructor. So it would be nice if phpcs
could allow this code:
/**
* UserService constructor
*
* @param UserRepository $userRepository
* @param BillingService $billingService
*/
public function __construct(
protected UserRepository $userRepository,
protected BillingService $billingService
) {}
Or even that:
/**
* BillingService constructor
*
* @param BillingRepository $billingRepository
*/
public function __construct(protected BillingRepository $billingRepository) {}
But it raises the warning, in VS Code for example, "Closing brace must be on a line by itself". I don't want to disable the rule, just allow an exception automatically when using constructor promotion.
The phpcs.xml.dist
looks like this:
<?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>
Anyone knows how to achieve this?
Thanks for your time. :)