src/Fixer/FunctionNotation/MethodArgumentSpaceFixer.php
private function fixSpace2(Tokens $tokens, $index)
    {
        // remove space before comma if exist
        if ($tokens[$index - 1]->isWhitespace()) {
            $prevIndex = $tokens->getPrevNonWhitespace($index - 1);

            if (!$tokens[$prevIndex]->equalsAny([',', [T_END_HEREDOC]]) && !$tokens[$prevIndex]->isComment()) {
                $tokens->clearAt($index - 1);
            }
        }

        $nextIndex = $index + 1;
        $nextToken = $tokens[$nextIndex];

        // Two cases for fix space after comma (exclude multiline comments)
        //  1) multiple spaces after comma
        //  2) no space after comma
        if ($nextToken->isWhitespace()) {
            $newContent = $nextToken->getContent();

            if ('ensure_single_line' === $this->configuration['on_multiline']) {
                $newContent = Preg::replace('/\R/', '', $newContent);
            }

            if (
                (!$this->configuration['keep_multiple_spaces_after_comma'] || Preg::match('/\R/', $newContent))
                && !$this->isCommentLastLineToken($tokens, $index + 2)
            ) {
                $newContent = ltrim($newContent, " \t");
            }

            $tokens[$nextIndex] = new Token([T_WHITESPACE, '' === $newContent ? ' ' : $newContent]);

            return;
        }

        if (!$this->isCommentLastLineToken($tokens, $index + 1)) {
            $tokens->insertAt($index + 1, new Token([T_WHITESPACE, ' ']));
        }
    }
private function fixSpace2(Tokens $tokens, $index)
    {
        // remove space before comma if exist
        if ($tokens[$index - 1]->isWhitespace()) {
            $prevIndex = $tokens->getPrevNonWhitespace($index - 1);

            if (!$tokens[$prevIndex]->equalsAny([',', [T_END_HEREDOC]]) && !$tokens[$prevIndex]->isComment()) {
                $tokens->clearAt($index - 1);
            }
        }

        $nextIndex = $index + 1;
        $nextToken = $tokens[$nextIndex];

        // Two cases for fix space after comma (exclude multiline comments)
        //  1) multiple spaces after comma
        //  2) no space after comma
        if ($nextToken->isWhitespace()) {
            $newContent = $nextToken->getContent();

            if ('ensure_single_line' === $this->configuration['on_multiline']) {
                $newContent = Preg::replace('/\R/', '', $newContent);
            }

            if (
                (!$this->configuration['keep_multiple_spaces_after_comma'] || Preg::match('/\R/', $newContent))
                && !$this->isCommentLastLineToken($tokens, $index + 2)
            ) {
                $newContent = ltrim($newContent, " \t");
            }

            $tokens[$nextIndex] = new Token([T_WHITESPACE, '' === $newContent ? ' ' : $newContent]);

            return;
        }

        if (!$this->isCommentLastLineToken($tokens, $index + 1)) {
            $tokens->insertAt($index + 1, new Token([T_WHITESPACE, ' ']));
        }
    }
private function fixSpace2 ( Tokens $ tokens , $ index ) { // remove space before comma if exist if ( $ tokens [ $ index - 1 ] -> isWhitespace ( ) ) { $ prevIndex = $ tokens -> getPrevNonWhitespace ( $ index - 1 ) ; if ( ! $ tokens [ $ prevIndex ] -> equalsAny ( [ ',' , [ T_END_HEREDOC ] ] ) && ! $ tokens [ $ prevIndex ] -> isComment ( ) ) { $ tokens -> clearAt ( $ index - 1 ) ; } } $ nextIndex = $ index + 1 ; $ nextToken = $ tokens [ $ nextIndex ] ; // Two cases for fix space after comma (exclude multiline comments) //  1) multiple spaces after comma //  2) no space after comma if ( $ nextToken -> isWhitespace ( ) ) { $ newContent = $ nextToken -> getContent ( ) ; if ( 'ensure_single_line' === $ this -> configuration [ 'on_multiline' ] ) { $ newContent = Preg :: replace ( '/\R/' , '' , $ newContent ) ; } if ( ( ! $ this -> configuration [ 'keep_multiple_spaces_after_comma' ] || Preg :: match ( '/\R/' , $ newContent ) ) && ! $ this -> isCommentLastLineToken ( $ tokens , $ index + 2 ) ) { $ newContent = ltrim ( $ newContent , " \t" ) ; } $ tokens [ $ nextIndex ] = new Token ( [ T_WHITESPACE , '' === $ newContent ? ' ' : $ newContent ] ) ; return ; } if ( ! $ this -> isCommentLastLineToken ( $ tokens , $ index + 1 ) ) { $ tokens -> insertAt ( $ index + 1 , new Token ( [ T_WHITESPACE , ' ' ] ) ) ; } }
Method to insert space after comma and remove space before comma.

@param Tokens $tokens
@param int    $index
Method to insert space after comma and remove space before comma .