<commit_before><?php

/*
 * This file is part of the PHP CS utility.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * This source file is subject to the MIT license that is bundled
 * with this source code in the file LICENSE.
 */

namespace Symfony\CS\Fixer\PSR2;

use Symfony\CS\AbstractFixer;
use Symfony\CS\Tokenizer\Tokens;
use Symfony\CS\Tokenizer\Token;

/**
 * Fixer for rules defined in PSR2 ¶4.6.
 *
 * @author <NAME> <<EMAIL>>
 */
class FunctionCallSpaceFixer extends AbstractFixer
{
    /**
     * {@inheritdoc}
     */
    public function fix(\SplFileInfo $file, $content)
    {
        $tokens = Tokens::fromCode($content);

        $functionyTokens = $this->getFunctionyTokens();

        // iterate on the tokens
        for ($index = $tokens->count() - 1; $index >= 0; --$index) {
            $token = $tokens[$index];

            // looking for start brace
            if ($token->equals('(')) {
                // last non-witespace token
                $lastTokenIndex = $tokens->getPrevNonWhitespace($index);

                if (null === $lastTokenIndex) {
                    continue;
                }

                // check if it is a function call
                if ($tokens[$lastTokenIndex]->isGivenKind($functionyTokens)) {
                    $this->fixFunctionCall($tokens, $index);
                }
            }
        }

        return $tokens->generateCode();
    }

    /**
     * Fixes whitespaces around braces of a function(y) call.
     *
     * @param Tokens $tokens tokens to handle
     * @param int    $index  index of token
     *
     * @return none
     */
    private function fixFunctionCall(Tokens $tokens, $index)<commit_msg>FunctionCallSpaceFixer - simplify<commit_after><?php

/*
 * This file is part of the PHP CS utility.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * This source file is subject to the MIT license that is bundled
 * with this source code in the file LICENSE.
 */

namespace Symfony\CS\Fixer\PSR2;

use Symfony\CS\AbstractFixer;
use Symfony\CS\Tokenizer\Tokens;
use Symfony\CS\Tokenizer\Token;

/**
 * Fixer for rules defined in PSR2 ¶4.6.
 *
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 */
class FunctionCallSpaceFixer extends AbstractFixer
{
    /**
     * {@inheritdoc}
     */
    public function fix(\SplFileInfo $file, $content)
    {
        $tokens = Tokens::fromCode($content);

        $functionyTokens = $this->getFunctionyTokens();

        foreach ($tokens as $index => $token) {
            // looking for start brace
            if (!$token->equals('(')) {
                continue;
            }

            // last non-witespace token
            $lastTokenIndex = $tokens->getPrevNonWhitespace($index);

            if (null === $lastTokenIndex) {
                continue;
            }

            // check if it is a function call
            if ($tokens[$lastTokenIndex]->isGivenKind($functionyTokens)) {
                $this->fixFunctionCall($tokens, $index);
            }
        }

        return $tokens->generateCode();
    }

    /**
     * Fixes whitespaces around braces of a function(y) call.
     *
     * @param Tokens $tokens tokens to handle
     * @param int    $index  index of token
     *
     * @return none
     */
    private function fixFunctionCall(Tokens $tokens, $index)
{'fraction_non_alphanumeric': 0.1251903746573256, 'fraction_numerical': 0.003045994517209869, 'mean_word_length': 2.029520295202952, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 33, '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': '3306563', 'n_tokens_mistral': 974, 'n_tokens_neox': 947, 'n_words': 262}