mirror of
https://github.com/danog/psalm.git
synced 2024-11-26 20:34:47 +01:00
fix offset for type param changes
This commit is contained in:
parent
22fd6fb9db
commit
ed94de5146
@ -11,6 +11,13 @@ declare(strict_types=1);
|
||||
//
|
||||
// What we are currently missing is properly parsing of <xi:include> directives.
|
||||
|
||||
use PhpParser\Lexer\Emulative;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\Node\Stmt\Namespace_;
|
||||
use PhpParser\NodeTraverser;
|
||||
use PhpParser\NodeVisitor\NameResolver;
|
||||
use PhpParser\ParserFactory;
|
||||
|
||||
set_error_handler(function ($num, $str, $file, $line, $context = null): void {
|
||||
throw new ErrorException($str, 0, $num, $file, $line);
|
||||
});
|
||||
@ -22,22 +29,22 @@ foreach ([__DIR__ . '/../../../autoload.php', __DIR__ . '/../vendor/autoload.php
|
||||
}
|
||||
}
|
||||
|
||||
$lexer = new PhpParser\Lexer\Emulative();
|
||||
$parser = (new PhpParser\ParserFactory)->create(
|
||||
PhpParser\ParserFactory::PREFER_PHP7,
|
||||
$lexer = new Emulative();
|
||||
$parser = (new ParserFactory)->create(
|
||||
ParserFactory::PREFER_PHP7,
|
||||
$lexer,
|
||||
);
|
||||
$traverser = new PhpParser\NodeTraverser();
|
||||
$traverser->addVisitor(new PhpParser\NodeVisitor\NameResolver);
|
||||
$traverser = new NodeTraverser();
|
||||
$traverser->addVisitor(new NameResolver);
|
||||
|
||||
function extractClassesFromStatements(array $statements): array
|
||||
{
|
||||
$classes = [];
|
||||
foreach ($statements as $statement) {
|
||||
if ($statement instanceof PhpParser\Node\Stmt\Class_) {
|
||||
if ($statement instanceof Class_) {
|
||||
$classes[strtolower($statement->namespacedName->toString())] = true;
|
||||
}
|
||||
if ($statement instanceof PhpParser\Node\Stmt\Namespace_) {
|
||||
if ($statement instanceof Namespace_) {
|
||||
$classes += extractClassesFromStatements($statement->stmts);
|
||||
}
|
||||
}
|
||||
|
@ -137,7 +137,7 @@ class FunctionDocblockManipulator
|
||||
if ($param->type) {
|
||||
$this->param_typehint_offsets[$param->var->name] = [
|
||||
(int) $param->type->getAttribute('startFilePos'),
|
||||
(int) $param->type->getAttribute('endFilePos'),
|
||||
(int) $param->type->getAttribute('endFilePos') + 1,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -365,6 +365,54 @@ class ParamTypeManipulationTest extends FileManipulationTestCase
|
||||
'issues_to_fix' => ['MissingParamType'],
|
||||
'safe_types' => true,
|
||||
],
|
||||
'ChangingTypeOfExplicitMixedParam' => [
|
||||
'input' => '<?php
|
||||
|
||||
class ConfigContainer
|
||||
{
|
||||
|
||||
public function setValue(mixed $value): void
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
function foo(){
|
||||
$config = new ConfigContainer();
|
||||
|
||||
$config->setValue([1,2,3,4]);
|
||||
|
||||
}
|
||||
',
|
||||
'output' => '<?php
|
||||
|
||||
class ConfigContainer
|
||||
{
|
||||
|
||||
/**
|
||||
* @param int[] $value
|
||||
*
|
||||
* @psalm-param list{1, 2, 3, 4} $value
|
||||
*/
|
||||
public function setValue(array $value): void
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
function foo(){
|
||||
$config = new ConfigContainer();
|
||||
|
||||
$config->setValue([1,2,3,4]);
|
||||
|
||||
}
|
||||
',
|
||||
'php_version' => '8.0',
|
||||
'issues_to_fix' => ['MissingParamType'],
|
||||
'safe_types' => false,
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user