Skip to content

Commit

Permalink
Merge c6c2e13 into 00724a1
Browse files Browse the repository at this point in the history
  • Loading branch information
OndraM committed Jan 4, 2022
2 parents 00724a1 + c6c2e13 commit 6a6c376
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 29 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -5,6 +5,7 @@
<!-- There is always Unreleased section on the top. Subsections (Added, Changed, Fixed, Removed) should be added as needed. -->

## Unreleased
- Fix SpecifyArgSeparatorFixer type error when adding empty `$numeric_prefix` parameter in PHP 7.4+.

## 3.2.0 - 2021-05-20
- Fix SpecifyArgSeparatorFixer not compatible with php-cs-fixer 3.0.
Expand Down
8 changes: 6 additions & 2 deletions src/Fixer/SpecifyArgSeparatorFixer.php
Expand Up @@ -81,7 +81,11 @@ private function fixFunction(Tokens $tokens, int $functionIndex): void

// When third argument is already present and it is null, override its value.
if ($argumentCount >= 3) {
$thirdArgumentTuple = $this->getThirdArgumentTokenTuple($tokens, $openParenthesisIndex, $closeParenthesisIndex);
$thirdArgumentTuple = $this->getThirdArgumentTokenTuple(
$tokens,
$openParenthesisIndex,
$closeParenthesisIndex
);
if ($thirdArgumentTuple === []) {
return;
}
Expand All @@ -100,7 +104,7 @@ private function fixFunction(Tokens $tokens, int $functionIndex): void
if ($argumentCount === 1) {
$tokensToInsert[] = new Token(',');
$tokensToInsert[] = new Token([T_WHITESPACE, ' ']);
$tokensToInsert[] = new Token([T_STRING, 'null']);
$tokensToInsert[] = new Token([T_STRING, "''"]);
}

// Add third argument (arg separator): ", '&'"
Expand Down
16 changes: 8 additions & 8 deletions tests/Fixer/Fixtures/Correct.php.inc
Expand Up @@ -6,20 +6,20 @@ class Correct
{
public function assembleQueryString(): void
{
$queryString1 = http_build_query(['foo' => 'bar'], null, '&');
$queryString1 = http_build_query(['foo' => 'bar'], '', '&');

$queryString1WithMultipleWhitespaces = http_build_query(['foo' => 'bar'], null, '&');
$queryString1WithMultipleWhitespaces = http_build_query(['foo' => 'bar'], 'prefix', '&');

$queryString1WithWhitespacesAndComments = http_build_query(['foo' => 'bar'], null, /* comment */ '&' /* x */);
$queryString1WithWhitespacesAndComments = http_build_query(['foo' => 'bar'], '', /* comment */ '&' /* x */);

$queryString1WithComment = http_build_query(['foo' => 'bar'], /* Comment, with commas, */ null , '&');
$queryString1WithComment = http_build_query(['foo' => 'bar'], /* Comment, with commas, */ '' , '&');

$queryString1WithObject = http_build_query((object) ['foo' => 'bar'], null, '&');
$queryString1WithObject = http_build_query((object) ['foo' => 'bar'], '', '&');

$queryString2 = http_build_query(['foo' => 'bar', 'baz' => 'bat'], null, '&');
$queryString2 = http_build_query(['foo' => 'bar', 'baz' => 'bat'], '', '&');

$queryString3 = http_build_query(['foo' => 'bar'], null, '&amp;');
$queryString3 = http_build_query(['foo' => 'bar'], '', '&amp;');

$queryString4 = http_build_query(['foo' => 'bar'], null, ';');
$queryString4 = http_build_query(['foo' => 'bar'], '', ';');
}
}
27 changes: 17 additions & 10 deletions tests/Fixer/Fixtures/Fixed.php.inc
@@ -1,23 +1,30 @@
<?php declare(strict_types=1);

function http_build_query($should, $not, $change): void
{
// this should not be affected
/**
* The function declaration should not be affected
*/
function http_build_query(
$data, // TODO: array|object in PHP 8.0+
string $numeric_prefix = '',
?string $arg_separator = null,
int $encoding_type = PHP_QUERY_RFC1738
): string {
return 'foo';
}

function assembleQueryString(): void
{
$queryString1 = http_build_query(['foo' => 'bar'], null, '&');
$queryString1 = http_build_query(['foo' => 'bar'], '', '&');

$queryString2 = http_build_query(['foo' => 'bar'], 333, '&');
$queryString2 = http_build_query(['foo' => 'bar'], '', '&');

$queryString3 = http_build_query(['foo' => 'bar'], 333, '&');
$queryString3 = http_build_query(['foo' => 'bar'], '', '&');

$queryString4 = http_build_query(['foo' => 'bar'], 333, '&', PHP_QUERY_RFC3986);
$queryString4 = http_build_query(['foo' => 'bar'], '', '&', PHP_QUERY_RFC3986);

$queryString5 = http_build_query(['foo' => 'bar'], null, '&', PHP_QUERY_RFC3986);
$queryString5 = http_build_query(['foo' => 'bar'], 'prefix', '&', PHP_QUERY_RFC3986);

$queryString6 = http_build_query(['foo' => 'bar', 'baz' => 'ban'], null, '&', PHP_QUERY_RFC3986);
$queryString6 = http_build_query(['foo' => 'bar', 'baz' => 'ban'], '', '&', PHP_QUERY_RFC3986);

$queryString6 = http_build_query((object) ['foo' => 'bar', 'baz' => 'ban'], null, '&', PHP_QUERY_RFC3986);
$queryString7 = http_build_query((object) ['foo' => 'bar', 'baz' => 'ban'], '', '&', PHP_QUERY_RFC3986);
}
25 changes: 16 additions & 9 deletions tests/Fixer/Fixtures/Wrong.php.inc
@@ -1,23 +1,30 @@
<?php declare(strict_types=1);

function http_build_query($should, $not, $change): void
{
// this should not be affected
/**
* The function declaration should not be affected
*/
function http_build_query(
$data, // TODO: array|object in PHP 8.0+
string $numeric_prefix = '',
?string $arg_separator = null,
int $encoding_type = PHP_QUERY_RFC1738
): string {
return 'foo';
}

function assembleQueryString(): void
{
$queryString1 = http_build_query(['foo' => 'bar']);

$queryString2 = http_build_query(['foo' => 'bar'], 333);
$queryString2 = http_build_query(['foo' => 'bar'], '');

$queryString3 = http_build_query(['foo' => 'bar'], 333, null);
$queryString3 = http_build_query(['foo' => 'bar'], '', null);

$queryString4 = http_build_query(['foo' => 'bar'], 333, null, PHP_QUERY_RFC3986);
$queryString4 = http_build_query(['foo' => 'bar'], '', null, PHP_QUERY_RFC3986);

$queryString5 = http_build_query(['foo' => 'bar'], null, null, PHP_QUERY_RFC3986);
$queryString5 = http_build_query(['foo' => 'bar'], 'prefix', null, PHP_QUERY_RFC3986);

$queryString6 = http_build_query(['foo' => 'bar', 'baz' => 'ban'], null, null, PHP_QUERY_RFC3986);
$queryString6 = http_build_query(['foo' => 'bar', 'baz' => 'ban'], '', null, PHP_QUERY_RFC3986);

$queryString6 = http_build_query((object) ['foo' => 'bar', 'baz' => 'ban'], null, null, PHP_QUERY_RFC3986);
$queryString7 = http_build_query((object) ['foo' => 'bar', 'baz' => 'ban'], '', null, PHP_QUERY_RFC3986);
}

0 comments on commit 6a6c376

Please sign in to comment.