Skip to content

Commit

Permalink
Fix deprecated parameter order
Browse files Browse the repository at this point in the history
  • Loading branch information
sayuprc committed Mar 16, 2024
1 parent 6ad6fc9 commit b1b625d
Show file tree
Hide file tree
Showing 9 changed files with 139 additions and 12 deletions.
1 change: 1 addition & 0 deletions src/Rules/FunctionDefinitionCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ private function checkRequiredParameterAfterOptional(array $parameterNodes): arr
$optionalParameter,
),
)->line($parameterNode->getStartLine())->build();
$targetPhpVersion = null;
continue;
}
if ($parameterNode->default === null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ public function dataRequiredParameterAfterOptional(): array
"Anonymous function uses native union types but they're supported only on PHP 8.0 and later.",
19,
],
[
"Anonymous function uses native union types but they're supported only on PHP 8.0 and later.",
25,
],
],
],
[
Expand Down Expand Up @@ -129,6 +133,10 @@ public function dataRequiredParameterAfterOptional(): array
'Deprecated in PHP 8.0: Required parameter $bar follows optional parameter $foo.',
21,
],
[
'Deprecated in PHP 8.0: Required parameter $bar follows optional parameter $foo.',
25,
],
],
],
[
Expand Down Expand Up @@ -162,6 +170,14 @@ public function dataRequiredParameterAfterOptional(): array
'Deprecated in PHP 8.0: Required parameter $bar follows optional parameter $foo.',
21,
],
[
'Deprecated in PHP 8.0: Required parameter $bar follows optional parameter $foo.',
25,
],
[
'Deprecated in PHP 8.1: Required parameter $qux follows optional parameter $baz.',
25,
],
],
],
[
Expand Down Expand Up @@ -203,6 +219,18 @@ public function dataRequiredParameterAfterOptional(): array
'Deprecated in PHP 8.3: Required parameter $bar follows optional parameter $foo.',
23,
],
[
'Deprecated in PHP 8.0: Required parameter $bar follows optional parameter $foo.',
25,
],
[
'Deprecated in PHP 8.1: Required parameter $qux follows optional parameter $baz.',
25,
],
[
'Deprecated in PHP 8.3: Required parameter $quuz follows optional parameter $quux.',
25,
],
],
],
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ public function dataRequiredParameterAfterOptional(): array
"Anonymous function uses native union types but they're supported only on PHP 8.0 and later.",
33,
],
[
"Anonymous function uses native union types but they're supported only on PHP 8.0 and later.",
45,
],
],
],
[
Expand Down Expand Up @@ -173,6 +177,10 @@ public function dataRequiredParameterAfterOptional(): array
'Deprecated in PHP 8.0: Required parameter $bar follows optional parameter $foo.',
37,
],
[
'Deprecated in PHP 8.0: Required parameter $bar follows optional parameter $foo.',
45,
],
],
],
[
Expand Down Expand Up @@ -206,6 +214,14 @@ public function dataRequiredParameterAfterOptional(): array
'Deprecated in PHP 8.0: Required parameter $bar follows optional parameter $foo.',
37,
],
[
'Deprecated in PHP 8.0: Required parameter $bar follows optional parameter $foo.',
45,
],
[
'Deprecated in PHP 8.1: Required parameter $qux follows optional parameter $baz.',
45,
],
],
],
[
Expand Down Expand Up @@ -247,6 +263,18 @@ public function dataRequiredParameterAfterOptional(): array
'Deprecated in PHP 8.3: Required parameter $bar follows optional parameter $foo.',
41,
],
[
'Deprecated in PHP 8.0: Required parameter $bar follows optional parameter $foo.',
45,
],
[
'Deprecated in PHP 8.1: Required parameter $qux follows optional parameter $baz.',
45,
],
[
'Deprecated in PHP 8.3: Required parameter $quuz follows optional parameter $quux.',
45,
],
],
],
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,10 @@ public function dataRequiredParameterAfterOptional(): array
"Function RequiredAfterOptional\doConsectetur() uses native union types but they're supported only on PHP 8.0 and later.",
38,
],
[
"Function RequiredAfterOptional\doSed() uses native union types but they're supported only on PHP 8.0 and later.",
38,
],
],
],
[
Expand Down Expand Up @@ -254,6 +258,10 @@ public function dataRequiredParameterAfterOptional(): array
'Deprecated in PHP 8.0: Required parameter $bar follows optional parameter $foo.',
42,
],
[
'Deprecated in PHP 8.0: Required parameter $bar follows optional parameter $foo.',
50,
],
],
],
[
Expand Down Expand Up @@ -287,6 +295,14 @@ public function dataRequiredParameterAfterOptional(): array
'Deprecated in PHP 8.0: Required parameter $bar follows optional parameter $foo.',
42,
],
[
'Deprecated in PHP 8.0: Required parameter $bar follows optional parameter $foo.',
50,
],
[
'Deprecated in PHP 8.1: Required parameter $qux follows optional parameter $bar.',
50,
],
],
],
[
Expand Down Expand Up @@ -328,6 +344,18 @@ public function dataRequiredParameterAfterOptional(): array
'Deprecated in PHP 8.3: Required parameter $bar follows optional parameter $foo.',
46,
],
[
'Deprecated in PHP 8.0: Required parameter $bar follows optional parameter $foo.',
50,
],
[
'Deprecated in PHP 8.1: Required parameter $qux follows optional parameter $bar.',
50,
],
[
'Deprecated in PHP 8.2: Required parameter $quuz follows optional parameter $quux.',
50,
],
],
],
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@
fn (mixed $foo = 1, $bar): int => 1; // not OK

fn (mixed $foo = null, $bar): int => 1; // not OK

fn (int $foo = 1, $bar, ?int $baz = null, $qux, int|null $quux, $quuz): int => 1; // not OK
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,7 @@ function (mixed $foo = 1, $bar): void // not OK
function (mixed $foo = null, $bar): void // not OK
{
};

function (int $foo = 1, $bar, ?int $baz = null, $qux, int|null $quux, $quuz): void // not OK
{
};
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,7 @@ function doAdipiscing(mixed $foo = 1, $bar): void // not OK
function doElit(mixed $foo = null, $bar): void // not OK
{
}

function doSed(int $foo = 1, $bar, ?int $baz = null, $qux, int|null $quux, $quuz): void // not OK
{
}
28 changes: 28 additions & 0 deletions tests/PHPStan/Rules/Methods/ExistingClassesInTypehintsRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,10 @@ public function dataRequiredParameterAfterOptional(): array
"Method RequiredAfterOptional\Foo::doConsectetur() uses native union types but they're supported only on PHP 8.0 and later.",
37,
],
[
"Method RequiredAfterOptional\Foo::doSed() uses native union types but they're supported only on PHP 8.0 and later.",
49,
],
],
],
[
Expand Down Expand Up @@ -248,6 +252,10 @@ public function dataRequiredParameterAfterOptional(): array
'Deprecated in PHP 8.0: Required parameter $bar follows optional parameter $foo.',
41,
],
[
'Deprecated in PHP 8.0: Required parameter $bar follows optional parameter $foo.',
49,
],
],
],
[
Expand Down Expand Up @@ -281,6 +289,14 @@ public function dataRequiredParameterAfterOptional(): array
'Deprecated in PHP 8.0: Required parameter $bar follows optional parameter $foo.',
41,
],
[
'Deprecated in PHP 8.0: Required parameter $bar follows optional parameter $foo.',
49,
],
[
'Deprecated in PHP 8.1: Required parameter $qux follows optional parameter $baz.',
49,
],
],
],
[
Expand Down Expand Up @@ -322,6 +338,18 @@ public function dataRequiredParameterAfterOptional(): array
'Deprecated in PHP 8.3: Required parameter $bar follows optional parameter $foo.',
45,
],
[
'Deprecated in PHP 8.0: Required parameter $bar follows optional parameter $foo.',
49,
],
[
'Deprecated in PHP 8.1: Required parameter $qux follows optional parameter $baz.',
49,
],
[
'Deprecated in PHP 8.2: Required parameter $quuz follows optional parameter $quux.',
49,
],
],
],
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,23 @@ public function doSit(?int $foo = null, $bar): void // not OK
{
}

public function doAmet(int|null $foo = 1, $bar): void // not OK
{
}
public function doAmet(int|null $foo = 1, $bar): void // not OK
{
}

public function doConsectetur(int|null $foo = null, $bar): void // not OK
{
}
public function doConsectetur(int|null $foo = null, $bar): void // not OK
{
}

public function doAdipiscing(mixed $foo = 1, $bar): void // not OK
{
}
public function doAdipiscing(mixed $foo = 1, $bar): void // not OK
{
}

public function doElit(mixed $foo = null, $bar): void // not OK
{
}
public function doElit(mixed $foo = null, $bar): void // not OK
{
}

public function doSed(int $foo = 1, $bar, ?int $baz = null, $qux, int|null $quux, $quuz): void // not OK
{
}
}

0 comments on commit b1b625d

Please sign in to comment.