<commit_before><?php

declare(strict_types=1);

namespace ShopSys\CodingStandards\Sniffs;

use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Sniffs\AbstractVariableSniff;
use PHP_CodeSniffer\Util\Common;

final class CamelCaseParameterSniff extends AbstractVariableSniff
{
    /**
     * @var string
     */
    private const NOT_LETTER_THEN_LETTER_PATTERN = '([^a-zA-Z]{1}(?<nextLetter>[A-Za-z]{1}))';

    /**
     * @param int $position
     */
    protected function processVariable(File $file, $position): void
    {
        $currentToken = $file->getTokens()[$position];

        $variableName = ltrim($currentToken['content'], '$');
        if (Common::isCamelCaps($variableName)) {
            return;
        }

        $fix = $file->addFixableError(sprintf(
            'Variable "$%s" should be camel case',
            $variableName
        ), $position, self::class);

        if ($fix) {
            $this->fixVariableName($file, $position, $variableName);
        }
    }

    /**
     * @param int $position
     */
    protected function processVariableInString(File $file, $position): void
    {
    }

    /**
     * @param int $position
     */
    protected function processMemberVar(File $file, $position): void
    {
    }

    /**
     * Changes:
     * _someVariable => someVariable
     * some_variable => someVariable
     */
    private function fixVariableName(File $file, int $position, string $variableName): void
    {
        $newVariableName = preg_replace_callback(
            '#(?<prefixLetter>[a-z]{1})?' . self::NOT_LETTER_THEN_LETTER_PATTERN . '#',
            function (array $match): string {
                $isFirstLetter = !(bool)$match['prefixLetter'];
                if ($isFirstLetter) {
                    return $match['nextLetter'];
                }

                return $match['prefixLetter'] . strtoupper($match['nextLetter']);
            },
            $variableName
        );

        $file->fixer->replaceToken($position, '$' . $newVariableName);
    }
}<commit_msg>remove fix ability from CamelCaseParameterSniff, not working propperly<commit_after><?php

declare(strict_types=1);

namespace ShopSys\CodingStandards\Sniffs;

use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Sniffs\AbstractVariableSniff;
use PHP_CodeSniffer\Util\Common;

final class CamelCaseParameterSniff extends AbstractVariableSniff
{
    /**
     * @param int $position
     */
    protected function processVariable(File $file, $position): void
    {
        $currentToken = $file->getTokens()[$position];

        $variableName = ltrim($currentToken['content'], '$');
        if (Common::isCamelCaps($variableName)) {
            return;
        }

        $file->addError(sprintf(
            'Variable "$%s" should be camel case',
            $variableName
        ), $position, self::class);
    }

    /**
     * @param int $position
     */
    protected function processVariableInString(File $file, $position): void
    {
    }

    /**
     * @param int $position
     */
    protected function processMemberVar(File $file, $position): void
    {
    }
}
{'fraction_non_alphanumeric': 0.13301127214170694, 'fraction_numerical': 0.001610305958132045, 'mean_word_length': 2.545662100456621, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7574397', 'n_tokens_mistral': 929, 'n_tokens_neox': 902, 'n_words': 171}