mirror of
https://github.com/danog/psalm.git
synced 2024-11-26 12:24:49 +01:00
Fix #4656 - separate UnusedConstructor from UnusedMethod
This commit is contained in:
parent
2b19795f29
commit
684340cbe3
@ -427,6 +427,7 @@
|
||||
<xs:element name="UnsafeInstantiation" type="IssueHandlerType" minOccurs="0" />
|
||||
<xs:element name="UnusedClass" type="ClassIssueHandlerType" minOccurs="0" />
|
||||
<xs:element name="UnusedClosureParam" type="IssueHandlerType" minOccurs="0" />
|
||||
<xs:element name="UnusedConstructor" type="MethodIssueHandlerType" minOccurs="0" />
|
||||
<xs:element name="UnusedFunctionCall" type="FunctionIssueHandlerType" minOccurs="0" />
|
||||
<xs:element name="UnusedMethod" type="MethodIssueHandlerType" minOccurs="0" />
|
||||
<xs:element name="UnusedMethodCall" type="MethodIssueHandlerType" minOccurs="0" />
|
||||
|
14
docs/running_psalm/issues/UnusedConstructor.md
Normal file
14
docs/running_psalm/issues/UnusedConstructor.md
Normal file
@ -0,0 +1,14 @@
|
||||
# UnusedConstructor
|
||||
|
||||
Emitted when `--find-dead-code` is turned on and Psalm cannot find any uses of a given private constructor or function
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
class A {
|
||||
private function __construct() {}
|
||||
|
||||
public static function createInstance() : void {}
|
||||
}
|
||||
A::createInstance();
|
||||
```
|
@ -1557,6 +1557,10 @@ class Config
|
||||
return 'UnusedParam';
|
||||
}
|
||||
|
||||
if ($issue_type === 'UnusedConstructor') {
|
||||
return 'UnusedMethod';
|
||||
}
|
||||
|
||||
if ($issue_type === 'StringIncrement') {
|
||||
return 'InvalidOperand';
|
||||
}
|
||||
|
@ -26,6 +26,7 @@ use Psalm\Issue\PossiblyUnusedMethod;
|
||||
use Psalm\Issue\PossiblyUnusedParam;
|
||||
use Psalm\Issue\PossiblyUnusedProperty;
|
||||
use Psalm\Issue\UnusedClass;
|
||||
use Psalm\Issue\UnusedConstructor;
|
||||
use Psalm\Issue\UnusedMethod;
|
||||
use Psalm\Issue\UnusedProperty;
|
||||
use Psalm\IssueBuffer;
|
||||
@ -1659,13 +1660,23 @@ class ClassLikes
|
||||
strtolower($classlike_storage->name . '::')
|
||||
) || $codebase->analyzer->hasMixedMemberName($method_name);
|
||||
|
||||
$issue = new UnusedMethod(
|
||||
'Cannot find ' . ($has_variable_calls ? 'explicit' : 'any')
|
||||
. ' calls to private method ' . $method_id
|
||||
. ($has_variable_calls ? ' (but did find some potential callers)' : ''),
|
||||
$method_location,
|
||||
$method_id
|
||||
);
|
||||
if ($method_name === '__construct') {
|
||||
$issue = new UnusedConstructor(
|
||||
'Cannot find ' . ($has_variable_calls ? 'explicit' : 'any')
|
||||
. ' calls to private constructor ' . $method_id
|
||||
. ($has_variable_calls ? ' (but did find some potential callers)' : ''),
|
||||
$method_location,
|
||||
$method_id
|
||||
);
|
||||
} else {
|
||||
$issue = new UnusedMethod(
|
||||
'Cannot find ' . ($has_variable_calls ? 'explicit' : 'any')
|
||||
. ' calls to private method ' . $method_id
|
||||
. ($has_variable_calls ? ' (but did find some potential callers)' : ''),
|
||||
$method_location,
|
||||
$method_id
|
||||
);
|
||||
}
|
||||
|
||||
if ($codebase->alter_code) {
|
||||
if ($method_storage->stmt_location
|
||||
|
8
src/Psalm/Issue/UnusedConstructor.php
Normal file
8
src/Psalm/Issue/UnusedConstructor.php
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
namespace Psalm\Issue;
|
||||
|
||||
class UnusedConstructor extends MethodIssue
|
||||
{
|
||||
public const ERROR_LEVEL = -2;
|
||||
public const SHORTCODE = 258;
|
||||
}
|
Loading…
Reference in New Issue
Block a user