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

Don’t be concerned about unused params named $_

Fixes #540
This commit is contained in:
Matt Brown 2018-02-27 11:39:26 -05:00
parent 1f358e36ef
commit 80864b1ce8
4 changed files with 36 additions and 8 deletions

View File

@ -375,9 +375,8 @@ class FunctionChecker extends FunctionLikeChecker
array_map(
/**
* @return Type\Union
* @psalm-suppress UnusedParam
*/
function (Type\Union $t) use ($inner_type) {
function (Type\Union $_) use ($inner_type) {
return clone $inner_type;
},
$array_arg_type->properties
@ -482,9 +481,8 @@ class FunctionChecker extends FunctionLikeChecker
array_map(
/**
* @return Type\Union
* @psalm-suppress UnusedParam
*/
function (Type\Union $t) use ($mapping_return_type) {
function (Type\Union $_) use ($mapping_return_type) {
return clone $mapping_return_type;
},
$array_arg_type->properties

View File

@ -499,6 +499,10 @@ abstract class FunctionLikeChecker extends SourceChecker implements StatementsSo
continue;
}
if ($var_name === '$_' || (strpos($var_name, '$unused') === 0 && $var_name !== '$unused')) {
continue;
}
$position = array_search(substr($var_name, 1), array_keys($storage->param_types), true);
if ($position === false) {

View File

@ -123,14 +123,12 @@ class Analyzer
$analysis_worker =
/**
* @param int $i
* @param int $_
* @param string $file_path
*
* @return void
*
* @psalm-suppress UnusedParam
*/
function ($i, $file_path) use ($project_checker, $filetype_checkers) {
function ($_, $file_path) use ($project_checker, $filetype_checkers) {
$file_checker = $this->getFileChecker($project_checker, $file_path, $filetype_checkers);
if ($this->debug_output) {

View File

@ -684,6 +684,34 @@ class UnusedCodeTest extends TestCase
printf("s is %s\n", $s);
}',
],
'unusedParamWithUnderscore' => [
'<?php
function foo(int $_) : void {}
foo(4);',
],
'unusedParamWithUnusedPrefix' => [
'<?php
function foo(int $unusedArg) : void {}
foo(4);',
],
'possiblyUnusedParamWithUnderscore' => [
'<?php
class A {
public static function foo(int $_ = null) : void {}
}
A::foo();',
],
'possiblyUnusedParamWithUnusedPrefix' => [
'<?php
class A {
public static function foo(int $unusedArg = null) : void {}
}
A::foo();',
],
];
}