1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-21 21:31:13 +01:00

Allow suppression of TooManyArguments by function/method id

This commit is contained in:
Matt Brown 2018-08-16 16:49:33 -04:00
parent 3b3863f3a8
commit 070e7903df
9 changed files with 30 additions and 16 deletions

View File

@ -256,8 +256,8 @@
<xs:element name="RedundantConditionGivenDocblockType" type="IssueHandlerType" minOccurs="0" />
<xs:element name="ReferenceConstraintViolation" type="IssueHandlerType" minOccurs="0" />
<xs:element name="ReservedWord" type="IssueHandlerType" minOccurs="0" />
<xs:element name="TooFewArguments" type="IssueHandlerType" minOccurs="0" />
<xs:element name="TooManyArguments" type="IssueHandlerType" minOccurs="0" />
<xs:element name="TooFewArguments" type="FunctionIssueHandlerType" minOccurs="0" />
<xs:element name="TooManyArguments" type="FunctionIssueHandlerType" minOccurs="0" />
<xs:element name="TypeCoercion" type="IssueHandlerType" minOccurs="0" />
<xs:element name="TypeDoesNotContainNull" type="IssueHandlerType" minOccurs="0" />
<xs:element name="TypeDoesNotContainType" type="IssueHandlerType" minOccurs="0" />

View File

@ -7566,8 +7566,8 @@ return [
'nsapi_response_headers' => ['array'],
'nsapi_virtual' => ['bool', 'uri'=>'string'],
'nthmac' => ['string', 'clent'=>'string', 'data'=>'string'],
'number_format' => ['string', 'number'=>'float', 'num_decimal_places='=>'int'],
'number_format\'1' => ['string', 'number'=>'float', 'num_decimal_places'=>'int', 'dec_separator'=>'string', 'thousands_separator'=>'string'],
'number_format' => ['string', 'number'=>'float|int|string', 'num_decimal_places='=>'int'],
'number_format\'1' => ['string', 'number'=>'float|int|string', 'num_decimal_places'=>'int', 'dec_separator'=>'string', 'thousands_separator'=>'string'],
'NumberFormatter::__construct' => ['void', 'locale'=>'string', 'style'=>'int', 'pattern='=>'string'],
'NumberFormatter::create' => ['NumberFormatter', 'locale'=>'string', 'style'=>'int', 'pattern='=>'string'],
'NumberFormatter::format' => ['string', 'num'=>'', 'type='=>'int'],

View File

@ -323,7 +323,8 @@ class NewChecker extends \Psalm\Checker\Statements\Expression\CallChecker
if (IssueBuffer::accepts(
new TooManyArguments(
'Class ' . $fq_class_name . ' has no __construct, but arguments were passed',
new CodeLocation($statements_checker->getSource(), $stmt)
new CodeLocation($statements_checker->getSource(), $stmt),
$fq_class_name . '::__construct'
),
$statements_checker->getSuppressedIssues()
)) {

View File

@ -1066,7 +1066,8 @@ class CallChecker
if (IssueBuffer::accepts(
new TooFewArguments(
'Too few arguments for ' . $method_id,
$code_location
$code_location,
$method_id
),
$statements_checker->getSuppressedIssues()
)) {
@ -1076,7 +1077,8 @@ class CallChecker
if (IssueBuffer::accepts(
new TooFewArguments(
'Too few arguments for ' . $method_id,
$code_location
$code_location,
$method_id
),
$statements_checker->getSuppressedIssues()
)) {
@ -1102,7 +1104,8 @@ class CallChecker
new TooManyArguments(
'Too many arguments for method ' . ($cased_method_id ?: $method_id)
. ' - expecting ' . count($function_params) . ' but saw ' . count($args),
$code_location
$code_location,
$method_id ?: ''
),
$statements_checker->getSuppressedIssues()
)) {
@ -1121,7 +1124,8 @@ class CallChecker
new TooFewArguments(
'Too few arguments for method ' . $cased_method_id
. ' - expecting ' . count($function_params) . ' but saw ' . count($args),
$code_location
$code_location,
$method_id ?: ''
),
$statements_checker->getSuppressedIssues()
)) {
@ -1402,7 +1406,8 @@ class CallChecker
new TooManyArguments(
'The callable passed to ' . $method_id . ' will be called with ' . $argument_text . ', expecting '
. $required_param_count,
new CodeLocation($statements_checker->getSource(), $closure_arg)
new CodeLocation($statements_checker->getSource(), $closure_arg),
$method_id
),
$statements_checker->getSuppressedIssues()
)) {
@ -1415,7 +1420,8 @@ class CallChecker
new TooFewArguments(
'The callable passed to ' . $method_id . ' will be called with ' . $argument_text . ', expecting '
. $required_param_count,
new CodeLocation($statements_checker->getSource(), $closure_arg)
new CodeLocation($statements_checker->getSource(), $closure_arg),
$method_id
),
$statements_checker->getSuppressedIssues()
)) {

View File

@ -180,6 +180,13 @@ class FileFilter
}
}
if ($e->referencedFunction) {
/** @var \SimpleXMLElement $referenced_function */
foreach ($e->referencedFunction as $referenced_function) {
$filter->method_ids[] = strtolower((string)$referenced_function['name']);
}
}
if ($e->referencedProperty) {
/** @var \SimpleXMLElement $referenced_property */
foreach ($e->referencedProperty as $referenced_property) {
@ -277,7 +284,7 @@ class FileFilter
*/
public function allowsMethod($method_id)
{
return in_array(strtolower($method_id), $this->method_ids);
return in_array($method_id, $this->method_ids);
}
/**

View File

@ -95,7 +95,7 @@ class IssueHandler
public function getReportingLevelForMethod($method_id)
{
foreach ($this->custom_levels as $custom_level) {
if ($custom_level->allowsMethod($method_id)) {
if ($custom_level->allowsMethod(strtolower($method_id))) {
return $custom_level->getErrorLevel();
}
}

View File

@ -19,6 +19,6 @@ abstract class MethodIssue extends CodeIssue
$method_id
) {
parent::__construct($message, $code_location);
$this->method_id = $method_id;
$this->method_id = strtolower($method_id);
}
}

View File

@ -1,6 +1,6 @@
<?php
namespace Psalm\Issue;
class TooFewArguments extends CodeIssue
class TooFewArguments extends MethodIssue
{
}

View File

@ -1,6 +1,6 @@
<?php
namespace Psalm\Issue;
class TooManyArguments extends CodeIssue
class TooManyArguments extends MethodIssue
{
}