Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix deprecated warning version display #2971

Merged
merged 1 commit into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 $quuz follows optional parameter $quux.',
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.1: Required parameter $qux follows optional parameter $baz.',
25,
],
[
'Deprecated in PHP 8.0: Required parameter $quuz follows optional parameter $quux.',
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.3: 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.0: 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 $quuz follows optional parameter $quux.',
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.1: Required parameter $qux follows optional parameter $baz.',
45,
],
[
'Deprecated in PHP 8.0: Required parameter $quuz follows optional parameter $quux.',
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.3: 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.0: 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.",
50,
],
],
],
[
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 $quuz follows optional parameter $quux.',
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.1: Required parameter $qux follows optional parameter $baz.',
50,
],
[
'Deprecated in PHP 8.0: Required parameter $quuz follows optional parameter $quux.',
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.3: Required parameter $bar follows optional parameter $foo.',
50,
],
[
'Deprecated in PHP 8.1: Required parameter $qux follows optional parameter $baz.',
50,
],
[
'Deprecated in PHP 8.0: 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|null $foo = null, $bar, ?int $baz = null, $qux, int $quux = 1, $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|null $foo = null, $bar, ?int $baz = null, $qux, int $quux = 1, $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|null $foo = null, $bar, ?int $baz = null, $qux, int $quux = 1, $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 $quuz follows optional parameter $quux.',
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.1: Required parameter $qux follows optional parameter $baz.',
49,
],
[
'Deprecated in PHP 8.0: Required parameter $quuz follows optional parameter $quux.',
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.3: 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.0: 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|null $foo = null, $bar, ?int $baz = null, $qux, int $quux = 1, $quuz): void // not OK
{
}
}