Skip to content

Commit

Permalink
Add extra safety feature
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Dec 3, 2019
1 parent 585ef06 commit aa4daea
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/Psalm/Internal/Codebase/ClassLikes.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -1952,6 +1952,17 @@ private function findPossibleMethodParamTypes(ClassLikeStorage $classlike_storag
$method_storage->location->file_path $method_storage->location->file_path
); );


$has_variable_calls = $codebase->analyzer->hasMixedMemberName(
strtolower($method_name)
)
|| $codebase->analyzer->hasMixedMemberName(
strtolower($classlike_storage->name . '::')
);

if ($has_variable_calls) {
$possible_type->from_docblock = true;
}

if ($function_analyzer) { if ($function_analyzer) {
$function_analyzer->addOrUpdateParamType( $function_analyzer->addOrUpdateParamType(
$project_analyzer, $project_analyzer,
Expand Down
28 changes: 28 additions & 0 deletions tests/FileManipulation/ParamTypeManipulationTest.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -78,6 +78,34 @@ public function fooFoo(string $a): void {}
['MissingParamType'], ['MissingParamType'],
true, true,
], ],
'noStringParamTypeWithVariableCall' => [
'<?php
class C {
public function fooFoo($a): void {}
}
/** @var mixed */
$c = null;
$c->fooFoo("hello");
(new C)->fooFoo("hello");',
'<?php
class C {
/**
* @param string $a
*/
public function fooFoo($a): void {}
}
/** @var mixed */
$c = null;
$c->fooFoo("hello");
(new C)->fooFoo("hello");',
'7.1',
['MissingParamType'],
true,
],
'noStringParamTypeWithDocblockCall' => [ 'noStringParamTypeWithDocblockCall' => [
'<?php '<?php
class C { class C {
Expand Down

0 comments on commit aa4daea

Please sign in to comment.