2020-08-14 21:25:21 +02:00
|
|
|
<?php
|
2021-12-15 04:58:32 +01:00
|
|
|
|
2020-08-14 21:25:21 +02:00
|
|
|
namespace Psalm\Tests\FileManipulation;
|
|
|
|
|
2021-01-11 23:30:33 +01:00
|
|
|
class ParamNameMismatchTest extends FileManipulationTestCase
|
2020-08-14 21:25:21 +02:00
|
|
|
{
|
2020-09-12 17:24:05 +02:00
|
|
|
public function providerValidCodeParse(): array
|
2020-08-14 21:25:21 +02:00
|
|
|
{
|
|
|
|
return [
|
|
|
|
'fixMismatchingParamName74' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'input' => '<?php
|
2020-08-14 21:25:21 +02:00
|
|
|
class A {
|
|
|
|
public function foo(string $str, bool $b = false) : void {}
|
|
|
|
}
|
|
|
|
|
|
|
|
class AChild extends A {
|
|
|
|
public function foo(string $string, bool $b = false) : void {
|
|
|
|
$str = $string;
|
|
|
|
$string = $string === "hello" ? "foo" : "bar";
|
|
|
|
echo $string;
|
|
|
|
echo $str;
|
|
|
|
}
|
|
|
|
}',
|
2022-01-13 19:49:37 +01:00
|
|
|
'output' => '<?php
|
2020-08-14 21:25:21 +02:00
|
|
|
class A {
|
|
|
|
public function foo(string $str, bool $b = false) : void {}
|
|
|
|
}
|
|
|
|
|
|
|
|
class AChild extends A {
|
|
|
|
public function foo(string $str, bool $b = false) : void {
|
|
|
|
$str_new = $str;
|
|
|
|
$str = $str === "hello" ? "foo" : "bar";
|
|
|
|
echo $str;
|
|
|
|
echo $str_new;
|
|
|
|
}
|
|
|
|
}',
|
2022-01-13 19:49:37 +01:00
|
|
|
'php_version' => '7.1',
|
|
|
|
'issues_to_fix' => ['ParamNameMismatch'],
|
|
|
|
'safe_types' => true,
|
2020-08-14 21:25:21 +02:00
|
|
|
],
|
|
|
|
'fixIfNewNameAlreadyExists74' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'input' => '<?php
|
2020-08-14 21:25:21 +02:00
|
|
|
class A {
|
|
|
|
public function foo(string $str, bool $b = false) : void {}
|
|
|
|
}
|
|
|
|
|
|
|
|
class AChild extends A {
|
|
|
|
public function foo(string $string, bool $b = false) : void {
|
|
|
|
$str_new = $string;
|
|
|
|
}
|
|
|
|
}',
|
2022-01-13 19:49:37 +01:00
|
|
|
'output' => '<?php
|
2020-08-14 21:25:21 +02:00
|
|
|
class A {
|
|
|
|
public function foo(string $str, bool $b = false) : void {}
|
|
|
|
}
|
|
|
|
|
|
|
|
class AChild extends A {
|
|
|
|
public function foo(string $str, bool $b = false) : void {
|
|
|
|
$str_new = $str;
|
|
|
|
}
|
|
|
|
}',
|
2022-01-13 19:49:37 +01:00
|
|
|
'php_version' => '7.1',
|
|
|
|
'issues_to_fix' => ['ParamNameMismatch'],
|
|
|
|
'safe_types' => true,
|
2020-08-14 21:25:21 +02:00
|
|
|
],
|
|
|
|
'noFixIfNewNameAndOldNameAlreadyExists74' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'input' => '<?php
|
2020-08-14 21:25:21 +02:00
|
|
|
class A {
|
|
|
|
public function foo(string $str, bool $b = false) : void {}
|
|
|
|
}
|
|
|
|
|
|
|
|
class AChild extends A {
|
|
|
|
public function foo(string $string, bool $b = false) : void {
|
|
|
|
$str = $string;
|
|
|
|
$str_new = $string;
|
|
|
|
}
|
|
|
|
}',
|
2022-01-13 19:49:37 +01:00
|
|
|
'output' => '<?php
|
2020-08-14 21:25:21 +02:00
|
|
|
class A {
|
|
|
|
public function foo(string $str, bool $b = false) : void {}
|
|
|
|
}
|
|
|
|
|
|
|
|
class AChild extends A {
|
|
|
|
public function foo(string $string, bool $b = false) : void {
|
|
|
|
$str = $string;
|
|
|
|
$str_new = $string;
|
|
|
|
}
|
|
|
|
}',
|
2022-01-13 19:49:37 +01:00
|
|
|
'php_version' => '7.1',
|
|
|
|
'issues_to_fix' => ['ParamNameMismatch'],
|
|
|
|
'safe_types' => true,
|
2020-08-14 21:25:21 +02:00
|
|
|
],
|
2020-08-14 22:26:55 +02:00
|
|
|
'fixMismatchingParamNameWithDocblockType74' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'input' => '<?php
|
2020-08-14 22:26:55 +02:00
|
|
|
class A {
|
|
|
|
/**
|
|
|
|
* @param string $str
|
|
|
|
*/
|
|
|
|
public function foo($str, bool $b = false) : void {}
|
|
|
|
}
|
|
|
|
|
|
|
|
class AChild extends A {
|
|
|
|
/**
|
|
|
|
* @param string $string
|
|
|
|
*/
|
|
|
|
public function foo($string, bool $b = false) : void {}
|
|
|
|
}',
|
2022-01-13 19:49:37 +01:00
|
|
|
'output' => '<?php
|
2020-08-14 22:26:55 +02:00
|
|
|
class A {
|
|
|
|
/**
|
|
|
|
* @param string $str
|
|
|
|
*/
|
|
|
|
public function foo($str, bool $b = false) : void {}
|
|
|
|
}
|
|
|
|
|
|
|
|
class AChild extends A {
|
|
|
|
/**
|
|
|
|
* @param string $str
|
|
|
|
*/
|
|
|
|
public function foo($str, bool $b = false) : void {}
|
|
|
|
}',
|
2022-01-13 19:49:37 +01:00
|
|
|
'php_version' => '7.1',
|
|
|
|
'issues_to_fix' => ['ParamNameMismatch'],
|
|
|
|
'safe_types' => true,
|
2020-08-14 22:26:55 +02:00
|
|
|
],
|
2020-08-14 21:25:21 +02:00
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|