Skip to content
Permalink
Browse files

Use better solution for inherited more-specific return types

  • Loading branch information...
muglug committed May 9, 2019
1 parent 629eeed commit 24dbc34bbe0ea7d823898efa9d02a545e9c51ecc
@@ -655,12 +655,11 @@ public static function checkReturnType(
$context->self
);
if ((!$storage instanceof MethodStorage || !$storage->imported_return_type)
&& !TypeAnalyzer::isContainedBy(
$codebase,
$fleshed_out_return_type,
$fleshed_out_signature_type
)
if (!TypeAnalyzer::isContainedBy(
$codebase,
$fleshed_out_return_type,
$fleshed_out_signature_type
)
) {
if ($codebase->alter_code
&& isset($project_analyzer->getIssuesToFix()['MismatchingDocblockReturnType'])
@@ -237,7 +237,7 @@ public static function isSimplyContainedBy(
$container_type_not_null = clone $container_type;
$container_type_not_null->removeType('null');
return (bool) array_intersect_key(
return !array_diff_key(
$input_type_not_null->getTypes(),
$container_type_not_null->getTypes()
);
@@ -322,13 +322,11 @@ private function populateOverriddenMethods(
) {
if ($declaring_method_storage->signature_return_type) {
$method_storage->return_type = $declaring_method_storage->return_type;
$method_storage->imported_return_type = true;
} elseif (TypeAnalyzer::isSimplyContainedBy(
$declaring_method_storage->return_type,
$method_storage->signature_return_type
)) {
$method_storage->return_type = $declaring_method_storage->return_type;
$method_storage->imported_return_type = true;
}
}
}
@@ -59,9 +59,4 @@ class MethodStorage extends FunctionLikeStorage
* @var bool
*/
public $has_docblock_param_types = false;
/**
* @var bool
*/
public $imported_return_type = false;
}
@@ -967,21 +967,6 @@ public function doFoo(): array {
'$b' => 'array<array-key, int>',
]
],
'allowLessSpecificDocblockTypeOnParent' => [
'<?php
abstract class Foo {
/**
* @return array|string
*/
abstract public function getTargets();
}
class Bar extends Foo {
public function getTargets(): string {
return "baz";
}
}',
],
];
}
@@ -447,6 +447,26 @@ public function f(string $a = "a", int $b = 1, float ...$rest): void {}
(new C)->f("b", 3, 0.5);
(new C)->f("b", 3, 0.5, 0.8);',
],
'allowLessSpecificDocblockTypeOnParent' => [
'<?php
abstract class Foo {
/**
* @return array|string
*/
abstract public function getTargets();
}
class Bar extends Foo {
public function getTargets(): string {
return "baz";
}
}
$a = (new Bar)->getTargets();',
[
'$a' => 'string',
]
],
];
}

0 comments on commit 24dbc34

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