PHP code example of deeem / hexlet-psr-linter

1. Go to this page and download the library: Download deeem/hexlet-psr-linter library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

deeem / hexlet-psr-linter example snippets



$code = file_get_contents('tests/fixtures/sniffs/variablesNamingForLeadingUnderscore.wrong.php');




namespace PsrLinter\Rules;

class VariablesNamingForCamelCase extends FixersTemplate implements RulesInterface
{
    public function check(\PhpParser\Node $node)
    {
        if (( $node instanceof \PhpParser\Node\Expr\Variable ) &&
            (!preg_match('/^[a-z]+([A-Z]?[a-z]+)+$/', $node->name))) {
            $this->addError($node, 'error', 'Names MUST be declared in camelCase.');

            return true;
        }
    }

    public function fix(\PhpParser\Node $node)
    {
        $camelize = function ($word) {
            $allWordsAreUpperCased = implode(array_map(function ($word) {
                return ucfirst(strtolower($word));
            }, explode('_', $word)));

            return lcfirst($allWordsAreUpperCased);
        };

        $node->name = $camelize($node->name);
    }
}