Skip to content

Commit

Permalink
Reinstate MethodSignatureMustProvideReturnType
Browse files Browse the repository at this point in the history
It's never emitted, but is there for BC.
  • Loading branch information
weirdan committed Jan 31, 2022
1 parent 3ae0677 commit f61193b
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions config.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@
<xs:element name="LoopInvalidation" type="IssueHandlerType" minOccurs="0" />
<xs:element name="MethodSignatureMismatch" type="IssueHandlerType" minOccurs="0" />
<xs:element name="MethodSignatureMustOmitReturnType" type="IssueHandlerType" minOccurs="0" />
<xs:element name="MethodSignatureMustProvideReturnType" type="IssueHandlerType" minOccurs="0" />
<xs:element name="MismatchingDocblockParamType" type="IssueHandlerType" minOccurs="0" />
<xs:element name="MismatchingDocblockPropertyType" type="IssueHandlerType" minOccurs="0" />
<xs:element name="MismatchingDocblockReturnType" type="IssueHandlerType" minOccurs="0" />
Expand Down
1 change: 1 addition & 0 deletions docs/running_psalm/error_levels.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ Level 5 and above allows a more non-verifiable code, and higher levels are even
- [InvalidThrow](issues/InvalidThrow.md)
- [LoopInvalidation](issues/LoopInvalidation.md)
- [MethodSignatureMustOmitReturnType](issues/MethodSignatureMustOmitReturnType.md)
- [MethodSignatureMustProvideReturnType](issues/MethodSignatureMustProvideReturnType.md)
- [MissingDependency](issues/MissingDependency.md)
- [MissingFile](issues/MissingFile.md)
- [MissingImmutableAnnotation](issues/MissingImmutableAnnotation.md)
Expand Down
1 change: 1 addition & 0 deletions docs/running_psalm/issues.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
- [LoopInvalidation](issues/LoopInvalidation.md)
- [MethodSignatureMismatch](issues/MethodSignatureMismatch.md)
- [MethodSignatureMustOmitReturnType](issues/MethodSignatureMustOmitReturnType.md)
- [MethodSignatureMustProvideReturnType](issues/MethodSignatureMustProvideReturnType.md)
- [MismatchingDocblockParamType](issues/MismatchingDocblockParamType.md)
- [MismatchingDocblockPropertyType](issues/MismatchingDocblockPropertyType.md)
- [MismatchingDocblockReturnType](issues/MismatchingDocblockReturnType.md)
Expand Down
16 changes: 16 additions & 0 deletions docs/running_psalm/issues/MethodSignatureMustProvideReturnType.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# MethodSignatureMustProvideReturnType

In PHP 8.1+, [most non-final internal methods now require overriding methods to declare a compatible return type, otherwise a deprecated notice is emitted during inheritance validation](https://www.php.net/manual/en/migration81.incompatible.php#migration81.incompatible.core.type-compatibility-internal).

This issue is emitted when a method overriding a native method is defined without a return type.

**Only if** the return type cannot be declared to keep support for PHP 7, a `#[ReturnTypeWillChange]` attribute can be added to silence the PHP deprecation notice and Psalm issue.

```php
<?php
class A implements JsonSerializable {
public function jsonSerialize() {
return ['type' => 'A'];
}
}
```
9 changes: 9 additions & 0 deletions src/Psalm/Issue/MethodSignatureMustProvideReturnType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Psalm\Issue;

class MethodSignatureMustProvideReturnType extends CodeIssue
{
public const ERROR_LEVEL = -1;
public const SHORTCODE = 282;
}
4 changes: 4 additions & 0 deletions tests/DocumentationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,10 @@ public function providerInvalidCodeParse(): array
case 'TraitMethodSignatureMismatch':
continue 2;

/** @todo reinstate this test when the issue is restored */
case 'MethodSignatureMustProvideReturnType':
continue 2;

case 'InvalidFalsableReturnType':
$ignored_issues = ['FalsableReturnStatement'];
break;
Expand Down

0 comments on commit f61193b

Please sign in to comment.