mirror of
https://github.com/danog/psalm.git
synced 2024-11-29 20:28:59 +01:00
Add new issue conditional on config flag
This commit is contained in:
parent
357ad1aa82
commit
b664c85642
@ -137,6 +137,7 @@
|
||||
<xs:element name="InvalidScope" type="IssueHandlerType" minOccurs="0" />
|
||||
<xs:element name="InvalidStaticInvocation" type="IssueHandlerType" minOccurs="0" />
|
||||
<xs:element name="InvalidStaticVariable" type="IssueHandlerType" minOccurs="0" />
|
||||
<xs:element name="InvalidStringClass" type="IssueHandlerType" minOccurs="0" />
|
||||
<xs:element name="InvalidThrow" type="IssueHandlerType" minOccurs="0" />
|
||||
<xs:element name="InvalidToString" type="IssueHandlerType" minOccurs="0" />
|
||||
<xs:element name="LessSpecificReturnStatement" type="IssueHandlerType" minOccurs="0" />
|
||||
|
@ -340,6 +340,16 @@ class Foo {}
|
||||
(new foo());
|
||||
```
|
||||
|
||||
### InvalidStringClass
|
||||
|
||||
Emitted when you have `allowStringToStandInForClass="false"` in your config and you’re passing a string instead of calling a class directly
|
||||
|
||||
```php
|
||||
class Foo {}
|
||||
$a = "Foo";
|
||||
new $a();
|
||||
```
|
||||
|
||||
### InvalidClone
|
||||
|
||||
Emitted when trying to clone a value that's not cloneable
|
||||
|
@ -12,8 +12,9 @@ use Psalm\Context;
|
||||
use Psalm\Issue\AbstractInstantiation;
|
||||
use Psalm\Issue\DeprecatedClass;
|
||||
use Psalm\Issue\InterfaceInstantiation;
|
||||
use Psalm\Issue\InvalidClass;
|
||||
use Psalm\Issue\InvalidStringClass;
|
||||
use Psalm\Issue\TooManyArguments;
|
||||
use Psalm\Issue\UndefinedClass;
|
||||
use Psalm\IssueBuffer;
|
||||
use Psalm\Type;
|
||||
use Psalm\Type\Atomic\TNamedObject;
|
||||
@ -125,12 +126,26 @@ class NewChecker extends \Psalm\Checker\Statements\Expression\CallChecker
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
} elseif ($lhs_type_part instanceof Type\Atomic\TMixed) {
|
||||
|
||||
if (IssueBuffer::accepts(
|
||||
new InvalidStringClass(
|
||||
'String cannot be used as a class',
|
||||
new CodeLocation($statements_checker->getSource(), $stmt)
|
||||
),
|
||||
$statements_checker->getSuppressedIssues()
|
||||
)) {
|
||||
// fall through
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($lhs_type_part instanceof Type\Atomic\TMixed) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (IssueBuffer::accepts(
|
||||
new InvalidClass(
|
||||
new UndefinedClass(
|
||||
'Type ' . $lhs_type_part . ' cannot be called as a class',
|
||||
new CodeLocation($statements_checker->getSource(), $stmt)
|
||||
),
|
||||
|
@ -11,8 +11,9 @@ use Psalm\Config;
|
||||
use Psalm\Context;
|
||||
use Psalm\FileManipulation\FileManipulationBuffer;
|
||||
use Psalm\Issue\DeprecatedClass;
|
||||
use Psalm\Issue\InvalidClass;
|
||||
use Psalm\Issue\InvalidStringClass;
|
||||
use Psalm\Issue\ParentNotFound;
|
||||
use Psalm\Issue\UndefinedClass;
|
||||
use Psalm\IssueBuffer;
|
||||
use Psalm\Type;
|
||||
use Psalm\Type\Atomic\TNamedObject;
|
||||
@ -205,12 +206,26 @@ class StaticCallChecker extends \Psalm\Checker\Statements\Expression\CallChecker
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
} elseif ($lhs_type_part instanceof Type\Atomic\TMixed) {
|
||||
|
||||
if (IssueBuffer::accepts(
|
||||
new InvalidStringClass(
|
||||
'String cannot be used as a class',
|
||||
new CodeLocation($statements_checker->getSource(), $stmt)
|
||||
),
|
||||
$statements_checker->getSuppressedIssues()
|
||||
)) {
|
||||
// fall through
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($lhs_type_part instanceof Type\Atomic\TMixed) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (IssueBuffer::accepts(
|
||||
new InvalidClass(
|
||||
new UndefinedClass(
|
||||
'Type ' . $lhs_type_part . ' cannot be called as a class',
|
||||
new CodeLocation($statements_checker->getSource(), $stmt)
|
||||
),
|
||||
|
6
src/Psalm/Issue/InvalidStringClass.php
Normal file
6
src/Psalm/Issue/InvalidStringClass.php
Normal file
@ -0,0 +1,6 @@
|
||||
<?php
|
||||
namespace Psalm\Issue;
|
||||
|
||||
class InvalidStringClass extends CodeIssue
|
||||
{
|
||||
}
|
@ -133,7 +133,7 @@ class AnnotationTest extends TestCase
|
||||
|
||||
/**
|
||||
* @expectedException \Psalm\Exception\CodeException
|
||||
* @expectedExceptionMessage InvalidClass
|
||||
* @expectedExceptionMessage InvalidStringClass
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
@ -156,7 +156,7 @@ class AnnotationTest extends TestCase
|
||||
|
||||
/**
|
||||
* @expectedException \Psalm\Exception\CodeException
|
||||
* @expectedExceptionMessage InvalidClass
|
||||
* @expectedExceptionMessage InvalidStringClass
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
|
@ -148,6 +148,9 @@ class DocumentationTest extends TestCase
|
||||
|
||||
foreach (self::getCodeBlocksFromDocs() as $issue_name => $blocks) {
|
||||
switch ($issue_name) {
|
||||
case 'InvalidStringClass':
|
||||
continue 2;
|
||||
|
||||
case 'InvalidFalsableReturnType':
|
||||
$ignored_issues = ['FalsableReturnStatement'];
|
||||
break;
|
||||
|
@ -271,13 +271,13 @@ class MethodCallTest extends TestCase
|
||||
'<?php
|
||||
$a = 5;
|
||||
$a::bar();',
|
||||
'error_message' => 'InvalidClass',
|
||||
'error_message' => 'UndefinedClass',
|
||||
],
|
||||
'intVarNewCall' => [
|
||||
'<?php
|
||||
$a = 5;
|
||||
new $a();',
|
||||
'error_message' => 'InvalidClass',
|
||||
'error_message' => 'UndefinedClass',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user