coding-standard
coding-standard copied to clipboard
Is there a sniff to disallow "variable variable"?
Looking to disallow things like:
$$variable
With two dollar signs.
Thank you!
This should be super simple with custom phpstan rule:
use PhpParser\Node\Expr\Variable;
use PhpParser\Node;
use PHPStan\Analyser\Scope;
use PHPStan\Rules\Rule;
/**
* @implements Rule<Variable>
*/
class CamelCaseFieldNamingRule implements Rule
{
public function getNodeType(): string
{
return Variable::class;
}
/**
* @param Variable $node
* @return string[]
*/
public function processNode(Node $node, Scope $scope): array
{
if (!is_string($node->name)) {
return ['Expression for variable name is not allowed!'];
}
return [];
}
}
Thank you very much. Haven't got the chance to implement phpstan in my project yet! But I'm taking the note for when I do :)
Do you think this would be hard to implement as a PHPCS rule?
Do you think this would be hard to implement as a PHPCS rule?
No, it should be really simple sniff :)
I leave the feature request here, so! Thank you!
Btw, it's already implemented by phpstan strict rules
https://phpstan.org/r/2966deda-b4e9-4d76-ada9-2c9b6467c857
Implemented in https://github.com/slevomat/coding-standard/commit/43904bdc6c8f6d424cc75a582f47a52d68643081
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.