1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

#2579 TooManyArguments was triggered if the variadic function declared at the autoloader file. Fixed. (#2580)

This commit is contained in:
Тальгат Хайруллов 2020-01-12 20:33:38 +04:00 committed by Matthew Brown
parent cfbf0dfcef
commit 39a822759d
4 changed files with 70 additions and 3 deletions

View File

@ -1180,14 +1180,19 @@ class CallAnalyzer
$codebase = $statements_analyzer->getCodebase();
if ($method_id) {
if ($in_call_map || !strpos($method_id, '::')) {
if (!$in_call_map && strpos($method_id, '::')) {
$fq_class_name = explode('::', $method_id)[0];
}
if ($function_storage) {
$is_variadic = $function_storage->variadic;
} elseif ($fq_class_name === null) {
$is_variadic = $codebase->functions->isVariadic(
$codebase,
strtolower($method_id),
$statements_analyzer->getRootFilePath()
);
} else {
$fq_class_name = explode('::', $method_id)[0];
$is_variadic = $codebase->methods->isVariadic($method_id);
}
}

View File

@ -2317,7 +2317,7 @@ class StatementsAnalyzer extends SourceAnalyzer implements StatementsSource
$is_expected = false;
foreach ($ignored_exceptions_and_descendants as $expected_exception => $_) {
if ($expected_exception === $possibly_thrown_exception
if ($expected_exception === strtolower($possibly_thrown_exception)
|| $this->codebase->classExtends($possibly_thrown_exception, $expected_exception)
) {
$is_expected = true;

View File

@ -1,7 +1,11 @@
<?php
namespace Psalm\Tests;
use Psalm\Config;
use Psalm\Context;
use Psalm\Tests\Internal\Provider;
use function dirname;
use function getcwd;
class VariadicTest extends TestCase
{
@ -29,6 +33,38 @@ class VariadicTest extends TestCase
$this->analyzeFile('somefile.php', new Context());
}
/**
* @throws \Psalm\Exception\ConfigException
* @return void
*/
public function testVariadicFunctionFromAutoloadFile()
{
$this->project_analyzer = $this->getProjectAnalyzerWithConfig(
TestConfig::loadFromXML(
dirname(__DIR__),
'<?xml version="1.0"?>
<psalm
autoloader="tests/fixtures/stubs/custom_functions.php"
>
<projectFiles>
<directory name="src" />
</projectFiles>
</psalm>'
)
);
$file_path = getcwd() . '/src/somefile.php';
$this->addFile(
$file_path,
'<?php
variadic2(16, 30);
'
);
$this->analyzeFile($file_path, new Context());
}
/**
* @return iterable<string,array{string,1?:array<string,string>,2?:string[]}>
*/
@ -91,4 +127,25 @@ class VariadicTest extends TestCase
],
];
}
/**
* @param Config $config
*
* @return \Psalm\Internal\Analyzer\ProjectAnalyzer
*/
private function getProjectAnalyzerWithConfig(Config $config)
{
$project_analyzer = new \Psalm\Internal\Analyzer\ProjectAnalyzer(
$config,
new \Psalm\Internal\Provider\Providers(
$this->file_provider,
new Provider\FakeParserCacheProvider()
)
);
$project_analyzer->setPhpVersion('7.3');
$config->visitComposerAutoloadFiles($project_analyzer, null);
return $project_analyzer;
}
}

View File

@ -10,3 +10,8 @@ function barBar(string $a) : string
function variadic()
{
}
function variadic2() : array
{
return func_get_args();
}