mirror of
https://github.com/danog/psalm.git
synced 2024-12-14 10:17:33 +01:00
f439d6550b
* Transformation that updates assertions * Simplify transformation * Ensure that all tests have keys * Fix a few remaining keys
170 lines
5.1 KiB
PHP
170 lines
5.1 KiB
PHP
<?php
|
|
|
|
namespace Psalm\Tests\FileManipulation;
|
|
|
|
class UnnecessaryVarAnnotationManipulationTest extends FileManipulationTestCase
|
|
{
|
|
/**
|
|
* @return array<string,array{input:string,output:string,php_version:string,issues_to_fix:string[],safe_types:bool}>
|
|
*/
|
|
public function providerValidCodeParse(): array
|
|
{
|
|
return [
|
|
'removeSingleLineVarAnnotation' => [
|
|
'input' => '<?php
|
|
function foo() : string {
|
|
return "hello";
|
|
}
|
|
|
|
/** @var string */
|
|
$a = foo();
|
|
|
|
/** @var "a"|"b" */
|
|
$b = foo();',
|
|
'output' => '<?php
|
|
function foo() : string {
|
|
return "hello";
|
|
}
|
|
|
|
$a = foo();
|
|
|
|
/** @var "a"|"b" */
|
|
$b = foo();',
|
|
'php_version' => '5.6',
|
|
'issues_to_fix' => ['UnnecessaryVarAnnotation'],
|
|
'safe_types' => true,
|
|
],
|
|
'removeSingleLineVarAnnotationFlipped' => [
|
|
'input' => '<?php
|
|
function foo() : string {
|
|
return "hello";
|
|
}
|
|
|
|
/** @var "a"|"b" */
|
|
$b = foo();
|
|
|
|
/** @var string */
|
|
$a = foo();',
|
|
'output' => '<?php
|
|
function foo() : string {
|
|
return "hello";
|
|
}
|
|
|
|
/** @var "a"|"b" */
|
|
$b = foo();
|
|
|
|
$a = foo();',
|
|
'php_version' => '5.6',
|
|
'issues_to_fix' => ['UnnecessaryVarAnnotation'],
|
|
'safe_types' => true,
|
|
],
|
|
'removeSingleLineVarAnnotationAndType' => [
|
|
'input' => '<?php
|
|
function foo() : string {
|
|
return "hello";
|
|
}
|
|
|
|
/** @var string $a */
|
|
$a = foo();
|
|
|
|
/** @var "a"|"b" */
|
|
$b = foo();',
|
|
'output' => '<?php
|
|
function foo() : string {
|
|
return "hello";
|
|
}
|
|
|
|
$a = foo();
|
|
|
|
/** @var "a"|"b" */
|
|
$b = foo();',
|
|
'php_version' => '5.6',
|
|
'issues_to_fix' => ['UnnecessaryVarAnnotation'],
|
|
'safe_types' => true,
|
|
],
|
|
'removeMultipleLineVarAnnotation' => [
|
|
'input' => '<?php
|
|
function foo() : string {
|
|
return "hello";
|
|
}
|
|
|
|
/**
|
|
* @var string
|
|
*/
|
|
$a = foo();
|
|
|
|
/** @var "a"|"b" */
|
|
$b = foo();',
|
|
'output' => '<?php
|
|
function foo() : string {
|
|
return "hello";
|
|
}
|
|
|
|
$a = foo();
|
|
|
|
/** @var "a"|"b" */
|
|
$b = foo();',
|
|
'php_version' => '5.6',
|
|
'issues_to_fix' => ['UnnecessaryVarAnnotation'],
|
|
'safe_types' => true,
|
|
],
|
|
'removeMultipleLineVarAnnotationKeepComment' => [
|
|
'input' => '<?php
|
|
function foo() : string {
|
|
return "hello";
|
|
}
|
|
|
|
/**
|
|
* @var string
|
|
* this comment should stay
|
|
*/
|
|
$a = foo();
|
|
|
|
/** @var "a"|"b" */
|
|
$b = foo();',
|
|
'output' => '<?php
|
|
function foo() : string {
|
|
return "hello";
|
|
}
|
|
|
|
/**
|
|
* this comment should stay
|
|
*/
|
|
$a = foo();
|
|
|
|
/** @var "a"|"b" */
|
|
$b = foo();',
|
|
'php_version' => '5.6',
|
|
'issues_to_fix' => ['UnnecessaryVarAnnotation'],
|
|
'safe_types' => true,
|
|
],
|
|
'removeMultipleLineVarAnnotationOnce' => [
|
|
'input' => '<?php
|
|
/** @return string[] */
|
|
function foo() : array {
|
|
return ["hello"];
|
|
}
|
|
|
|
/**
|
|
* @var int $k
|
|
* @var string $v
|
|
*/
|
|
foreach (foo() as $k => $v) {}',
|
|
'output' => '<?php
|
|
/** @return string[] */
|
|
function foo() : array {
|
|
return ["hello"];
|
|
}
|
|
|
|
/**
|
|
* @var int $k
|
|
*/
|
|
foreach (foo() as $k => $v) {}',
|
|
'php_version' => '5.6',
|
|
'issues_to_fix' => ['UnnecessaryVarAnnotation'],
|
|
'safe_types' => true,
|
|
],
|
|
];
|
|
}
|
|
}
|