Skip to content

Commit

Permalink
Migrate most IssueBuffer::accepts calls to IssueBuffer::maybeAdd (#7020)
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Nov 29, 2021
1 parent e29571d commit 175ba83
Show file tree
Hide file tree
Showing 73 changed files with 912 additions and 1,781 deletions.
24 changes: 8 additions & 16 deletions src/Psalm/Internal/Analyzer/AlgebraAnalyzer.php
Expand Up @@ -61,16 +61,14 @@ public static function checkForParadox(
&& (isset($formula_1_hashes[$hash]) || isset($formula_2_hashes[$hash]))
&& !array_intersect_key($new_assigned_var_ids, $formula_2_clause->possibilities)
) {
if (IssueBuffer::accepts(
IssueBuffer::maybeAdd(
new RedundantCondition(
$formula_2_clause . ' has already been asserted',
new CodeLocation($statements_analyzer, $stmt),
null
),
$statements_analyzer->getSuppressedIssues()
)) {
// fall through
}
);
}

foreach ($formula_2_clause->possibilities as $key => $values) {
Expand All @@ -79,15 +77,13 @@ public static function checkForParadox(
&& !isset($new_assigned_var_ids[$key])
&& count(array_unique($values)) < count($values)
) {
if (IssueBuffer::accepts(
IssueBuffer::maybeAdd(
new ParadoxicalCondition(
'Found a redundant condition when evaluating assertion (' . $formula_2_clause . ')',
new CodeLocation($statements_analyzer, $stmt)
),
$statements_analyzer->getSuppressedIssues()
)) {
// fall through
}
);
}
}

Expand All @@ -102,16 +98,14 @@ public static function checkForParadox(
&& !isset($new_assigned_var_ids[$key])
&& count(array_unique($values)) < count($values)
) {
if (IssueBuffer::accepts(
IssueBuffer::maybeAdd(
new RedundantCondition(
'Found a redundant condition when evaluating ' . $key,
new CodeLocation($statements_analyzer, $stmt),
null
),
$statements_analyzer->getSuppressedIssues()
)) {
// fall through
}
);
}
}
}
Expand Down Expand Up @@ -161,15 +155,13 @@ public static function checkForParadox(
. ' contradicts a previously-established condition (' . $clause_1 . ')';
}

if (IssueBuffer::accepts(
IssueBuffer::maybeAdd(
new ParadoxicalCondition(
$paradox_message,
new CodeLocation($statements_analyzer, $stmt)
),
$statements_analyzer->getSuppressedIssues()
)) {
// fall through
}
);

return;
}
Expand Down
42 changes: 14 additions & 28 deletions src/Psalm/Internal/Analyzer/AttributeAnalyzer.php
Expand Up @@ -54,57 +54,47 @@ public static function analyze(

if ($attribute->fq_class_name === 'Attribute' && $classlike_storage) {
if ($classlike_storage->is_trait) {
if (\Psalm\IssueBuffer::accepts(
\Psalm\IssueBuffer::maybeAdd(
new InvalidAttribute(
'Traits cannot act as attribute classes',
$attribute->name_location
),
$source->getSuppressedIssues()
)) {
// fall through
}
);
} elseif ($classlike_storage->is_interface) {
if (\Psalm\IssueBuffer::accepts(
\Psalm\IssueBuffer::maybeAdd(
new InvalidAttribute(
'Interfaces cannot act as attribute classes',
$attribute->name_location
),
$source->getSuppressedIssues()
)) {
// fall through
}
);
} elseif ($classlike_storage->abstract) {
if (\Psalm\IssueBuffer::accepts(
\Psalm\IssueBuffer::maybeAdd(
new InvalidAttribute(
'Abstract classes cannot act as attribute classes',
$attribute->name_location
),
$source->getSuppressedIssues()
)) {
// fall through
}
);
} elseif (isset($classlike_storage->methods['__construct'])
&& $classlike_storage->methods['__construct']->visibility !== ClassLikeAnalyzer::VISIBILITY_PUBLIC
) {
if (\Psalm\IssueBuffer::accepts(
\Psalm\IssueBuffer::maybeAdd(
new InvalidAttribute(
'Classes with protected/private constructors cannot act as attribute classes',
$attribute->name_location
),
$source->getSuppressedIssues()
)) {
// fall through
}
);
} elseif ($classlike_storage->is_enum) {
if (\Psalm\IssueBuffer::accepts(
\Psalm\IssueBuffer::maybeAdd(
new InvalidAttribute(
'Enums cannot act as attribute classes',
$attribute->name_location
),
$source->getSuppressedIssues()
)) {
// fall through
}
);
}
}

Expand Down Expand Up @@ -235,29 +225,25 @@ private static function checkAttributeTargets(
32 => 'function/method parameter'
];

if (\Psalm\IssueBuffer::accepts(
\Psalm\IssueBuffer::maybeAdd(
new InvalidAttribute(
'This attribute can not be used on a ' . $target_map[$target],
$attribute->name_location
),
$source->getSuppressedIssues()
)) {
// fall through
}
);
}
}
}

if (!$has_attribute_attribute) {
if (\Psalm\IssueBuffer::accepts(
\Psalm\IssueBuffer::maybeAdd(
new InvalidAttribute(
'The class ' . $attribute->fq_class_name . ' doesn’t have the Attribute attribute',
$attribute->name_location
),
$source->getSuppressedIssues()
)) {
// fall through
}
);
}
}
}

0 comments on commit 175ba83

Please sign in to comment.