Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
NoWhitespaceBeforeCommaInArrayFixer - fix comma after heredoc-end (ph…
…p 7.3)
  • Loading branch information
gharlan committed Jan 1, 2019
1 parent 0b17fc3 commit 8f7ba7f
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -96,7 +96,7 @@ jobs:
php: 7.3
env: COMPOSER_FLAGS="--ignore-platform-reqs" PHP_CS_FIXER_IGNORE_ENV=1 SYMFONY_DEPRECATIONS_HELPER=weak
before_script:
- php php-cs-fixer fix --rules @PHP71Migration,@PHP71Migration:risky,blank_line_after_opening_tag -q || travis_terminate 1
- php php-cs-fixer fix --rules @PHP71Migration,@PHP71Migration:risky,blank_line_after_opening_tag,no_whitespace_before_comma_in_array -q || travis_terminate 1

-
<<: *STANDARD_TEST_JOB
Expand Down
Expand Up @@ -74,7 +74,11 @@ private function fixSpacing($index, Tokens $tokens)
$i = $this->skipNonArrayElements($i, $tokens);
$currentToken = $tokens[$i];
$prevIndex = $tokens->getPrevNonWhitespace($i - 1);
if ($currentToken->equals(',') && !$tokens[$prevIndex]->equals([T_END_HEREDOC]) && !$tokens[$prevIndex]->isComment()) {

if (
$currentToken->equals(',') && !$tokens[$prevIndex]->isComment() &&
(\PHP_VERSION_ID >= 70300 || !$tokens[$prevIndex]->equals([T_END_HEREDOC]))
) {
$tokens->removeLeadingWhitespace($i);
}
}
Expand Down
Expand Up @@ -129,9 +129,60 @@ public function provideFixCases()
123,
);',
],
];
}

/**
* @param string $expected
* @param null|string $input
*
* @dataProvider provideFixLower73Cases
* @requires PHP <7.3
*/
public function testFixLower73($expected, $input = null)
{
$this->doTest($expected, $input);
}

public function provideFixLower73Cases()
{
return [
[
"<?php \$x = array(<<<'EOF'
<?php \$a = '\\foo\\bar\\\\';
EOF
, <<<'EOF'
<?php \$a = \"\\foo\\bar\\\\\";
EOF
);",
],
];
}

/**
* @param string $expected
* @param null|string $input
*
* @dataProvider provideFix73Cases
* @requires PHP 7.3
*/
public function testFix73($expected, $input = null)
{
$this->doTest($expected, $input);
}

public function provideFix73Cases()
{
return [
[
"<?php \$x = array(<<<'EOF'
<?php \$a = '\\foo\\bar\\\\';
EOF, <<<'EOF'
<?php \$a = \"\\foo\\bar\\\\\";
EOF
);",
"<?php \$x = array(<<<'EOF'
<?php \$a = '\\foo\\bar\\\\';
EOF
, <<<'EOF'
<?php \$a = \"\\foo\\bar\\\\\";
Expand Down
18 changes: 18 additions & 0 deletions tests/Fixtures/Integration/misc/PHP7_3.test
Expand Up @@ -6,6 +6,7 @@ PHP 7.3 test.
"@PHP71Migration:risky": true,
"@Symfony": true,
"@Symfony:risky": true,
"heredoc_indentation": true,
"list_syntax": {"syntax":"short"},
"mb_str_functions": true,
"multiline_whitespace_before_semicolons": true,
Expand Down Expand Up @@ -55,6 +56,14 @@ final class MyTest extends \PHPUnit_Framework_TestCase
random_int($a, $b, ); // `random_api_migration` rule
foo(null === $a, ); // `yoda_style` rule

// https://wiki.php.net/rfc/flexible_heredoc_nowdoc_syntaxes
$a = [<<<'EOD'
foo
EOD, <<<'EOD'
bar
EOD
];

--INPUT--
<?php

Expand Down Expand Up @@ -92,3 +101,12 @@ final class MyTest extends \PHPUnit_Framework_TestCase
}
rand($a, $b, ); // `random_api_migration` rule
foo($a === null, ); // `yoda_style` rule

// https://wiki.php.net/rfc/flexible_heredoc_nowdoc_syntaxes
$a = [<<<'EOD'
foo
EOD
, <<<'EOD'
bar
EOD
];

0 comments on commit 8f7ba7f

Please sign in to comment.