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