mirror of
https://github.com/danog/psalm.git
synced 2024-12-02 09:37: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="InvalidScope" type="IssueHandlerType" minOccurs="0" />
|
||||||
<xs:element name="InvalidStaticInvocation" type="IssueHandlerType" minOccurs="0" />
|
<xs:element name="InvalidStaticInvocation" type="IssueHandlerType" minOccurs="0" />
|
||||||
<xs:element name="InvalidStaticVariable" 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="InvalidThrow" type="IssueHandlerType" minOccurs="0" />
|
||||||
<xs:element name="InvalidToString" type="IssueHandlerType" minOccurs="0" />
|
<xs:element name="InvalidToString" type="IssueHandlerType" minOccurs="0" />
|
||||||
<xs:element name="LessSpecificReturnStatement" type="IssueHandlerType" minOccurs="0" />
|
<xs:element name="LessSpecificReturnStatement" type="IssueHandlerType" minOccurs="0" />
|
||||||
|
@ -340,6 +340,16 @@ class Foo {}
|
|||||||
(new 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
|
### InvalidClone
|
||||||
|
|
||||||
Emitted when trying to clone a value that's not cloneable
|
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\AbstractInstantiation;
|
||||||
use Psalm\Issue\DeprecatedClass;
|
use Psalm\Issue\DeprecatedClass;
|
||||||
use Psalm\Issue\InterfaceInstantiation;
|
use Psalm\Issue\InterfaceInstantiation;
|
||||||
use Psalm\Issue\InvalidClass;
|
use Psalm\Issue\InvalidStringClass;
|
||||||
use Psalm\Issue\TooManyArguments;
|
use Psalm\Issue\TooManyArguments;
|
||||||
|
use Psalm\Issue\UndefinedClass;
|
||||||
use Psalm\IssueBuffer;
|
use Psalm\IssueBuffer;
|
||||||
use Psalm\Type;
|
use Psalm\Type;
|
||||||
use Psalm\Type\Atomic\TNamedObject;
|
use Psalm\Type\Atomic\TNamedObject;
|
||||||
@ -125,12 +126,26 @@ class NewChecker extends \Psalm\Checker\Statements\Expression\CallChecker
|
|||||||
) {
|
) {
|
||||||
continue;
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IssueBuffer::accepts(
|
if (IssueBuffer::accepts(
|
||||||
new InvalidClass(
|
new UndefinedClass(
|
||||||
'Type ' . $lhs_type_part . ' cannot be called as a class',
|
'Type ' . $lhs_type_part . ' cannot be called as a class',
|
||||||
new CodeLocation($statements_checker->getSource(), $stmt)
|
new CodeLocation($statements_checker->getSource(), $stmt)
|
||||||
),
|
),
|
||||||
|
@ -11,8 +11,9 @@ use Psalm\Config;
|
|||||||
use Psalm\Context;
|
use Psalm\Context;
|
||||||
use Psalm\FileManipulation\FileManipulationBuffer;
|
use Psalm\FileManipulation\FileManipulationBuffer;
|
||||||
use Psalm\Issue\DeprecatedClass;
|
use Psalm\Issue\DeprecatedClass;
|
||||||
use Psalm\Issue\InvalidClass;
|
use Psalm\Issue\InvalidStringClass;
|
||||||
use Psalm\Issue\ParentNotFound;
|
use Psalm\Issue\ParentNotFound;
|
||||||
|
use Psalm\Issue\UndefinedClass;
|
||||||
use Psalm\IssueBuffer;
|
use Psalm\IssueBuffer;
|
||||||
use Psalm\Type;
|
use Psalm\Type;
|
||||||
use Psalm\Type\Atomic\TNamedObject;
|
use Psalm\Type\Atomic\TNamedObject;
|
||||||
@ -205,12 +206,26 @@ class StaticCallChecker extends \Psalm\Checker\Statements\Expression\CallChecker
|
|||||||
) {
|
) {
|
||||||
continue;
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IssueBuffer::accepts(
|
if (IssueBuffer::accepts(
|
||||||
new InvalidClass(
|
new UndefinedClass(
|
||||||
'Type ' . $lhs_type_part . ' cannot be called as a class',
|
'Type ' . $lhs_type_part . ' cannot be called as a class',
|
||||||
new CodeLocation($statements_checker->getSource(), $stmt)
|
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
|
* @expectedException \Psalm\Exception\CodeException
|
||||||
* @expectedExceptionMessage InvalidClass
|
* @expectedExceptionMessage InvalidStringClass
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
@ -156,7 +156,7 @@ class AnnotationTest extends TestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \Psalm\Exception\CodeException
|
* @expectedException \Psalm\Exception\CodeException
|
||||||
* @expectedExceptionMessage InvalidClass
|
* @expectedExceptionMessage InvalidStringClass
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
|
@ -148,6 +148,9 @@ class DocumentationTest extends TestCase
|
|||||||
|
|
||||||
foreach (self::getCodeBlocksFromDocs() as $issue_name => $blocks) {
|
foreach (self::getCodeBlocksFromDocs() as $issue_name => $blocks) {
|
||||||
switch ($issue_name) {
|
switch ($issue_name) {
|
||||||
|
case 'InvalidStringClass':
|
||||||
|
continue 2;
|
||||||
|
|
||||||
case 'InvalidFalsableReturnType':
|
case 'InvalidFalsableReturnType':
|
||||||
$ignored_issues = ['FalsableReturnStatement'];
|
$ignored_issues = ['FalsableReturnStatement'];
|
||||||
break;
|
break;
|
||||||
|
@ -271,13 +271,13 @@ class MethodCallTest extends TestCase
|
|||||||
'<?php
|
'<?php
|
||||||
$a = 5;
|
$a = 5;
|
||||||
$a::bar();',
|
$a::bar();',
|
||||||
'error_message' => 'InvalidClass',
|
'error_message' => 'UndefinedClass',
|
||||||
],
|
],
|
||||||
'intVarNewCall' => [
|
'intVarNewCall' => [
|
||||||
'<?php
|
'<?php
|
||||||
$a = 5;
|
$a = 5;
|
||||||
new $a();',
|
new $a();',
|
||||||
'error_message' => 'InvalidClass',
|
'error_message' => 'UndefinedClass',
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user