2019-09-26 21:08:05 +02:00
|
|
|
<?php
|
2021-12-15 04:58:32 +01:00
|
|
|
|
2019-09-26 21:08:05 +02:00
|
|
|
namespace Psalm\Tests\FileManipulation;
|
|
|
|
|
2021-01-11 23:30:33 +01:00
|
|
|
class UnnecessaryVarAnnotationManipulationTest extends FileManipulationTestCase
|
2019-09-26 21:08:05 +02:00
|
|
|
{
|
2020-09-12 17:24:05 +02:00
|
|
|
public function providerValidCodeParse(): array
|
2019-09-26 21:08:05 +02:00
|
|
|
{
|
|
|
|
return [
|
|
|
|
'removeSingleLineVarAnnotation' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'input' => '<?php
|
2019-09-26 21:08:05 +02:00
|
|
|
function foo() : string {
|
|
|
|
return "hello";
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @var string */
|
2019-09-26 21:22:33 +02:00
|
|
|
$a = foo();
|
|
|
|
|
|
|
|
/** @var "a"|"b" */
|
|
|
|
$b = foo();',
|
2022-01-13 19:49:37 +01:00
|
|
|
'output' => '<?php
|
2019-09-26 21:22:33 +02:00
|
|
|
function foo() : string {
|
|
|
|
return "hello";
|
|
|
|
}
|
|
|
|
|
|
|
|
$a = foo();
|
|
|
|
|
|
|
|
/** @var "a"|"b" */
|
|
|
|
$b = foo();',
|
2022-01-13 19:49:37 +01:00
|
|
|
'php_version' => '5.6',
|
|
|
|
'issues_to_fix' => ['UnnecessaryVarAnnotation'],
|
|
|
|
'safe_types' => true,
|
2019-09-26 21:22:33 +02:00
|
|
|
],
|
2019-09-26 21:31:56 +02:00
|
|
|
'removeSingleLineVarAnnotationFlipped' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'input' => '<?php
|
2019-09-26 21:31:56 +02:00
|
|
|
function foo() : string {
|
|
|
|
return "hello";
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @var "a"|"b" */
|
|
|
|
$b = foo();
|
|
|
|
|
|
|
|
/** @var string */
|
|
|
|
$a = foo();',
|
2022-01-13 19:49:37 +01:00
|
|
|
'output' => '<?php
|
2019-09-26 21:31:56 +02:00
|
|
|
function foo() : string {
|
|
|
|
return "hello";
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @var "a"|"b" */
|
|
|
|
$b = foo();
|
|
|
|
|
|
|
|
$a = foo();',
|
2022-01-13 19:49:37 +01:00
|
|
|
'php_version' => '5.6',
|
|
|
|
'issues_to_fix' => ['UnnecessaryVarAnnotation'],
|
|
|
|
'safe_types' => true,
|
2019-09-26 21:31:56 +02:00
|
|
|
],
|
2019-09-26 21:22:33 +02:00
|
|
|
'removeSingleLineVarAnnotationAndType' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'input' => '<?php
|
2019-09-26 21:08:05 +02:00
|
|
|
function foo() : string {
|
|
|
|
return "hello";
|
|
|
|
}
|
|
|
|
|
2019-09-26 21:22:33 +02:00
|
|
|
/** @var string $a */
|
|
|
|
$a = foo();
|
|
|
|
|
|
|
|
/** @var "a"|"b" */
|
|
|
|
$b = foo();',
|
2022-01-13 19:49:37 +01:00
|
|
|
'output' => '<?php
|
2019-09-26 21:22:33 +02:00
|
|
|
function foo() : string {
|
|
|
|
return "hello";
|
|
|
|
}
|
|
|
|
|
|
|
|
$a = foo();
|
|
|
|
|
|
|
|
/** @var "a"|"b" */
|
|
|
|
$b = foo();',
|
2022-01-13 19:49:37 +01:00
|
|
|
'php_version' => '5.6',
|
|
|
|
'issues_to_fix' => ['UnnecessaryVarAnnotation'],
|
|
|
|
'safe_types' => true,
|
2019-09-26 21:08:05 +02:00
|
|
|
],
|
|
|
|
'removeMultipleLineVarAnnotation' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'input' => '<?php
|
2019-09-26 21:08:05 +02:00
|
|
|
function foo() : string {
|
|
|
|
return "hello";
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
2019-09-26 21:22:33 +02:00
|
|
|
$a = foo();
|
|
|
|
|
|
|
|
/** @var "a"|"b" */
|
|
|
|
$b = foo();',
|
2022-01-13 19:49:37 +01:00
|
|
|
'output' => '<?php
|
2019-09-26 21:08:05 +02:00
|
|
|
function foo() : string {
|
|
|
|
return "hello";
|
|
|
|
}
|
|
|
|
|
2019-09-26 21:22:33 +02:00
|
|
|
$a = foo();
|
|
|
|
|
|
|
|
/** @var "a"|"b" */
|
|
|
|
$b = foo();',
|
2022-01-13 19:49:37 +01:00
|
|
|
'php_version' => '5.6',
|
|
|
|
'issues_to_fix' => ['UnnecessaryVarAnnotation'],
|
|
|
|
'safe_types' => true,
|
2019-09-26 21:08:05 +02:00
|
|
|
],
|
|
|
|
'removeMultipleLineVarAnnotationKeepComment' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'input' => '<?php
|
2019-09-26 21:08:05 +02:00
|
|
|
function foo() : string {
|
|
|
|
return "hello";
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
* this comment should stay
|
|
|
|
*/
|
2019-09-26 21:22:33 +02:00
|
|
|
$a = foo();
|
|
|
|
|
|
|
|
/** @var "a"|"b" */
|
|
|
|
$b = foo();',
|
2022-01-13 19:49:37 +01:00
|
|
|
'output' => '<?php
|
2019-09-26 21:08:05 +02:00
|
|
|
function foo() : string {
|
|
|
|
return "hello";
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* this comment should stay
|
|
|
|
*/
|
2019-09-26 21:22:33 +02:00
|
|
|
$a = foo();
|
|
|
|
|
|
|
|
/** @var "a"|"b" */
|
|
|
|
$b = foo();',
|
2022-01-13 19:49:37 +01:00
|
|
|
'php_version' => '5.6',
|
|
|
|
'issues_to_fix' => ['UnnecessaryVarAnnotation'],
|
|
|
|
'safe_types' => true,
|
2019-09-26 21:22:33 +02:00
|
|
|
],
|
|
|
|
'removeMultipleLineVarAnnotationOnce' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'input' => '<?php
|
2019-09-26 21:22:33 +02:00
|
|
|
/** @return string[] */
|
|
|
|
function foo() : array {
|
|
|
|
return ["hello"];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var int $k
|
|
|
|
* @var string $v
|
|
|
|
*/
|
|
|
|
foreach (foo() as $k => $v) {}',
|
2022-01-13 19:49:37 +01:00
|
|
|
'output' => '<?php
|
2019-09-26 21:22:33 +02:00
|
|
|
/** @return string[] */
|
|
|
|
function foo() : array {
|
|
|
|
return ["hello"];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var int $k
|
|
|
|
*/
|
|
|
|
foreach (foo() as $k => $v) {}',
|
2022-01-13 19:49:37 +01:00
|
|
|
'php_version' => '5.6',
|
|
|
|
'issues_to_fix' => ['UnnecessaryVarAnnotation'],
|
|
|
|
'safe_types' => true,
|
2019-09-26 21:08:05 +02:00
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|