deeem/hexlet-psr-linter

View on GitHub
sniffs/VariablesNamingForLeadUnderscore.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php

namespace PsrLinter\Rules;

class VariablesNamingForLeadUnderscore extends CheckersTemplate implements RulesInterface
{
    public function check(\PhpParser\Node $node)
    {
        if (($node instanceof \PhpParser\Node\Expr\Variable ) &&
            (preg_match('/^_.+/', $node->name))) {
            $reason = "Property names SHOULD NOT be prefixed with a single " .
                      "underscore to indicate protected or private visibility.";
            $this->addError($node, 'error', $reason);
        }
    }
}