mirror of
https://github.com/danog/psalm.git
synced 2024-11-26 20:34:47 +01:00
Fix #945 - allow ...$foo in docblock for non-user files to inform variadic
This commit is contained in:
parent
23fe4b3591
commit
ef49e3984b
@ -1592,7 +1592,23 @@ class ReflectorVisitor extends PhpParser\NodeVisitorAbstract implements PhpParse
|
||||
}
|
||||
|
||||
if ($storage_param === null) {
|
||||
continue;
|
||||
if (!$docblock_param_variadic || $storage->params || $this->scan_deep) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$storage_param = new FunctionLikeParameter(
|
||||
$param_name,
|
||||
false,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
null
|
||||
);
|
||||
|
||||
$storage->params[] = $storage_param;
|
||||
}
|
||||
|
||||
$code_location = new CodeLocation(
|
||||
|
@ -158,7 +158,7 @@ class StubTest extends TestCase
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testStubFunction()
|
||||
public function testStubRegularFunction()
|
||||
{
|
||||
$this->project_analyzer = $this->getProjectAnalyzerWithConfig(
|
||||
TestConfig::loadFromXML(
|
||||
@ -187,6 +187,108 @@ class StubTest extends TestCase
|
||||
$this->analyzeFile($file_path, new Context());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testStubVariadicFunction()
|
||||
{
|
||||
$this->project_analyzer = $this->getProjectAnalyzerWithConfig(
|
||||
TestConfig::loadFromXML(
|
||||
dirname(__DIR__),
|
||||
'<?xml version="1.0"?>
|
||||
<psalm>
|
||||
<projectFiles>
|
||||
<directory name="src" />
|
||||
</projectFiles>
|
||||
|
||||
<stubs>
|
||||
<file name="tests/stubs/custom_functions.php" />
|
||||
</stubs>
|
||||
</psalm>'
|
||||
)
|
||||
);
|
||||
|
||||
$file_path = getcwd() . '/src/somefile.php';
|
||||
|
||||
$this->addFile(
|
||||
$file_path,
|
||||
'<?php
|
||||
variadic("bat", "bam");'
|
||||
);
|
||||
|
||||
$this->analyzeFile($file_path, new Context());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Psalm\Exception\CodeException
|
||||
* @expectedExceptionMessage InvalidScalarArgument
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testStubVariadicFunctionWrongArgType()
|
||||
{
|
||||
$this->project_analyzer = $this->getProjectAnalyzerWithConfig(
|
||||
TestConfig::loadFromXML(
|
||||
dirname(__DIR__),
|
||||
'<?xml version="1.0"?>
|
||||
<psalm>
|
||||
<projectFiles>
|
||||
<directory name="src" />
|
||||
</projectFiles>
|
||||
|
||||
<stubs>
|
||||
<file name="tests/stubs/custom_functions.php" />
|
||||
</stubs>
|
||||
</psalm>'
|
||||
)
|
||||
);
|
||||
|
||||
$file_path = getcwd() . '/src/somefile.php';
|
||||
|
||||
$this->addFile(
|
||||
$file_path,
|
||||
'<?php
|
||||
variadic("bat", 5);'
|
||||
);
|
||||
|
||||
$this->analyzeFile($file_path, new Context());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Psalm\Exception\CodeException
|
||||
* @expectedExceptionMessage TooManyArguments
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testUserVariadicWithFalseVariadic()
|
||||
{
|
||||
$this->project_analyzer = $this->getProjectAnalyzerWithConfig(
|
||||
TestConfig::loadFromXML(
|
||||
dirname(__DIR__),
|
||||
'<?xml version="1.0"?>
|
||||
<psalm>
|
||||
<projectFiles>
|
||||
<directory name="src" />
|
||||
</projectFiles>
|
||||
</psalm>'
|
||||
)
|
||||
);
|
||||
|
||||
$file_path = getcwd() . '/src/somefile.php';
|
||||
|
||||
$this->addFile(
|
||||
$file_path,
|
||||
'<?php
|
||||
/**
|
||||
* @param string ...$bar
|
||||
*/
|
||||
function variadic() : void {}
|
||||
variadic("hello");'
|
||||
);
|
||||
|
||||
$this->analyzeFile($file_path, new Context());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
|
@ -1,3 +1,8 @@
|
||||
<?php
|
||||
|
||||
function barBar(string $a) : string {}
|
||||
|
||||
/**
|
||||
* @param string ...$bar
|
||||
*/
|
||||
function variadic() {}
|
||||
|
Loading…
Reference in New Issue
Block a user