Skip to content
Permalink
Browse files

Fix #1634 - don’t remove existing return types when preventing bc breaks

  • Loading branch information...
muglug committed May 15, 2019
1 parent a34692f commit cfff66efb7e953ab8d4b9d267b8514b5271b34ba
@@ -263,7 +263,7 @@ public static function verifyReturnType(
$source,
$function_like_analyzer,
($project_analyzer->only_replace_php_types_with_non_docblock_types
|| $unsafe_return_type)
|| $unsafe_return_type)
&& $inferred_return_type->from_docblock,
$function_like_storage
);
@@ -300,9 +300,9 @@ public static function verifyReturnType(
$source,
$function_like_analyzer,
$compatible_method_ids
|| (($project_analyzer->only_replace_php_types_with_non_docblock_types
|| $unsafe_return_type)
&& $inferred_return_type->from_docblock),
|| (($project_analyzer->only_replace_php_types_with_non_docblock_types
|| $unsafe_return_type)
&& $inferred_return_type->from_docblock),
$function_like_storage
);
@@ -356,8 +356,8 @@ public static function verifyReturnType(
$function_like_analyzer,
$compatible_method_ids
|| (($project_analyzer->only_replace_php_types_with_non_docblock_types
|| $unsafe_return_type)
&& $inferred_return_type->from_docblock)
|| $unsafe_return_type)
&& $inferred_return_type->from_docblock)
);
return null;
@@ -448,7 +448,7 @@ public static function verifyReturnType(
$source,
$function_like_analyzer,
($project_analyzer->only_replace_php_types_with_non_docblock_types
|| $unsafe_return_type)
|| $unsafe_return_type)
&& $inferred_return_type->from_docblock,
$function_like_storage
);
@@ -485,9 +485,9 @@ public static function verifyReturnType(
$source,
$function_like_analyzer,
$compatible_method_ids
|| (($project_analyzer->only_replace_php_types_with_non_docblock_types
|| $unsafe_return_type)
&& $inferred_return_type->from_docblock),
|| (($project_analyzer->only_replace_php_types_with_non_docblock_types
|| $unsafe_return_type)
&& $inferred_return_type->from_docblock),
$function_like_storage
);
@@ -542,7 +542,7 @@ public static function verifyReturnType(
$source,
$function_like_analyzer,
($project_analyzer->only_replace_php_types_with_non_docblock_types
|| $unsafe_return_type)
|| $unsafe_return_type)
&& $inferred_return_type->from_docblock,
$function_like_storage
);
@@ -578,7 +578,7 @@ public static function verifyReturnType(
$source,
$function_like_analyzer,
($project_analyzer->only_replace_php_types_with_non_docblock_types
|| $unsafe_return_type)
|| $unsafe_return_type)
&& $inferred_return_type->from_docblock,
$function_like_storage
);
@@ -736,11 +736,12 @@ private static function addOrUpdateReturnType(
&& (
$codebase->allow_backwards_incompatible_changes
|| $is_final
|| !$function instanceof PhpParser\Node\Stmt\ClassMethod
);
$manipulator->setReturnType(
$allow_native_type
? $inferred_return_type->toPhpString(
? (string) $inferred_return_type->toPhpString(
$source->getNamespace(),
$source->getAliasedClassesFlipped(),
$source->getFQCLN(),
@@ -354,7 +354,8 @@ public static function getManipulationsForFile($file_path)
': ' . $manipulator->new_php_return_type
);
}
} elseif ($manipulator->return_typehint_colon_start
} elseif ($manipulator->new_php_return_type === ''
&& $manipulator->return_typehint_colon_start
&& $manipulator->new_phpdoc_return_type
&& $manipulator->return_typehint_start
&& $manipulator->return_typehint_end
@@ -34,8 +34,14 @@ public function setUp()
*
* @return void
*/
public function testValidCode($input_code, $output_code, $php_version, array $issues_to_fix, $safe_types, bool $allow_backwards_incompatible_changes = true)
{
public function testValidCode(
$input_code,
$output_code,
$php_version,
array $issues_to_fix,
$safe_types,
bool $allow_backwards_incompatible_changes = true
) {
$test_name = $this->getTestName();
if (strpos($test_name, 'SKIPPED-') !== false) {
$this->markTestSkipped('Skipped due to a bug.');
@@ -8,7 +8,7 @@
class ReturnTypeManipulationTest extends FileManipulationTest
{
/**
* @return array<string,array{string,string,string,string[],bool}>
* @return array<string,array{string,string,string,string[],bool,5?:bool}>
*/
public function providerValidCodeParse()
{
@@ -1226,6 +1226,58 @@ function foo(): array {
['MissingReturnType'],
false,
],
'dontReplaceValidReturnTypePreventingBackwardsIncompatibility' => [
'<?php
class A {
/**
* @return int[]|null
*/
public function foo(): ?array {
return ["hello"];
}
}',
'<?php
class A {
/**
* @return string[]
*
* @psalm-return array{0:string}
*/
public function foo(): ?array {
return ["hello"];
}
}',
'7.3',
['InvalidReturnType'],
false,
false
],
'dontReplaceValidReturnTypeAllowBackwardsIncompatibility' => [
'<?php
class A {
/**
* @return int[]|null
*/
public function foo(): ?array {
return ["hello"];
}
}',
'<?php
class A {
/**
* @return string[]
*
* @psalm-return array{0:string}
*/
public function foo(): array {
return ["hello"];
}
}',
'7.3',
['InvalidReturnType'],
false,
true
],
];
}
}

0 comments on commit cfff66e

Please sign in to comment.
You can’t perform that action at this time.