mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Add complex issue error
This commit is contained in:
parent
0b292a55c1
commit
3be31563d6
@ -187,6 +187,8 @@
|
||||
<xs:element name="ArgumentTypeCoercion" type="ArgumentIssueHandlerType" minOccurs="0" />
|
||||
<xs:element name="AssignmentToVoid" type="IssueHandlerType" minOccurs="0" />
|
||||
<xs:element name="CircularReference" type="IssueHandlerType" minOccurs="0" />
|
||||
<xs:element name="ComplexFunction" type="IssueHandlerType" minOccurs="0" />
|
||||
<xs:element name="ComplexMethod" type="IssueHandlerType" minOccurs="0" />
|
||||
<xs:element name="ConflictingReferenceConstraint" type="IssueHandlerType" minOccurs="0" />
|
||||
<xs:element name="ConstructorSignatureMismatch" type="IssueHandlerType" minOccurs="0" />
|
||||
<xs:element name="ContinueOutsideLoop" type="IssueHandlerType" minOccurs="0" />
|
||||
|
@ -30,6 +30,8 @@ use Psalm\DocComment;
|
||||
use Psalm\Exception\DocblockParseException;
|
||||
use Psalm\FileManipulation;
|
||||
use Psalm\Internal\FileManipulation\FileManipulationBuffer;
|
||||
use Psalm\Issue\ComplexFunction;
|
||||
use Psalm\Issue\ComplexMethod;
|
||||
use Psalm\Issue\InvalidDocblock;
|
||||
use Psalm\Issue\MissingDocblockType;
|
||||
use Psalm\Issue\Trace;
|
||||
@ -699,6 +701,8 @@ class StatementsAnalyzer extends SourceAnalyzer
|
||||
&& $codebase->config->limit_method_complexity
|
||||
&& $source instanceof FunctionLikeAnalyzer
|
||||
&& !$source instanceof ClosureAnalyzer
|
||||
&& $function_storage
|
||||
&& $function_storage->location
|
||||
) {
|
||||
[$count, $branching, $mean] = $this->data_flow_graph->getEdgeStats();
|
||||
|
||||
@ -706,8 +710,31 @@ class StatementsAnalyzer extends SourceAnalyzer
|
||||
&& $mean > $codebase->config->max_avg_path_length
|
||||
&& $branching > 1.1
|
||||
) {
|
||||
echo $source->getId() . ' ' . $count . ' ' . round($mean) . ' ' . $branching . "\n";
|
||||
// do something else
|
||||
if ($source instanceof FunctionAnalyzer) {
|
||||
if (IssueBuffer::accepts(
|
||||
new ComplexFunction(
|
||||
'This function’s complexity is greater than the project limit'
|
||||
. ' (method graph size = ' . $count .', average path length = ' . round($mean). ')',
|
||||
$function_storage->location
|
||||
),
|
||||
$this->getSuppressedIssues(),
|
||||
true
|
||||
)) {
|
||||
// fall through
|
||||
}
|
||||
} elseif ($source instanceof MethodAnalyzer) {
|
||||
if (IssueBuffer::accepts(
|
||||
new ComplexMethod(
|
||||
'This method’s complexity is greater than the project limit'
|
||||
. ' (method graph size = ' . $count .', average path length = ' . round($mean) . ')',
|
||||
$function_storage->location
|
||||
),
|
||||
$this->getSuppressedIssues(),
|
||||
true
|
||||
)) {
|
||||
// fall through
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
8
src/Psalm/Issue/ComplexFunction.php
Normal file
8
src/Psalm/Issue/ComplexFunction.php
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
namespace Psalm\Issue;
|
||||
|
||||
class ComplexFunction extends CodeIssue
|
||||
{
|
||||
public const ERROR_LEVEL = -1;
|
||||
public const SHORTCODE = 259;
|
||||
}
|
8
src/Psalm/Issue/ComplexMethod.php
Normal file
8
src/Psalm/Issue/ComplexMethod.php
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
namespace Psalm\Issue;
|
||||
|
||||
class ComplexMethod extends CodeIssue
|
||||
{
|
||||
public const ERROR_LEVEL = -1;
|
||||
public const SHORTCODE = 260;
|
||||
}
|
@ -132,6 +132,8 @@ class DocumentationTest extends TestCase
|
||||
$code_blocks['PluginIssue'] = true;
|
||||
$code_blocks['TaintedInput'] = true;
|
||||
$code_blocks['TaintedCustom'] = true;
|
||||
$code_blocks['ComplexFunction'] = true;
|
||||
$code_blocks['ComplexMethod'] = true;
|
||||
|
||||
$documented_issues = array_keys($code_blocks);
|
||||
sort($documented_issues);
|
||||
|
Loading…
Reference in New Issue
Block a user