You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would like to use arbitrary error messages for SlevomatCodingStandard.PHP.ForbiddenClasses.forbiddenClasses, because I want to tell a developer what to do instead, but it's not necessarily a "fixable" alternative. For example, say I have a class \SomeClass. It has no alternative, it's just supposed to be instantiated via a factory, e.g., \SomeClassFactory::create(). If I try to provide that detail, it breaks the fixer, which creates invalid PHP.
No message
With no message, the error is confusing an un-actionable:
<elementkey="SomeClass"value="null"/>
# The problem:newSomeClass('argument');
$ php vendor/bin/phpcs
------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
------------------------------------------------------
10 | ERROR | Usage of \SomeClass class is forbidden.
------------------------------------------------------
Arbitrary message
But a helpful, arbitrary message confuses the fixer, which assumes the value is a valid class:
<elementkey="SomeClass"value="I'm trying to be helpful by recommending SomeClassFactory::create()"/>
# The problem:newSomeClass('argument');
$ php vendor/bin/phpcs
--------------------------------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
--------------------------------------------------------------------------------------------------------------------------------------------
10 | ERROR | [x] Usage of \SomeClass class is forbidden, use \I'm trying to be helpful by recommending SomeClassFactory::create() instead.
--------------------------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------------------------------------------------------------------
$ php vendor/bin/phpcbf
...
# "Fixed":new I'm trying to be helpful by recommending SomeClassFactory::create()('argument');
Possible solution
If I could just disable the fixer for that one class element, that would solve the problem for me.
The text was updated successfully, but these errors were encountered:
I would like to use arbitrary error messages for
SlevomatCodingStandard.PHP.ForbiddenClasses.forbiddenClasses
, because I want to tell a developer what to do instead, but it's not necessarily a "fixable" alternative. For example, say I have a class\SomeClass
. It has no alternative, it's just supposed to be instantiated via a factory, e.g.,\SomeClassFactory::create()
. If I try to provide that detail, it breaks the fixer, which creates invalid PHP.No message
With no message, the error is confusing an un-actionable:
Arbitrary message
But a helpful, arbitrary message confuses the fixer, which assumes the value is a valid class:
Possible solution
If I could just disable the fixer for that one class element, that would solve the problem for me.
The text was updated successfully, but these errors were encountered: