mirror of
https://github.com/danog/psalm.git
synced 2024-11-26 20:34:47 +01:00
Change the Issue type and add documentation
This commit is contained in:
parent
cad5288484
commit
aa85669645
@ -250,6 +250,7 @@
|
||||
<xs:element name="InaccessibleClassConstant" type="IssueHandlerType" minOccurs="0" />
|
||||
<xs:element name="InaccessibleMethod" type="MethodIssueHandlerType" minOccurs="0" />
|
||||
<xs:element name="InaccessibleProperty" type="IssueHandlerType" minOccurs="0" />
|
||||
<xs:element name="InheritorViolation" type="ClassIssueHandlerType" minOccurs="0" />
|
||||
<xs:element name="InterfaceInstantiation" type="IssueHandlerType" minOccurs="0" />
|
||||
<xs:element name="InternalClass" type="ClassIssueHandlerType" minOccurs="0" />
|
||||
<xs:element name="InternalMethod" type="MethodIssueHandlerType" minOccurs="0" />
|
||||
|
@ -743,19 +743,13 @@ Used to tell Psalm that a class can only be extended by a certain subset of clas
|
||||
|
||||
For example,
|
||||
```php
|
||||
<?php
|
||||
/**
|
||||
* @psalm-inheritors FooClass|BarClass
|
||||
*/
|
||||
class BaseClass {}
|
||||
|
||||
class FooClass extends BaseClass {
|
||||
public function thing(string $s) : void { return $s . "hello"; }
|
||||
}
|
||||
|
||||
class BarClass extends BaseClass {
|
||||
public function thing(int $i) : string { return $i . "hello"; }
|
||||
}
|
||||
|
||||
class FooClass extends BaseClass {}
|
||||
class BarClass extends BaseClass {}
|
||||
class BazClass extends BaseClass {} // this is an error
|
||||
```
|
||||
|
||||
|
@ -52,6 +52,7 @@
|
||||
- [InaccessibleClassConstant](issues/InaccessibleClassConstant.md)
|
||||
- [InaccessibleMethod](issues/InaccessibleMethod.md)
|
||||
- [InaccessibleProperty](issues/InaccessibleProperty.md)
|
||||
- [InheritorViolation](issues/InheritorViolation.md)
|
||||
- [InterfaceInstantiation](issues/InterfaceInstantiation.md)
|
||||
- [InternalClass](issues/InternalClass.md)
|
||||
- [InternalMethod](issues/InternalMethod.md)
|
||||
|
17
docs/running_psalm/issues/InheritorViolation.md
Normal file
17
docs/running_psalm/issues/InheritorViolation.md
Normal file
@ -0,0 +1,17 @@
|
||||
# InheritorViolation
|
||||
|
||||
Emitted when a class/interface using `@psalm-inheritors` is extended/implemented
|
||||
by a class that does not fulfil it's requirements.
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @psalm-inheritors FooClass|BarClass
|
||||
*/
|
||||
class BaseClass {}
|
||||
class BazClass extends BaseClass {}
|
||||
// InheritorViolation is emitted, as BaseClass can only be extended
|
||||
// by FooClass|BarClass, which is not the case
|
||||
$a = new BazClass();
|
||||
```
|
@ -14,8 +14,8 @@ use Psalm\Internal\Type\Comparator\UnionTypeComparator;
|
||||
use Psalm\Internal\Type\TemplateResult;
|
||||
use Psalm\Internal\Type\TemplateStandinTypeReplacer;
|
||||
use Psalm\Issue\InaccessibleProperty;
|
||||
use Psalm\Issue\InheritorViolation;
|
||||
use Psalm\Issue\InvalidClass;
|
||||
use Psalm\Issue\InvalidExtendClass;
|
||||
use Psalm\Issue\InvalidTemplateParam;
|
||||
use Psalm\Issue\MissingDependency;
|
||||
use Psalm\Issue\MissingTemplateParam;
|
||||
@ -340,10 +340,9 @@ abstract class ClassLikeAnalyzer extends SourceAnalyzer
|
||||
if ($parent_storage && $parent_storage->inheritors) {
|
||||
if (!UnionTypeComparator::isContainedBy($codebase, $classUnion, $parent_storage->inheritors)) {
|
||||
IssueBuffer::maybeAdd(
|
||||
new InvalidExtendClass(
|
||||
new InheritorViolation(
|
||||
'Class ' . $fq_class_name . ' is not an allowed inheritor of parent class ' . $parent_class,
|
||||
$code_location,
|
||||
$fq_class_name,
|
||||
),
|
||||
$suppressed_issues,
|
||||
);
|
||||
|
9
src/Psalm/Issue/InheritorViolation.php
Normal file
9
src/Psalm/Issue/InheritorViolation.php
Normal file
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Psalm\Issue;
|
||||
|
||||
final class InheritorViolation extends CodeIssue
|
||||
{
|
||||
public const ERROR_LEVEL = 4;
|
||||
public const SHORTCODE = 283;
|
||||
}
|
@ -1393,7 +1393,7 @@ class ClassTest extends TestCase
|
||||
class BazClass extends BaseClass {} // this is an error
|
||||
$a = new BazClass();
|
||||
PHP,
|
||||
'error_message' => 'InvalidExtendClass',
|
||||
'error_message' => 'InheritorViolation',
|
||||
'ignored_issues' => [],
|
||||
],
|
||||
'classCannotImplementIfNotInInheritors' => [
|
||||
@ -1406,7 +1406,7 @@ class ClassTest extends TestCase
|
||||
class BazClass implements BaseInterface {}
|
||||
$a = new BazClass();
|
||||
PHP,
|
||||
'error_message' => 'InvalidExtendClass',
|
||||
'error_message' => 'InheritorViolation',
|
||||
'ignored_issues' => [],
|
||||
],
|
||||
'UnfulfilledInterfaceInheritors' => [
|
||||
@ -1423,7 +1423,7 @@ class ClassTest extends TestCase
|
||||
class BazClass implements InterFaceA, InterFaceB {}
|
||||
$a = new BazClass();
|
||||
PHP,
|
||||
'error_message' => 'InvalidExtendClass',
|
||||
'error_message' => 'InheritorViolation',
|
||||
'ignored_issues' => [],
|
||||
],
|
||||
];
|
||||
|
Loading…
Reference in New Issue
Block a user