Skip to content

Commit

Permalink
Fix #3654 - use correct function id for namespaced functions
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Jun 23, 2020
1 parent 6a746b6 commit 96d05ab
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php
Expand Up @@ -324,11 +324,10 @@ public function analyze(
$context->calling_method_id = strtolower((string) $method_id);
}
} elseif ($this->function instanceof Function_) {
$cased_method_id = $this->function->name->name;
$function_name = $this->function->name->name;
$namespace_prefix = $this->getNamespace();
$context->calling_function_id = strtolower(
($namespace_prefix !== null ? $namespace_prefix . '\\' : '') . $cased_method_id
);
$cased_method_id = ($namespace_prefix !== null ? $namespace_prefix . '\\' : '') . $function_name;
$context->calling_function_id = strtolower($cased_method_id);
} else { // Closure
if ($storage->return_type) {
$closure_return_type = \Psalm\Internal\Type\TypeExpander::expandUnion(
Expand Down
22 changes: 22 additions & 0 deletions tests/TaintTest.php
Expand Up @@ -1856,4 +1856,26 @@ public function testEncapsulatedString() : void

$this->analyzeFile('somefile.php', new Context());
}

public function testNamespacedFunction() : void
{
$this->expectException(\Psalm\Exception\CodeException::class);
$this->expectExceptionMessage('TaintedInput');

$this->project_analyzer->trackTaintedInputs();

$this->addFile(
'somefile.php',
'<?php
namespace ns;
function identity(string $s) : string {
return $s;
}
echo identity($_GET[\'userinput\']);'
);

$this->analyzeFile('somefile.php', new Context());
}
}

0 comments on commit 96d05ab

Please sign in to comment.