Skip to content
Permalink
Browse files

Prepare for tracking unused suppressions

Ref #1444
  • Loading branch information...
muglug committed Aug 18, 2019
1 parent 1e400c5 commit 2146f73782f9506eda8e2d1a74dbbcd4989ec8a9
@@ -1211,18 +1211,11 @@ public function mustBeIgnored($file_path)
return $this->project_files && $this->project_files->forbids($file_path);
}
/**
* @param string[] $suppressed_issues
*/
public function getReportingLevelForIssue(CodeIssue $e, array $suppressed_issues = []) : string
public function getReportingLevelForIssue(CodeIssue $e) : string
{
$fqcn_parts = explode('\\', get_class($e));
$issue_type = array_pop($fqcn_parts);
if (in_array($issue_type, $suppressed_issues, true)) {
return self::REPORT_SUPPRESS;
}
$reporting_level = null;
if ($e instanceof ClassIssue) {
@@ -1243,10 +1236,6 @@ public function getReportingLevelForIssue(CodeIssue $e, array $suppressed_issues
$parent_issue_type = self::getParentIssueType($issue_type);
if ($parent_issue_type && in_array($parent_issue_type, $suppressed_issues, true)) {
return self::REPORT_SUPPRESS;
}
if ($parent_issue_type && $reporting_level === Config::REPORT_ERROR) {
$parent_reporting_level = $this->getReportingLevelForFile($parent_issue_type, $e->getFilePath());
@@ -1263,7 +1252,7 @@ public function getReportingLevelForIssue(CodeIssue $e, array $suppressed_issues
*
* @return string|null
*/
private static function getParentIssueType($issue_type)
public static function getParentIssueType($issue_type)
{
if (strpos($issue_type, 'Possibly') === 0) {
$stripped_issue_type = preg_replace('/^Possibly(False|Null)?/', '', $issue_type);
@@ -134,7 +134,7 @@ public function analyze(
),
$class_name
),
array_merge($storage->suppressed_issues, $this->source->getSuppressedIssues())
$storage->suppressed_issues + $this->getSuppressedIssues()
)) {
// fall through
}
@@ -222,7 +222,7 @@ public function analyze(
$this->getSource(),
$parent_fq_class_name,
$parent_reference_location,
array_merge($storage->suppressed_issues, $this->getSuppressedIssues()),
$storage->suppressed_issues + $this->getSuppressedIssues(),
false
) === false) {
return false;
@@ -255,7 +255,7 @@ public function analyze(
$code_location,
$parent_fq_class_name . ' as class'
),
array_merge($storage->suppressed_issues, $this->getSuppressedIssues())
$storage->suppressed_issues + $this->getSuppressedIssues()
)) {
// fall through
}
@@ -268,7 +268,7 @@ public function analyze(
$code_location,
$parent_fq_class_name
),
array_merge($storage->suppressed_issues, $this->getSuppressedIssues())
$storage->suppressed_issues + $this->getSuppressedIssues()
)) {
// fall through
}
@@ -288,7 +288,7 @@ public function analyze(
$code_location,
$parent_fq_class_name
),
array_merge($storage->suppressed_issues, $this->getSuppressedIssues())
$storage->suppressed_issues + $this->getSuppressedIssues()
)) {
// fall through
}
@@ -304,7 +304,7 @@ public function analyze(
$code_location,
$parent_fq_class_name
),
array_merge($storage->suppressed_issues, $this->getSuppressedIssues())
$storage->suppressed_issues + $this->getSuppressedIssues()
)) {
// fall through
}
@@ -406,7 +406,7 @@ public function analyze(
$code_location,
$fq_interface_name
),
array_merge($storage->suppressed_issues, $this->getSuppressedIssues())
$storage->suppressed_issues + $this->getSuppressedIssues()
)) {
// fall through
}
@@ -492,7 +492,7 @@ public function analyze(
$code_location,
$interface_name
),
array_merge($storage->suppressed_issues, $this->getSuppressedIssues())
$storage->suppressed_issues + $this->getSuppressedIssues()
)) {
// fall through
}
@@ -524,7 +524,7 @@ public function analyze(
$storage->name,
$code_location
),
array_merge($storage->suppressed_issues, $this->getSuppressedIssues())
$storage->suppressed_issues + $this->getSuppressedIssues()
)) {
return false;
}
@@ -563,7 +563,7 @@ public function analyze(
. ' must be public in ' . $storage->name,
$code_location
),
array_merge($storage->suppressed_issues, $this->getSuppressedIssues())
$storage->suppressed_issues + $this->getSuppressedIssues()
)) {
return false;
}
@@ -634,7 +634,7 @@ public function analyze(
true
)
),
array_merge($storage->suppressed_issues, $this->getSuppressedIssues())
$storage->suppressed_issues + $this->getSuppressedIssues()
)) {
return false;
}
@@ -730,7 +730,7 @@ public function analyze(
$fleshed_out_type->check(
$this,
$property_type_location,
array_merge($this->getSuppressedIssues(), $storage->suppressed_issues),
$storage->suppressed_issues + $this->getSuppressedIssues(),
[],
false
);
@@ -1245,7 +1245,7 @@ function (FunctionLikeParameter $param) : PhpParser\Node\Arg {
$error_location,
$property_id
),
array_merge($this->source->getSuppressedIssues(), $storage->suppressed_issues)
$storage->suppressed_issues + $this->getSuppressedIssues()
)) {
continue;
}
@@ -1271,7 +1271,7 @@ function (FunctionLikeParameter $param) : PhpParser\Node\Arg {
', but no constructor',
$first_uninitialized_property->location
),
array_merge($storage->suppressed_issues, $this->getSuppressedIssues())
$storage->suppressed_issues + $this->getSuppressedIssues()
)) {
// fall through
}
@@ -1310,7 +1310,7 @@ private function analyzeTraitUse(
'Trait ' . $fq_trait_name . ' does not exist',
new CodeLocation($this, $trait_name)
),
array_merge($storage->suppressed_issues, $this->getSuppressedIssues())
$storage->suppressed_issues + $this->getSuppressedIssues()
)) {
return false;
}
@@ -1321,7 +1321,7 @@ private function analyzeTraitUse(
'Trait ' . $fq_trait_name . ' has wrong casing',
new CodeLocation($this, $trait_name)
),
array_merge($storage->suppressed_issues, $this->getSuppressedIssues())
$storage->suppressed_issues + $this->getSuppressedIssues()
)) {
return false;
}
@@ -1337,7 +1337,7 @@ private function analyzeTraitUse(
'Trait ' . $fq_trait_name . ' is deprecated',
new CodeLocation($this, $trait_name)
),
array_merge($storage->suppressed_issues, $this->getSuppressedIssues())
$storage->suppressed_issues + $this->getSuppressedIssues()
)) {
// fall through
}
@@ -1746,7 +1746,7 @@ private function checkTemplateParams(
. $template_type_count,
$code_location
),
array_merge($storage->suppressed_issues, $this->getSuppressedIssues())
$storage->suppressed_issues + $this->getSuppressedIssues()
)) {
// fall through
}
@@ -1757,7 +1757,7 @@ private function checkTemplateParams(
. $template_type_count,
$code_location
),
array_merge($storage->suppressed_issues, $this->getSuppressedIssues())
$storage->suppressed_issues + $this->getSuppressedIssues()
)) {
// fall through
}
@@ -1791,7 +1791,7 @@ private function checkTemplateParams(
. ' from an invariant context',
$code_location
),
array_merge($storage->suppressed_issues, $this->getSuppressedIssues())
$storage->suppressed_issues + $this->getSuppressedIssues()
)) {
// fall through
}
@@ -1809,7 +1809,7 @@ private function checkTemplateParams(
. ', type ' . $extended_type->getId() . ' given',
$code_location
),
array_merge($storage->suppressed_issues, $this->getSuppressedIssues())
$storage->suppressed_issues + $this->getSuppressedIssues()
)) {
// fall through
}
@@ -517,8 +517,8 @@ public static function extractFunctionDocblockInfo(PhpParser\Comment\Doc $commen
if (isset($parsed_docblock['specials']['psalm-suppress'])) {
foreach ($parsed_docblock['specials']['psalm-suppress'] as $suppress_entry) {
$info->suppress[] = preg_split('/[\s]+/', $suppress_entry)[0];
foreach ($parsed_docblock['specials']['psalm-suppress'] as $offset => $suppress_entry) {
$info->suppressed_issues[$offset] = preg_split('/[\s]+/', $suppress_entry)[0];
}
}
@@ -57,7 +57,7 @@ class FileAnalyzer extends SourceAnalyzer implements StatementsSource
private $parent_file_paths = [];
/**
* @var array<int, string>
* @var array<string>
*/
private $suppressed_issues = [];
@@ -539,7 +539,7 @@ public function getRequireNesting()
}
/**
* @return array<int, string>
* @return array<string>
*/
public function getSuppressedIssues()
{
@@ -553,7 +553,11 @@ public function getSuppressedIssues()
*/
public function addSuppressedIssues(array $new_issues)
{
$this->suppressed_issues = array_merge($new_issues, $this->suppressed_issues);
if (isset($new_issues[0])) {
$new_issues = \array_combine($new_issues, $new_issues);
}
$this->suppressed_issues = $new_issues + $this->suppressed_issues;
}
/**
@@ -563,7 +567,11 @@ public function addSuppressedIssues(array $new_issues)
*/
public function removeSuppressedIssues(array $new_issues)
{
$this->suppressed_issues = array_diff($this->suppressed_issues, $new_issues);
if (isset($new_issues[0])) {
$new_issues = \array_combine($new_issues, $new_issues);
}
$this->suppressed_issues = \array_diff_key($this->suppressed_issues, $new_issues);
}
/**
@@ -292,10 +292,7 @@ public function analyze(
]);
}
$this->suppressed_issues = array_merge(
$this->getSource()->getSuppressedIssues(),
$storage->suppressed_issues
);
$this->suppressed_issues = $this->getSource()->getSuppressedIssues() + $storage->suppressed_issues;
if ($storage instanceof MethodStorage && $storage->is_static) {
$this->is_static = true;
@@ -841,15 +838,15 @@ function (FunctionLikeParameter $p) {
'Parameter $' . $function_param->name . ' has no provided type',
$function_param->location
),
array_merge($this->suppressed_issues, $storage->suppressed_issues)
$storage->suppressed_issues + $this->getSuppressedIssues()
);
} else {
IssueBuffer::accepts(
new MissingParamType(
'Parameter $' . $function_param->name . ' has no provided type',
$function_param->location
),
array_merge($this->suppressed_issues, $storage->suppressed_issues)
$storage->suppressed_issues + $this->getSuppressedIssues()
);
}
}
@@ -1457,7 +1454,11 @@ public function getSuppressedIssues()
*/
public function addSuppressedIssues(array $new_issues)
{
$this->suppressed_issues = array_merge($new_issues, $this->suppressed_issues);
if (isset($new_issues[0])) {
$new_issues = \array_combine($new_issues, $new_issues);
}
$this->suppressed_issues = $new_issues + $this->suppressed_issues;
}
/**
@@ -1467,7 +1468,11 @@ public function addSuppressedIssues(array $new_issues)
*/
public function removeSuppressedIssues(array $new_issues)
{
$this->suppressed_issues = array_diff($this->suppressed_issues, $new_issues);
if (isset($new_issues[0])) {
$new_issues = \array_combine($new_issues, $new_issues);
}
$this->suppressed_issues = \array_diff_key($this->suppressed_issues, $new_issues);
}
/**
@@ -108,7 +108,7 @@ class FunctionDocblockComment
/**
* @var array<int, string>
*/
public $suppress = [];
public $suppressed_issues = [];
/**
* @var array<int, array{0: string, 1: int, 2: int}>
@@ -2032,7 +2032,7 @@ private function registerFunctionLike(PhpParser\Node\FunctionLike $stmt, $fake_m
$storage->return_type->ignore_falsable_issues = true;
}
$storage->suppressed_issues = $docblock_info->suppress;
$storage->suppressed_issues = $docblock_info->suppressed_issues;
foreach ($docblock_info->throws as [$throw, $offset, $line]) {
$throw_location = new CodeLocation\DocblockTypeLocation(
@@ -90,7 +90,23 @@ public static function isSuppressed(CodeIssue $e, array $suppressed_issues = [])
return true;
}
$reporting_level = $config->getReportingLevelForIssue($e, $suppressed_issues);
$suppressed_issue_position = array_search($issue_type, $suppressed_issues);
if ($suppressed_issue_position !== false) {
return true;
}
$parent_issue_type = Config::getParentIssueType($issue_type);
if ($parent_issue_type) {
$suppressed_issue_position = array_search($parent_issue_type, $suppressed_issues);
if ($suppressed_issue_position !== false) {
return true;
}
}
$reporting_level = $config->getReportingLevelForIssue($e);
if ($reporting_level === Config::REPORT_SUPPRESS) {
return true;
@@ -14,7 +14,7 @@ class IssueSuppressionTest extends TestCase
public function providerValidCodeParse()
{
return [
'undefinedClass' => [
'undefinedClassSimple' => [
'<?php
class A {
/**

0 comments on commit 2146f73

Please sign in to comment.
You can’t perform that action at this time.