2016-12-15 01:24:33 +01:00
|
|
|
<?php
|
2021-12-15 04:58:32 +01:00
|
|
|
|
2016-12-15 01:24:33 +01:00
|
|
|
namespace Psalm\Tests;
|
|
|
|
|
2021-06-08 04:55:21 +02:00
|
|
|
use Psalm\Context;
|
2021-12-03 20:29:06 +01:00
|
|
|
use Psalm\Exception\CodeException;
|
2021-12-04 21:55:53 +01:00
|
|
|
use Psalm\Tests\Traits\InvalidCodeAnalysisTestTrait;
|
|
|
|
use Psalm\Tests\Traits\ValidCodeAnalysisTestTrait;
|
2021-06-08 04:55:21 +02:00
|
|
|
|
2019-06-26 22:52:29 +02:00
|
|
|
use const DIRECTORY_SEPARATOR;
|
2016-12-15 01:24:33 +01:00
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
class MethodSignatureTest extends TestCase
|
2016-12-15 01:24:33 +01:00
|
|
|
{
|
2021-12-04 21:55:53 +01:00
|
|
|
use ValidCodeAnalysisTestTrait;
|
|
|
|
use InvalidCodeAnalysisTestTrait;
|
2017-02-09 23:49:13 +01:00
|
|
|
|
2021-11-26 20:59:41 +01:00
|
|
|
public function testExtendSoapClientWithDocblockTypes(): void
|
2017-02-09 23:49:13 +01:00
|
|
|
{
|
2017-07-25 22:11:02 +02:00
|
|
|
$this->addFile(
|
|
|
|
'somefile.php',
|
|
|
|
'<?php
|
|
|
|
class A extends SoapClient
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @param string $function_name
|
|
|
|
* @param array<mixed> $arguments
|
|
|
|
* @param array<mixed> $options default null
|
2019-05-14 21:44:46 +02:00
|
|
|
* @param array|SoapHeader $input_headers default null
|
2017-07-25 22:11:02 +02:00
|
|
|
* @param array<mixed> $output_headers default null
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function __soapCall(
|
|
|
|
$function_name,
|
|
|
|
$arguments,
|
|
|
|
$options = [],
|
|
|
|
$input_headers = [],
|
|
|
|
&$output_headers = []
|
|
|
|
) {
|
2018-07-17 02:32:16 +02:00
|
|
|
return $_GET["foo"];
|
2017-07-25 22:11:02 +02:00
|
|
|
}
|
2022-12-18 17:15:15 +01:00
|
|
|
}',
|
2019-05-14 21:44:46 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
$this->analyzeFile('somefile.php', new Context());
|
|
|
|
}
|
|
|
|
|
2021-11-26 20:59:41 +01:00
|
|
|
public function testExtendSoapClientWithNoDocblockTypes(): void
|
2019-05-14 21:44:46 +02:00
|
|
|
{
|
|
|
|
$this->addFile(
|
|
|
|
'somefile.php',
|
|
|
|
'<?php
|
|
|
|
class C extends SoapClient
|
2019-03-25 16:49:05 +01:00
|
|
|
{
|
|
|
|
public function __soapCall(
|
2019-05-14 21:44:46 +02:00
|
|
|
string $function_name,
|
2019-03-25 16:49:05 +01:00
|
|
|
$arguments,
|
|
|
|
$options = [],
|
|
|
|
$input_headers = [],
|
|
|
|
&$output_headers = []
|
|
|
|
) {
|
|
|
|
return $_GET["foo"];
|
|
|
|
}
|
2022-12-18 17:15:15 +01:00
|
|
|
}',
|
2019-05-14 21:44:46 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
$this->analyzeFile('somefile.php', new Context());
|
|
|
|
}
|
2019-03-25 16:49:05 +01:00
|
|
|
|
2021-11-26 20:59:41 +01:00
|
|
|
public function testExtendSoapClientWithParamType(): void
|
2019-05-14 21:44:46 +02:00
|
|
|
{
|
|
|
|
$this->addFile(
|
|
|
|
'somefile.php',
|
|
|
|
'<?php
|
2019-03-25 16:49:05 +01:00
|
|
|
class C extends SoapClient
|
|
|
|
{
|
|
|
|
public function __soapCall(
|
|
|
|
string $function_name,
|
|
|
|
$arguments,
|
|
|
|
$options = [],
|
|
|
|
$input_headers = [],
|
|
|
|
&$output_headers = []
|
|
|
|
) {
|
|
|
|
return $_GET["foo"];
|
|
|
|
}
|
2022-12-18 17:15:15 +01:00
|
|
|
}',
|
2017-07-25 22:11:02 +02:00
|
|
|
);
|
2017-02-09 23:49:13 +01:00
|
|
|
|
2018-01-21 16:22:04 +01:00
|
|
|
$this->analyzeFile('somefile.php', new Context());
|
2017-02-09 23:49:13 +01:00
|
|
|
}
|
|
|
|
|
2020-09-12 17:24:05 +02:00
|
|
|
public function testMismatchingCovariantReturnIn73(): void
|
2019-11-27 06:19:36 +01:00
|
|
|
{
|
|
|
|
$this->expectExceptionMessage('MethodSignatureMismatch');
|
2021-12-03 20:29:06 +01:00
|
|
|
$this->expectException(CodeException::class);
|
2019-11-27 06:19:36 +01:00
|
|
|
|
2021-11-27 01:06:33 +01:00
|
|
|
$this->project_analyzer->setPhpVersion('7.3', 'tests');
|
2019-11-27 06:19:36 +01:00
|
|
|
|
|
|
|
$this->addFile(
|
|
|
|
'somefile.php',
|
|
|
|
'<?php
|
|
|
|
class A {
|
|
|
|
function foo(): C {
|
|
|
|
return new C();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
class B extends A {
|
|
|
|
function foo(): D {
|
|
|
|
return new D();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
class C {}
|
2022-12-18 17:15:15 +01:00
|
|
|
class D extends C {}',
|
2019-11-27 06:19:36 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
$this->analyzeFile('somefile.php', new Context());
|
|
|
|
}
|
|
|
|
|
2020-09-12 17:24:05 +02:00
|
|
|
public function testMismatchingCovariantReturnIn74(): void
|
2019-11-27 06:19:36 +01:00
|
|
|
{
|
2021-11-27 01:06:33 +01:00
|
|
|
$this->project_analyzer->setPhpVersion('7.4', 'tests');
|
2019-11-27 06:19:36 +01:00
|
|
|
|
|
|
|
$this->addFile(
|
|
|
|
'somefile.php',
|
|
|
|
'<?php
|
|
|
|
class A {
|
|
|
|
function foo(): C {
|
|
|
|
return new C();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
class B extends A {
|
|
|
|
function foo(): D {
|
|
|
|
return new D();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
class C {}
|
2022-12-18 17:15:15 +01:00
|
|
|
class D extends C {}',
|
2019-11-27 06:19:36 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
$this->analyzeFile('somefile.php', new Context());
|
|
|
|
}
|
|
|
|
|
2020-09-12 17:24:05 +02:00
|
|
|
public function testMismatchingCovariantReturnIn73WithSelf(): void
|
2019-11-27 06:19:36 +01:00
|
|
|
{
|
|
|
|
$this->expectExceptionMessage('MethodSignatureMismatch');
|
2021-12-03 20:29:06 +01:00
|
|
|
$this->expectException(CodeException::class);
|
2019-11-27 06:19:36 +01:00
|
|
|
|
2021-11-27 01:06:33 +01:00
|
|
|
$this->project_analyzer->setPhpVersion('7.3', 'tests');
|
2019-11-27 06:19:36 +01:00
|
|
|
|
|
|
|
$this->addFile(
|
|
|
|
'somefile.php',
|
|
|
|
'<?php
|
|
|
|
class A {
|
|
|
|
function foo(): self {
|
|
|
|
return new A();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
class B extends A {
|
|
|
|
function foo(): self {
|
|
|
|
return new B();
|
|
|
|
}
|
2022-12-18 17:15:15 +01:00
|
|
|
}',
|
2019-11-27 06:19:36 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
$this->analyzeFile('somefile.php', new Context());
|
|
|
|
}
|
|
|
|
|
2020-09-12 17:24:05 +02:00
|
|
|
public function testMismatchingCovariantReturnIn74WithSelf(): void
|
2019-11-27 06:19:36 +01:00
|
|
|
{
|
2021-11-27 01:06:33 +01:00
|
|
|
$this->project_analyzer->setPhpVersion('7.4', 'tests');
|
2019-11-27 06:19:36 +01:00
|
|
|
|
|
|
|
$this->addFile(
|
|
|
|
'somefile.php',
|
|
|
|
'<?php
|
|
|
|
class A {
|
|
|
|
function foo(): self {
|
|
|
|
return new A();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
class B extends A {
|
|
|
|
function foo(): self {
|
|
|
|
return new B();
|
|
|
|
}
|
2022-12-18 17:15:15 +01:00
|
|
|
}',
|
2019-11-27 06:19:36 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
$this->analyzeFile('somefile.php', new Context());
|
|
|
|
}
|
|
|
|
|
2020-09-12 17:24:05 +02:00
|
|
|
public function testMismatchingCovariantParamIn73(): void
|
2019-11-27 06:19:36 +01:00
|
|
|
{
|
|
|
|
$this->expectExceptionMessage('MethodSignatureMismatch');
|
2021-12-03 20:29:06 +01:00
|
|
|
$this->expectException(CodeException::class);
|
2019-11-27 06:19:36 +01:00
|
|
|
|
2021-11-27 01:06:33 +01:00
|
|
|
$this->project_analyzer->setPhpVersion('7.3', 'tests');
|
2019-11-27 06:19:36 +01:00
|
|
|
|
|
|
|
$this->addFile(
|
|
|
|
'somefile.php',
|
|
|
|
'<?php
|
|
|
|
class A {
|
|
|
|
public function foo(D $d) : void {}
|
|
|
|
}
|
|
|
|
class B extends A {
|
|
|
|
public function foo(C $c): void {}
|
|
|
|
}
|
|
|
|
|
|
|
|
class C {}
|
2022-12-18 17:15:15 +01:00
|
|
|
class D extends C {}',
|
2019-11-27 06:19:36 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
$this->analyzeFile('somefile.php', new Context());
|
|
|
|
}
|
|
|
|
|
2020-09-12 17:24:05 +02:00
|
|
|
public function testMismatchingCovariantParamIn74(): void
|
2019-11-27 06:19:36 +01:00
|
|
|
{
|
2021-11-27 01:06:33 +01:00
|
|
|
$this->project_analyzer->setPhpVersion('7.4', 'tests');
|
2019-11-27 06:19:36 +01:00
|
|
|
|
|
|
|
$this->addFile(
|
|
|
|
'somefile.php',
|
|
|
|
'<?php
|
|
|
|
class A {
|
|
|
|
public function foo(D $d) : void {}
|
|
|
|
}
|
|
|
|
class B extends A {
|
|
|
|
public function foo(C $c): void {}
|
|
|
|
}
|
|
|
|
|
|
|
|
class C {}
|
2022-12-18 17:15:15 +01:00
|
|
|
class D extends C {}',
|
2019-11-27 06:19:36 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
$this->analyzeFile('somefile.php', new Context());
|
|
|
|
}
|
|
|
|
|
2021-11-26 20:59:41 +01:00
|
|
|
public function testExtendDocblockParamTypeWithWrongDocblockParam(): void
|
2017-02-09 23:49:13 +01:00
|
|
|
{
|
2019-05-17 00:36:36 +02:00
|
|
|
$this->expectExceptionMessage('ImplementedParamTypeMismatch');
|
2021-12-03 20:29:06 +01:00
|
|
|
$this->expectException(CodeException::class);
|
2017-04-25 05:45:02 +02:00
|
|
|
|
2017-07-25 22:11:02 +02:00
|
|
|
$this->addFile(
|
|
|
|
'somefile.php',
|
|
|
|
'<?php
|
|
|
|
class A extends SoapClient
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @param string $function_name
|
|
|
|
* @param string $arguments
|
|
|
|
* @param array<mixed> $options default null
|
|
|
|
* @param array<mixed> $input_headers default null
|
|
|
|
* @param array<mixed> $output_headers default null
|
|
|
|
* @return mixed
|
|
|
|
*/
|
2019-05-14 21:44:46 +02:00
|
|
|
public function __soapCall(
|
|
|
|
$function_name,
|
|
|
|
$arguments,
|
|
|
|
$options = [],
|
|
|
|
$input_headers = [],
|
|
|
|
&$output_headers = []
|
|
|
|
) {
|
|
|
|
|
|
|
|
}
|
2022-12-18 17:15:15 +01:00
|
|
|
}',
|
2019-05-14 21:44:46 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
$this->analyzeFile('somefile.php', new Context());
|
|
|
|
}
|
|
|
|
|
2021-12-05 18:51:26 +01:00
|
|
|
public function testExtendDocblockParamTypeWithWrongParam(): void
|
2019-05-14 21:44:46 +02:00
|
|
|
{
|
2021-12-03 20:29:06 +01:00
|
|
|
$this->expectException(CodeException::class);
|
2019-05-17 00:36:36 +02:00
|
|
|
$this->expectExceptionMessage('MethodSignatureMismatch');
|
|
|
|
|
2019-05-14 21:44:46 +02:00
|
|
|
$this->addFile(
|
|
|
|
'somefile.php',
|
|
|
|
'<?php
|
|
|
|
class A extends SoapClient
|
|
|
|
{
|
2017-07-25 22:11:02 +02:00
|
|
|
public function __soapCall(
|
|
|
|
$function_name,
|
|
|
|
string $arguments,
|
|
|
|
$options = [],
|
|
|
|
$input_headers = [],
|
|
|
|
&$output_headers = []
|
|
|
|
) {
|
2017-02-09 23:49:13 +01:00
|
|
|
|
2017-07-25 22:11:02 +02:00
|
|
|
}
|
2022-12-18 17:15:15 +01:00
|
|
|
}',
|
2017-07-25 22:11:02 +02:00
|
|
|
);
|
|
|
|
|
2018-01-21 16:22:04 +01:00
|
|
|
$this->analyzeFile('somefile.php', new Context());
|
2017-02-09 23:49:13 +01:00
|
|
|
}
|
2017-04-25 05:45:02 +02:00
|
|
|
|
2020-09-12 17:24:05 +02:00
|
|
|
public function providerValidCodeParse(): iterable
|
2017-11-09 03:27:23 +01:00
|
|
|
{
|
|
|
|
return [
|
|
|
|
'privateArgs' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2017-11-09 03:27:23 +01:00
|
|
|
class A {
|
2018-01-11 21:50:45 +01:00
|
|
|
private function foo(): void {}
|
2017-11-09 03:27:23 +01:00
|
|
|
}
|
|
|
|
class B extends A {
|
2018-01-11 21:50:45 +01:00
|
|
|
private function foo(int $arg): void {}
|
2017-11-09 03:27:23 +01:00
|
|
|
}',
|
|
|
|
],
|
2017-11-13 22:31:33 +01:00
|
|
|
'nullableSubclassParam' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2017-11-13 22:31:33 +01:00
|
|
|
class A {
|
2018-01-11 21:50:45 +01:00
|
|
|
public function foo(string $s): ?string {
|
2017-11-29 05:09:09 +01:00
|
|
|
return rand(0, 1) ? $s : null;
|
2017-11-13 22:31:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class B extends A {
|
2018-01-11 21:50:45 +01:00
|
|
|
public function foo(?string $s): string {
|
2017-11-13 22:31:33 +01:00
|
|
|
return $s ?: "hello";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
echo (new B)->foo(null);',
|
|
|
|
],
|
|
|
|
'nullableSubclassParamWithDefault' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2017-11-13 22:31:33 +01:00
|
|
|
class A {
|
2018-01-11 21:50:45 +01:00
|
|
|
public function foo(string $s): string {
|
2017-11-13 22:31:33 +01:00
|
|
|
return $s;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class B extends A {
|
2018-01-11 21:50:45 +01:00
|
|
|
public function foo(string $s = null): string {
|
2017-11-13 22:31:33 +01:00
|
|
|
return $s ?: "hello";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
echo (new B)->foo();',
|
|
|
|
],
|
2018-01-05 06:19:35 +01:00
|
|
|
'allowSubclassesForNonInheritedMethodParams' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2018-01-05 06:19:35 +01:00
|
|
|
class A {}
|
|
|
|
class B extends A {
|
2018-01-11 21:50:45 +01:00
|
|
|
public function bar(): void {}
|
2018-01-05 06:19:35 +01:00
|
|
|
}
|
|
|
|
class C extends A {
|
2018-01-11 21:50:45 +01:00
|
|
|
public function bar(): void {}
|
2018-01-05 06:19:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** @param B|C $a */
|
2018-01-11 21:50:45 +01:00
|
|
|
function foo(A $a): void {
|
2018-01-05 06:19:35 +01:00
|
|
|
$a->bar();
|
|
|
|
}',
|
|
|
|
],
|
2018-01-08 23:17:49 +01:00
|
|
|
'allowNoReturnInSubclassWithNullableReturnType' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2018-01-08 23:17:49 +01:00
|
|
|
class A {
|
|
|
|
/** @return ?int */
|
|
|
|
public function foo() {
|
|
|
|
if (rand(0, 1)) return 5;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class B extends A {
|
|
|
|
public function foo() {}
|
|
|
|
}',
|
|
|
|
],
|
2018-01-26 16:59:30 +01:00
|
|
|
'selfReturnShouldBeParent' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2018-01-26 16:59:30 +01:00
|
|
|
class A {
|
2020-03-24 23:58:15 +01:00
|
|
|
/** @return self */
|
|
|
|
public function foo() {
|
|
|
|
return new A();
|
|
|
|
}
|
2018-01-26 16:59:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
class B extends A {
|
2020-03-24 23:58:15 +01:00
|
|
|
public function foo() {
|
|
|
|
return new A();
|
|
|
|
}
|
2018-01-26 16:59:30 +01:00
|
|
|
}',
|
|
|
|
],
|
2018-01-26 19:51:00 +01:00
|
|
|
'staticReturnShouldBeStatic' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2018-01-26 19:51:00 +01:00
|
|
|
class A {
|
2020-03-24 23:58:15 +01:00
|
|
|
/** @return static */
|
|
|
|
public static function foo() {
|
|
|
|
return new static();
|
|
|
|
}
|
2020-08-06 01:39:27 +02:00
|
|
|
|
|
|
|
final public function __construct() {}
|
2018-01-26 19:51:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
class B extends A {
|
2020-03-24 23:58:15 +01:00
|
|
|
public static function foo() {
|
|
|
|
return new static();
|
|
|
|
}
|
2018-01-26 19:51:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$b = B::foo();',
|
|
|
|
'assertions' => [
|
|
|
|
'$b' => 'B',
|
|
|
|
],
|
|
|
|
],
|
2018-02-01 01:24:34 +01:00
|
|
|
'allowSomeCovariance' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2018-01-30 04:29:49 +01:00
|
|
|
interface I1 {
|
|
|
|
public function test(string $s) : ?string;
|
|
|
|
public function testIterable(array $a) : ?iterable;
|
|
|
|
}
|
|
|
|
|
|
|
|
class A1 implements I1 {
|
|
|
|
public function test(?string $s) : string {
|
|
|
|
return "value";
|
|
|
|
}
|
2021-05-09 01:33:48 +02:00
|
|
|
public function testIterable(?iterable $a) : array {
|
2018-01-30 04:29:49 +01:00
|
|
|
return [];
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
],
|
2018-02-01 01:24:34 +01:00
|
|
|
'allowVoidToNullConversion' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2018-02-01 01:24:34 +01:00
|
|
|
class A {
|
2020-11-12 19:54:27 +01:00
|
|
|
/** @return ?string */
|
|
|
|
public function foo() {
|
|
|
|
return rand(0, 1) ? "hello" : null;
|
|
|
|
}
|
2018-02-01 01:24:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
class B extends A {
|
2020-11-12 19:54:27 +01:00
|
|
|
public function foo(): void {
|
|
|
|
return;
|
|
|
|
}
|
2018-02-01 01:24:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
class C extends A {
|
2020-11-12 19:54:27 +01:00
|
|
|
/** @return void */
|
|
|
|
public function foo() {
|
|
|
|
return;
|
|
|
|
}
|
2018-02-01 01:24:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
class D extends A {
|
2020-11-12 19:54:27 +01:00
|
|
|
/** @return null */
|
|
|
|
public function foo() {
|
|
|
|
return null;
|
|
|
|
}
|
2018-02-01 01:24:34 +01:00
|
|
|
}',
|
|
|
|
],
|
2018-02-21 17:57:52 +01:00
|
|
|
'allowNoChildClassPropertyWhenMixed' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2018-02-21 17:57:52 +01:00
|
|
|
class A implements Serializable {
|
|
|
|
/** @var int */
|
|
|
|
private $id = 1;
|
|
|
|
|
2019-05-14 21:44:46 +02:00
|
|
|
/**
|
|
|
|
* @param string $serialized
|
|
|
|
*/
|
|
|
|
public function unserialize($serialized) : void
|
2018-02-21 17:57:52 +01:00
|
|
|
{
|
|
|
|
[
|
|
|
|
$this->id,
|
2020-11-25 18:04:48 +01:00
|
|
|
] = (array) \unserialize($serialized);
|
2018-02-21 17:57:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function serialize() : string
|
|
|
|
{
|
|
|
|
return serialize([$this->id]);
|
|
|
|
}
|
2018-02-22 00:59:31 +01:00
|
|
|
}',
|
2018-02-21 17:57:52 +01:00
|
|
|
],
|
2018-02-22 19:42:34 +01:00
|
|
|
'clashWithCallMapClass' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2018-04-07 17:38:41 +02:00
|
|
|
class HaruDestination {}
|
2018-02-22 19:42:34 +01:00
|
|
|
class AClass
|
|
|
|
{
|
2018-04-07 17:38:41 +02:00
|
|
|
public function get(): HaruDestination
|
2018-02-22 19:42:34 +01:00
|
|
|
{
|
2018-04-07 17:38:41 +02:00
|
|
|
return new HaruDestination;
|
2018-02-22 19:42:34 +01:00
|
|
|
}
|
|
|
|
}',
|
|
|
|
],
|
2018-03-13 23:11:57 +01:00
|
|
|
'classWithTraitExtendsNonAbstractWithMethod' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2018-03-13 23:11:57 +01:00
|
|
|
class A {
|
|
|
|
public function foo() : void {}
|
|
|
|
}
|
|
|
|
|
|
|
|
trait T {
|
|
|
|
abstract public function foo() : void;
|
|
|
|
}
|
|
|
|
|
|
|
|
class B extends A {
|
|
|
|
use T;
|
|
|
|
}',
|
|
|
|
],
|
2018-09-20 05:12:35 +02:00
|
|
|
'inheritsSplClasses' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2018-09-20 05:12:35 +02:00
|
|
|
namespace App;
|
|
|
|
|
|
|
|
use SplObserver;
|
|
|
|
use SplSubject;
|
|
|
|
|
|
|
|
class Observer implements \SplObserver
|
|
|
|
{
|
|
|
|
public function update(SplSubject $subject)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class Subject implements \SplSubject
|
|
|
|
{
|
|
|
|
public function attach(SplObserver $observer)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public function detach(SplObserver $observer)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public function notify()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
],
|
2018-10-06 20:00:45 +02:00
|
|
|
'noMixedIssueWhenInheritParamTypes' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2018-10-06 20:00:45 +02:00
|
|
|
class A {
|
|
|
|
/**
|
|
|
|
* @param string $bar
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function foo($bar) {
|
|
|
|
echo $bar;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class B extends A {
|
|
|
|
public function foo($bar) {
|
|
|
|
echo "hello " . $bar;
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
],
|
2019-01-05 14:43:37 +01:00
|
|
|
'inheritDocumentedSelf' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2019-01-05 14:43:37 +01:00
|
|
|
interface I {
|
|
|
|
/**
|
|
|
|
* @param self $f
|
|
|
|
*/
|
|
|
|
public function foo(self $f) : self;
|
|
|
|
}
|
|
|
|
|
|
|
|
class C implements I {
|
2021-05-09 01:33:48 +02:00
|
|
|
public function foo(I $f) : I {
|
2019-01-05 14:43:37 +01:00
|
|
|
return new C();
|
|
|
|
}
|
2019-03-23 19:27:54 +01:00
|
|
|
}',
|
2019-01-05 14:43:37 +01:00
|
|
|
],
|
2019-01-16 21:08:11 +01:00
|
|
|
'allowInterfaceImplementation' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2019-01-16 21:08:11 +01:00
|
|
|
abstract class A {
|
|
|
|
/** @return static */
|
|
|
|
public function foo() {
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
interface I {
|
|
|
|
/** @return I */
|
|
|
|
public function foo();
|
|
|
|
}
|
|
|
|
|
|
|
|
class C extends A implements I {}',
|
|
|
|
],
|
2019-01-19 18:42:46 +01:00
|
|
|
'enforceParameterInheritanceWithInheritDocAndParam' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2019-01-19 18:42:46 +01:00
|
|
|
class A {}
|
|
|
|
class B extends A {}
|
|
|
|
|
|
|
|
class X {
|
|
|
|
/**
|
|
|
|
* @param B $class
|
|
|
|
*/
|
|
|
|
public function boo(A $class): void {}
|
|
|
|
}
|
|
|
|
|
|
|
|
class Y extends X {
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
* @param A $class
|
|
|
|
*/
|
|
|
|
public function boo(A $class): void {}
|
|
|
|
}
|
|
|
|
|
2019-03-08 00:04:02 +01:00
|
|
|
class Z extends X {
|
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
* @param A $class
|
|
|
|
*/
|
|
|
|
public function boo(A $class): void {}
|
|
|
|
}
|
|
|
|
|
|
|
|
(new Y())->boo(new A());
|
|
|
|
(new Z())->boo(new A());',
|
2019-01-19 18:42:46 +01:00
|
|
|
],
|
2019-01-24 21:03:13 +01:00
|
|
|
'allowMixedExtensionOfIteratorAggregate' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2022-01-26 18:46:02 +01:00
|
|
|
/**
|
|
|
|
* @psalm-suppress MissingTemplateParam
|
|
|
|
*/
|
2019-01-24 21:03:13 +01:00
|
|
|
class C implements IteratorAggregate {
|
|
|
|
public function getIterator(): Iterator {
|
|
|
|
return new ArrayIterator([]);
|
|
|
|
}
|
2019-03-23 19:27:54 +01:00
|
|
|
}',
|
2019-01-24 21:03:13 +01:00
|
|
|
],
|
2019-03-02 21:26:18 +01:00
|
|
|
'allowExtraVariadic' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2019-03-02 21:26:18 +01:00
|
|
|
interface I {
|
|
|
|
public function f(string $a, int $b): void;
|
|
|
|
}
|
|
|
|
|
|
|
|
class C implements I {
|
|
|
|
public function f(string $a = "a", int $b = 1, float ...$rest): void {}
|
|
|
|
}
|
|
|
|
|
|
|
|
(new C)->f();
|
|
|
|
(new C)->f("b");
|
|
|
|
(new C)->f("b", 3);
|
|
|
|
(new C)->f("b", 3, 0.5);
|
2019-03-23 19:27:54 +01:00
|
|
|
(new C)->f("b", 3, 0.5, 0.8);',
|
2019-03-02 21:26:18 +01:00
|
|
|
],
|
2019-05-09 16:41:30 +02:00
|
|
|
'allowLessSpecificDocblockTypeOnParent' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2019-05-09 16:41:30 +02:00
|
|
|
abstract class Foo {
|
|
|
|
/**
|
|
|
|
* @return array|string
|
|
|
|
*/
|
|
|
|
abstract public function getTargets();
|
|
|
|
}
|
|
|
|
|
|
|
|
class Bar extends Foo {
|
|
|
|
public function getTargets(): string {
|
|
|
|
return "baz";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$a = (new Bar)->getTargets();',
|
2022-01-13 19:49:37 +01:00
|
|
|
'assertions' => [
|
2019-05-09 16:41:30 +02:00
|
|
|
'$a' => 'string',
|
2019-07-05 22:24:00 +02:00
|
|
|
],
|
2019-05-09 16:41:30 +02:00
|
|
|
],
|
2019-05-25 17:51:09 +02:00
|
|
|
'parentIsKnown' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2019-05-25 17:51:09 +02:00
|
|
|
class A {
|
|
|
|
public function returnSelf() : self {
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class B extends A {
|
|
|
|
public function returnSelf() : parent {
|
|
|
|
return parent::returnSelf();
|
|
|
|
}
|
|
|
|
|
|
|
|
}',
|
|
|
|
],
|
|
|
|
'returnStaticParent' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2019-05-25 17:51:09 +02:00
|
|
|
class A {
|
|
|
|
/**
|
|
|
|
* @return static
|
|
|
|
*/
|
|
|
|
public static function foo() {
|
|
|
|
return new static();
|
|
|
|
}
|
2020-08-06 01:39:27 +02:00
|
|
|
|
|
|
|
final public function __construct() {}
|
2019-05-25 17:51:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
class B extends A {
|
|
|
|
/**
|
|
|
|
* @return static
|
|
|
|
*/
|
|
|
|
public static function foo() {
|
|
|
|
return parent::foo();
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
],
|
2020-01-24 17:15:35 +01:00
|
|
|
'selfInTraitAbstractIsFine' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2020-01-24 17:15:35 +01:00
|
|
|
trait SomeTrait {
|
|
|
|
abstract public function a(self $b): self;
|
|
|
|
}
|
|
|
|
|
|
|
|
class SomeClass {
|
|
|
|
use SomeTrait;
|
|
|
|
|
|
|
|
public function a(self $b): self {
|
|
|
|
return $this;
|
|
|
|
}
|
2022-12-18 17:15:15 +01:00
|
|
|
}',
|
2020-01-24 17:15:35 +01:00
|
|
|
],
|
2020-04-03 21:11:37 +02:00
|
|
|
'allowMatchIn74' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2020-04-03 21:11:37 +02:00
|
|
|
trait FooTrait {
|
|
|
|
/**
|
|
|
|
* @return static
|
|
|
|
*/
|
|
|
|
public function bar(): self {
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
interface FooInterface {
|
|
|
|
/**
|
|
|
|
* @return static
|
|
|
|
*/
|
|
|
|
public function bar(): self;
|
|
|
|
}
|
|
|
|
|
|
|
|
class FooClass implements FooInterface {
|
|
|
|
use FooTrait;
|
|
|
|
}',
|
2022-01-13 19:49:37 +01:00
|
|
|
'assertions' => [],
|
|
|
|
'ignored_issues' => [],
|
2022-12-18 17:15:15 +01:00
|
|
|
'php_version' => '7.4',
|
2020-04-03 21:11:37 +02:00
|
|
|
],
|
2020-04-20 23:17:47 +02:00
|
|
|
'allowOverridingThrowable' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2020-04-20 23:17:47 +02:00
|
|
|
/**
|
|
|
|
* @psalm-immutable
|
|
|
|
*/
|
|
|
|
interface MyException extends \Throwable
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Informative comment
|
|
|
|
*/
|
|
|
|
public function getMessage(): string;
|
|
|
|
public function getCode();
|
|
|
|
public function getFile(): string;
|
|
|
|
public function getLine(): int;
|
|
|
|
public function getTrace(): array;
|
|
|
|
public function getPrevious(): ?\Throwable;
|
|
|
|
public function getTraceAsString(): string;
|
2022-12-18 17:15:15 +01:00
|
|
|
}',
|
2020-07-02 20:09:56 +02:00
|
|
|
],
|
|
|
|
'allowExecptionToStringWithNoType' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2020-07-02 20:09:56 +02:00
|
|
|
class E extends Exception {
|
|
|
|
public function __toString() {
|
|
|
|
return "hello";
|
|
|
|
}
|
2022-12-18 17:15:15 +01:00
|
|
|
}',
|
2020-07-02 20:09:56 +02:00
|
|
|
],
|
|
|
|
'allowExecptionToStringIn71' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2020-07-02 20:09:56 +02:00
|
|
|
class E extends Exception {
|
|
|
|
public function __toString() : string {
|
|
|
|
return "hello";
|
|
|
|
}
|
|
|
|
}',
|
2022-01-13 19:49:37 +01:00
|
|
|
'assertions' => [],
|
|
|
|
'ignored_issues' => [],
|
2022-12-18 17:15:15 +01:00
|
|
|
'php_version' => '7.1',
|
2020-08-06 01:39:27 +02:00
|
|
|
],
|
|
|
|
'consistentConstructor' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2020-08-06 01:39:27 +02:00
|
|
|
/**
|
|
|
|
* @psalm-consistent-constructor
|
|
|
|
*/
|
|
|
|
class A {
|
|
|
|
public function getInstance() : self {
|
|
|
|
return new static();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class AChild extends A {
|
|
|
|
public function __construct() {}
|
2022-12-18 17:15:15 +01:00
|
|
|
}',
|
2020-08-06 01:39:27 +02:00
|
|
|
],
|
2020-10-04 05:34:29 +02:00
|
|
|
'allowStaticInheritance' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2020-10-04 05:34:29 +02:00
|
|
|
class A {
|
|
|
|
public function method(): static {
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
class B extends A {
|
|
|
|
public function method(): static {
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
}',
|
2022-01-13 19:49:37 +01:00
|
|
|
'assertions' => [],
|
|
|
|
'ignored_issues' => [],
|
2022-12-18 17:15:15 +01:00
|
|
|
'php_version' => '8.0',
|
2020-10-04 05:34:29 +02:00
|
|
|
],
|
2020-12-02 21:13:28 +01:00
|
|
|
'suppressDocblockFinal' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2020-12-02 21:13:28 +01:00
|
|
|
/**
|
|
|
|
* @final
|
|
|
|
*/
|
|
|
|
class A {
|
|
|
|
public function foo(): void {}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @psalm-suppress InvalidExtendClass
|
|
|
|
*/
|
|
|
|
class B extends A {
|
|
|
|
/**
|
|
|
|
* @psalm-suppress MethodSignatureMismatch
|
|
|
|
*/
|
|
|
|
public function foo(): void {}
|
2022-12-18 17:15:15 +01:00
|
|
|
}',
|
2020-12-02 21:13:28 +01:00
|
|
|
],
|
2020-12-10 06:15:37 +01:00
|
|
|
'inheritParamTypeWhenSignatureReturnTypeChanged' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2020-12-10 06:15:37 +01:00
|
|
|
class A {
|
|
|
|
public function __construct(string $s) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
class AChild extends A {}
|
|
|
|
|
|
|
|
interface B {
|
|
|
|
/** @param string $data */
|
|
|
|
public function create($data): A;
|
|
|
|
}
|
|
|
|
|
|
|
|
class C implements B {
|
|
|
|
public function create($data): AChild {
|
|
|
|
return new AChild($data);
|
|
|
|
}
|
|
|
|
}',
|
2022-01-13 19:49:37 +01:00
|
|
|
'assertions' => [],
|
|
|
|
'ignored_issues' => [],
|
2022-12-18 17:15:15 +01:00
|
|
|
'php_version' => '7.4',
|
2020-12-10 06:15:37 +01:00
|
|
|
],
|
2021-01-22 15:58:09 +01:00
|
|
|
'extendStaticReturnTypeInFinal' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2021-01-22 15:58:09 +01:00
|
|
|
final class B extends A
|
|
|
|
{
|
|
|
|
public static function doCretate1(): self
|
|
|
|
{
|
|
|
|
return self::create1();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function doCretate2(): self
|
|
|
|
{
|
|
|
|
return self::create2();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
abstract class A
|
|
|
|
{
|
|
|
|
final private function __construct() {}
|
|
|
|
|
|
|
|
final protected static function create1(): static
|
|
|
|
{
|
|
|
|
return new static();
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @return static */
|
|
|
|
final protected static function create2()
|
|
|
|
{
|
|
|
|
return new static();
|
|
|
|
}
|
|
|
|
}',
|
2022-01-13 19:49:37 +01:00
|
|
|
'assertions' => [],
|
|
|
|
'ignored_issues' => [],
|
2022-12-18 17:15:15 +01:00
|
|
|
'php_version' => '8.0',
|
2021-01-22 15:58:09 +01:00
|
|
|
],
|
2021-02-24 01:06:45 +01:00
|
|
|
'notExtendedStaticReturntypeInFinal' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2021-02-24 01:06:45 +01:00
|
|
|
final class X
|
|
|
|
{
|
|
|
|
public static function create(): static
|
|
|
|
{
|
|
|
|
return new self();
|
|
|
|
}
|
2022-12-18 17:15:15 +01:00
|
|
|
}',
|
2021-02-24 01:06:45 +01:00
|
|
|
],
|
2021-02-24 02:48:22 +01:00
|
|
|
'callParentMethodFromTrait' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2021-02-24 02:48:22 +01:00
|
|
|
class MyParentClass
|
|
|
|
{
|
|
|
|
/** @return static */
|
|
|
|
public function myMethod()
|
|
|
|
{
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
trait MyTrait
|
|
|
|
{
|
|
|
|
final public function myMethod() : self
|
|
|
|
{
|
|
|
|
return parent::myMethod();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class MyChildClass extends MyParentClass
|
|
|
|
{
|
|
|
|
use MyTrait;
|
2022-12-18 17:15:15 +01:00
|
|
|
}',
|
2021-02-24 02:48:22 +01:00
|
|
|
],
|
2021-05-15 02:23:54 +02:00
|
|
|
'MixedParamInImplementation' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2021-05-15 02:23:54 +02:00
|
|
|
interface I
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @param mixed $a
|
|
|
|
*/
|
|
|
|
public function a($a): void;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
final class B implements I
|
|
|
|
{
|
|
|
|
public function a(mixed $a): void {}
|
2022-12-18 17:15:15 +01:00
|
|
|
}',
|
2021-05-15 02:23:54 +02:00
|
|
|
],
|
2022-12-26 20:45:44 +01:00
|
|
|
'doesNotRequireInterfaceDestructorsToHaveReturnType' => [
|
|
|
|
'code' => '<?php
|
|
|
|
interface I
|
|
|
|
{
|
|
|
|
public function __destruct();
|
|
|
|
}
|
|
|
|
|
|
|
|
class C implements I
|
|
|
|
{
|
|
|
|
public function __destruct() {}
|
|
|
|
}
|
|
|
|
',
|
|
|
|
],
|
2017-11-09 03:27:23 +01:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2020-09-12 17:24:05 +02:00
|
|
|
public function providerInvalidCodeParse(): iterable
|
2017-04-25 05:45:02 +02:00
|
|
|
{
|
|
|
|
return [
|
2021-05-09 01:33:48 +02:00
|
|
|
'oneParam' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2021-05-09 01:33:48 +02:00
|
|
|
interface I {
|
|
|
|
/**
|
|
|
|
* @param array $i
|
|
|
|
*/
|
|
|
|
public function foo(array $i) : void;
|
|
|
|
}
|
|
|
|
|
|
|
|
class C implements I {
|
|
|
|
public function foo(array $c) : void {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
'error_message' => 'Argument 1 of C::foo has wrong name $c, expecting $i as defined by I::foo',
|
|
|
|
],
|
2017-04-25 05:45:02 +02:00
|
|
|
'moreArguments' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2017-04-25 05:45:02 +02:00
|
|
|
class A {
|
2018-01-11 21:50:45 +01:00
|
|
|
public function fooFoo(int $a, bool $b): void {
|
2017-07-25 22:11:02 +02:00
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
}
|
|
|
|
}
|
2017-07-25 22:11:02 +02:00
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
class B extends A {
|
2018-01-11 21:50:45 +01:00
|
|
|
public function fooFoo(int $a, bool $b, array $c): void {
|
2017-07-25 22:11:02 +02:00
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
}
|
|
|
|
}',
|
2018-07-14 02:17:29 +02:00
|
|
|
'error_message' => 'Method B::fooFoo has more required parameters than parent method A::fooFoo',
|
2017-04-25 05:45:02 +02:00
|
|
|
],
|
|
|
|
'fewerArguments' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2017-04-25 05:45:02 +02:00
|
|
|
class A {
|
2018-01-11 21:50:45 +01:00
|
|
|
public function fooFoo(int $a, bool $b): void {
|
2017-07-25 22:11:02 +02:00
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
}
|
|
|
|
}
|
2017-07-25 22:11:02 +02:00
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
class B extends A {
|
2018-01-11 21:50:45 +01:00
|
|
|
public function fooFoo(int $a): void {
|
2017-07-25 22:11:02 +02:00
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
}
|
|
|
|
}',
|
2018-07-14 02:17:29 +02:00
|
|
|
'error_message' => 'Method B::fooFoo has fewer parameters than parent method A::fooFoo',
|
2017-04-25 05:45:02 +02:00
|
|
|
],
|
2020-08-10 15:58:43 +02:00
|
|
|
'differentArgumentTypes' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2017-04-25 05:45:02 +02:00
|
|
|
class A {
|
2018-01-11 21:50:45 +01:00
|
|
|
public function fooFoo(int $a, bool $b): void {
|
2017-07-25 22:11:02 +02:00
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
}
|
|
|
|
}
|
2017-07-25 22:11:02 +02:00
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
class B extends A {
|
2020-08-10 15:58:43 +02:00
|
|
|
public function fooFoo(int $a, int $b): void {
|
2017-07-25 22:11:02 +02:00
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
}
|
|
|
|
}',
|
2020-08-10 15:58:43 +02:00
|
|
|
'error_message' => 'Argument 2 of B::fooFoo has wrong type \'int\', expecting \'bool\' as defined ' .
|
2018-01-11 23:38:24 +01:00
|
|
|
'by A::fooFoo',
|
2017-05-27 02:05:57 +02:00
|
|
|
],
|
2020-08-10 15:58:43 +02:00
|
|
|
'differentArgumentNames' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2020-08-10 15:58:43 +02:00
|
|
|
class A {
|
|
|
|
public function fooFoo(int $a, bool $b): void {
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class B extends A {
|
|
|
|
public function fooFoo(int $a, bool $c): void {
|
|
|
|
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
'error_message' => 'ParamNameMismatch',
|
|
|
|
],
|
2017-11-13 22:31:33 +01:00
|
|
|
'nonNullableSubclassParam' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2017-11-13 22:31:33 +01:00
|
|
|
class A {
|
2018-01-11 21:50:45 +01:00
|
|
|
public function foo(?string $s): string {
|
2017-11-13 22:31:33 +01:00
|
|
|
return $s ?: "hello";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class B extends A {
|
2018-01-11 21:50:45 +01:00
|
|
|
public function foo(string $s): string {
|
2017-11-13 22:31:33 +01:00
|
|
|
return $s;
|
|
|
|
}
|
|
|
|
}',
|
2019-10-17 07:14:33 +02:00
|
|
|
'error_message' => 'Argument 1 of B::foo has wrong type \'string\', expecting \'null|string\' as',
|
2017-11-13 22:31:33 +01:00
|
|
|
],
|
2017-12-30 16:54:01 +01:00
|
|
|
'misplacedRequiredParam' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2019-06-07 15:25:03 +02:00
|
|
|
function foo(string $bar = null, int $bat): void {}
|
|
|
|
foo();',
|
|
|
|
'error_message' => 'TooFewArguments',
|
2017-12-30 16:54:01 +01:00
|
|
|
],
|
2018-01-04 20:01:17 +01:00
|
|
|
'clasginByRef' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2018-01-04 20:01:17 +01:00
|
|
|
class A {
|
2018-01-11 21:50:45 +01:00
|
|
|
public function foo(string $a): void {
|
2018-01-04 20:01:17 +01:00
|
|
|
echo $a;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
class B extends A {
|
2018-01-11 21:50:45 +01:00
|
|
|
public function foo(string &$a): void {
|
2018-01-04 20:01:17 +01:00
|
|
|
echo $a;
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
'error_message' => 'MethodSignatureMismatch',
|
|
|
|
],
|
2018-01-05 06:19:35 +01:00
|
|
|
'disallowSubclassesForNonInheritedMethodParams' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2018-01-05 06:19:35 +01:00
|
|
|
class A {}
|
|
|
|
class B extends A {
|
2018-01-11 21:50:45 +01:00
|
|
|
public function bar(): void {}
|
2018-01-05 06:19:35 +01:00
|
|
|
}
|
|
|
|
class C extends A {
|
2018-01-11 21:50:45 +01:00
|
|
|
public function bar(): void {}
|
2018-01-05 06:19:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
class D {
|
2018-01-11 21:50:45 +01:00
|
|
|
public function foo(A $a): void {}
|
2018-01-05 06:19:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
class E extends D {
|
|
|
|
/** @param B|C $a */
|
2018-01-11 21:50:45 +01:00
|
|
|
public function foo(A $a): void {
|
2018-01-05 06:19:35 +01:00
|
|
|
$a->bar();
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
'error_message' => 'MoreSpecificImplementedParamType',
|
|
|
|
],
|
2020-11-12 19:54:27 +01:00
|
|
|
'preventVoidToNullConversionSignature' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2018-02-01 01:24:34 +01:00
|
|
|
class A {
|
2020-11-12 19:54:27 +01:00
|
|
|
public function foo(): ?string {
|
|
|
|
return rand(0, 1) ? "hello" : null;
|
|
|
|
}
|
2018-02-01 01:24:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
class B extends A {
|
2020-11-12 19:54:27 +01:00
|
|
|
public function foo(): void {
|
|
|
|
return;
|
|
|
|
}
|
2018-02-01 01:24:34 +01:00
|
|
|
}',
|
|
|
|
'error_message' => 'MethodSignatureMismatch',
|
|
|
|
],
|
2018-03-13 17:52:00 +01:00
|
|
|
'abstractExtendsNonAbstractWithMethod' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2018-03-13 17:52:00 +01:00
|
|
|
class A {
|
|
|
|
public function foo() : void {}
|
|
|
|
}
|
|
|
|
|
|
|
|
abstract class B extends A {
|
|
|
|
abstract public function foo() : void;
|
|
|
|
}',
|
|
|
|
'error_message' => 'MethodSignatureMismatch',
|
|
|
|
],
|
2018-03-13 23:11:57 +01:00
|
|
|
'traitReturnTypeMismatch' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2018-03-13 23:11:57 +01:00
|
|
|
class A {
|
|
|
|
public function foo() : void {}
|
|
|
|
}
|
|
|
|
|
|
|
|
trait T {
|
|
|
|
abstract public function foo() : string;
|
|
|
|
}
|
|
|
|
|
|
|
|
class B extends A {
|
|
|
|
use T;
|
|
|
|
}',
|
2020-01-17 04:36:30 +01:00
|
|
|
'error_message' => 'MethodSignatureMismatch',
|
2019-01-13 19:27:07 +01:00
|
|
|
],
|
|
|
|
'abstractTraitMethodWithDifferentReturnType' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2019-01-13 19:27:07 +01:00
|
|
|
class A {}
|
|
|
|
class B {}
|
|
|
|
|
|
|
|
trait T {
|
|
|
|
abstract public function foo() : A;
|
|
|
|
}
|
|
|
|
|
|
|
|
class C {
|
|
|
|
use T;
|
|
|
|
|
|
|
|
public function foo() : B{
|
|
|
|
return new B();
|
|
|
|
}
|
|
|
|
}',
|
2019-03-29 19:09:06 +01:00
|
|
|
'error_message' => 'TraitMethodSignatureMismatch',
|
|
|
|
],
|
|
|
|
'traitMoreParams' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2019-03-29 19:09:06 +01:00
|
|
|
class A {
|
|
|
|
public function foo() : void {}
|
|
|
|
}
|
|
|
|
|
|
|
|
trait T {
|
|
|
|
abstract public function foo(string $s) : string;
|
|
|
|
}
|
|
|
|
|
|
|
|
class B extends A {
|
|
|
|
use T;
|
|
|
|
}',
|
2020-01-17 04:36:30 +01:00
|
|
|
'error_message' => 'MethodSignatureMismatch',
|
2019-03-29 19:09:06 +01:00
|
|
|
],
|
|
|
|
'abstractTraitMethodWithDifferentParamType' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2019-03-29 19:09:06 +01:00
|
|
|
class A {}
|
|
|
|
class B {}
|
|
|
|
|
|
|
|
trait T {
|
|
|
|
abstract public function foo(A $a) : void;
|
|
|
|
}
|
|
|
|
|
|
|
|
class C {
|
|
|
|
use T;
|
|
|
|
|
2021-05-09 01:33:48 +02:00
|
|
|
public function foo(B $a) : void {}
|
2019-03-29 19:09:06 +01:00
|
|
|
}',
|
|
|
|
'error_message' => 'TraitMethodSignatureMismatch',
|
2018-03-13 23:11:57 +01:00
|
|
|
],
|
2018-04-21 21:59:16 +02:00
|
|
|
'mustOmitReturnType' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2018-04-21 21:59:16 +02:00
|
|
|
class A
|
|
|
|
{
|
|
|
|
public function __construct(): void
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
'error_message' => 'MethodSignatureMustOmitReturnType',
|
|
|
|
],
|
2018-07-14 02:17:29 +02:00
|
|
|
'requireParam' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2018-07-14 02:17:29 +02:00
|
|
|
interface I {
|
|
|
|
function foo(bool $b = false): void;
|
|
|
|
}
|
|
|
|
|
|
|
|
class C implements I {
|
|
|
|
public function foo(bool $b): void {}
|
|
|
|
}',
|
2019-02-27 22:00:44 +01:00
|
|
|
'error_message' => 'MethodSignatureMismatch - src' . DIRECTORY_SEPARATOR . 'somefile.php:6:27 - Method C::foo has more required',
|
2018-07-14 02:17:29 +02:00
|
|
|
],
|
2018-10-06 20:00:45 +02:00
|
|
|
'inheritParamTypes' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2018-10-06 20:00:45 +02:00
|
|
|
class A {
|
|
|
|
/**
|
|
|
|
* @param string $bar
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function foo($bar) {
|
|
|
|
echo $bar;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class B extends A {
|
|
|
|
public function foo($bar) {
|
|
|
|
echo "hello " . $bar;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
(new B)->foo(new stdClass);',
|
2019-03-23 19:27:54 +01:00
|
|
|
'error_message' => 'InvalidArgument',
|
2018-10-06 20:00:45 +02:00
|
|
|
],
|
2018-12-13 04:35:27 +01:00
|
|
|
'interfaceHasFewerConstructorArgs' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2018-12-13 04:35:27 +01:00
|
|
|
interface Foo {
|
|
|
|
public function __construct();
|
|
|
|
}
|
|
|
|
|
|
|
|
class Bar implements Foo {
|
|
|
|
public function __construct(bool $foo) {}
|
|
|
|
}',
|
2020-08-10 18:26:25 +02:00
|
|
|
'error_message' => 'ConstructorSignatureMismatch',
|
2018-12-13 04:35:27 +01:00
|
|
|
],
|
2019-01-19 18:19:07 +01:00
|
|
|
'enforceParameterInheritanceWithInheritDoc' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2019-01-19 18:19:07 +01:00
|
|
|
class A {}
|
|
|
|
class B extends A {}
|
|
|
|
|
|
|
|
class X {
|
|
|
|
/**
|
|
|
|
* @param B $class
|
|
|
|
*/
|
|
|
|
public function boo(A $class): void {}
|
|
|
|
}
|
|
|
|
|
|
|
|
class Y extends X {
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
public function boo(A $class): void {}
|
|
|
|
}
|
|
|
|
|
|
|
|
(new Y())->boo(new A());',
|
2019-04-26 00:02:19 +02:00
|
|
|
'error_message' => 'ArgumentTypeCoercion',
|
2019-01-19 18:19:07 +01:00
|
|
|
],
|
2019-03-08 00:04:02 +01:00
|
|
|
'enforceParameterInheritanceWithCapitalizedInheritDoc' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2019-03-08 00:04:02 +01:00
|
|
|
class A {}
|
|
|
|
class B extends A {}
|
|
|
|
|
|
|
|
class X {
|
|
|
|
/**
|
|
|
|
* @param B $class
|
|
|
|
*/
|
|
|
|
public function boo(A $class): void {}
|
|
|
|
}
|
|
|
|
|
|
|
|
class Y extends X {
|
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
public function boo(A $class): void {}
|
|
|
|
}
|
|
|
|
|
|
|
|
(new Y())->boo(new A());',
|
2019-04-26 00:02:19 +02:00
|
|
|
'error_message' => 'ArgumentTypeCoercion',
|
2019-03-08 00:04:02 +01:00
|
|
|
],
|
2019-01-19 18:19:07 +01:00
|
|
|
'warnAboutMismatchingClassParamDoc' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2019-01-19 18:19:07 +01:00
|
|
|
class A {}
|
|
|
|
class B {}
|
|
|
|
|
|
|
|
class X {
|
|
|
|
/**
|
|
|
|
* @param B $class
|
|
|
|
*/
|
|
|
|
public function boo(A $class): void {}
|
|
|
|
}',
|
|
|
|
'error_message' => 'MismatchingDocblockParamType',
|
|
|
|
],
|
|
|
|
'warnAboutMismatchingInterfaceParamDoc' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2019-01-19 18:19:07 +01:00
|
|
|
class A {}
|
|
|
|
class B {}
|
|
|
|
|
|
|
|
interface X {
|
|
|
|
/**
|
|
|
|
* @param B $class
|
|
|
|
*/
|
|
|
|
public function boo(A $class): void {}
|
|
|
|
}',
|
|
|
|
'error_message' => 'MismatchingDocblockParamType',
|
2019-01-24 16:58:59 +01:00
|
|
|
],
|
|
|
|
'interfaceInsertDocblockTypes' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2019-01-24 16:58:59 +01:00
|
|
|
class Foo {}
|
|
|
|
class Bar {}
|
|
|
|
|
|
|
|
interface I {
|
|
|
|
/** @return array<int, Foo> */
|
|
|
|
public function getFoos() : array;
|
|
|
|
}
|
|
|
|
|
|
|
|
class A implements I {
|
|
|
|
public function getFoos() : array {
|
|
|
|
return [new Bar()];
|
|
|
|
}
|
|
|
|
}',
|
2019-01-24 17:55:59 +01:00
|
|
|
'error_message' => 'InvalidReturnStatement',
|
|
|
|
],
|
|
|
|
'classInsertDocblockTypesFromParent' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2019-01-24 17:55:59 +01:00
|
|
|
class Foo {}
|
|
|
|
class Bar {}
|
|
|
|
|
|
|
|
class B {
|
|
|
|
/** @return array<int, Foo> */
|
|
|
|
public function getFoos() : array {
|
|
|
|
return [new Foo()];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class A extends B {
|
|
|
|
public function getFoos() : array {
|
|
|
|
return [new Bar()];
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
'error_message' => 'InvalidReturnStatement',
|
2019-01-24 16:58:59 +01:00
|
|
|
],
|
2019-03-02 21:29:43 +01:00
|
|
|
'preventInterfaceOverload' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2019-03-02 21:29:43 +01:00
|
|
|
interface I {
|
|
|
|
public function f(float ...$rest): void;
|
|
|
|
}
|
|
|
|
|
|
|
|
class C implements I {
|
2021-05-09 01:33:48 +02:00
|
|
|
/**
|
|
|
|
* @param array<int,float> $f
|
|
|
|
* @psalm-suppress ParamNameMismatch
|
|
|
|
*/
|
2019-03-02 21:29:43 +01:00
|
|
|
public function f($f): void {}
|
|
|
|
}',
|
|
|
|
'error_message' => 'MethodSignatureMismatch',
|
2022-01-13 19:49:37 +01:00
|
|
|
'ignored_issues' => ['MoreSpecificImplementedParamType'],
|
2019-03-02 21:29:43 +01:00
|
|
|
],
|
2019-05-14 22:15:31 +02:00
|
|
|
'preventOneOfUnionMoreSpecific' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2019-05-14 22:15:31 +02:00
|
|
|
class A {
|
|
|
|
/** @param string|int $s */
|
|
|
|
public function foo($s) : void {}
|
|
|
|
}
|
|
|
|
|
|
|
|
class B extends A {
|
|
|
|
/** @param string $s */
|
|
|
|
public function foo($s) : void {}
|
|
|
|
}',
|
|
|
|
'error_message' => 'MoreSpecificImplementedParamType',
|
|
|
|
],
|
2019-05-14 21:44:46 +02:00
|
|
|
'preventImplementingSerializableWithWrongDocblockType' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2019-05-14 21:44:46 +02:00
|
|
|
class Foo implements \Serializable {
|
|
|
|
/** @param int $serialized */
|
|
|
|
public function unserialize($serialized) {}
|
|
|
|
public function serialize() {}
|
|
|
|
}',
|
|
|
|
'error_message' => 'ImplementedParamTypeMismatch',
|
|
|
|
],
|
2019-11-11 06:21:43 +01:00
|
|
|
'returnsParentWithNoParent' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2019-11-11 06:21:43 +01:00
|
|
|
class Foo {
|
|
|
|
public function f(): parent {}
|
|
|
|
}
|
|
|
|
',
|
|
|
|
'error_message' => 'InvalidParent',
|
|
|
|
],
|
|
|
|
'returnsParentWithNoParentAndInvalidParentSuppressed' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2019-11-11 06:21:43 +01:00
|
|
|
class Foo {
|
|
|
|
public function f(): parent {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
',
|
|
|
|
'error_message' => 'InvalidReturnType',
|
2022-01-13 19:49:37 +01:00
|
|
|
'ignored_issues' => ['InvalidParent'],
|
2019-11-11 06:21:43 +01:00
|
|
|
],
|
|
|
|
// not sure how to handle it
|
|
|
|
'SKIPPED-returnsParentWithNoParentAndInvalidParentSuppressedMismatchingReturn' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2019-11-11 06:21:43 +01:00
|
|
|
class Foo {
|
|
|
|
public function f(): parent {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
',
|
|
|
|
'error_message' => 'InvalidReturnType',
|
2022-01-13 19:49:37 +01:00
|
|
|
'ignored_issues' => ['InvalidParent'],
|
2019-11-11 06:21:43 +01:00
|
|
|
],
|
2020-01-17 04:36:30 +01:00
|
|
|
'regularMethodMismatchFromParentUse' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2020-01-17 04:36:30 +01:00
|
|
|
trait T2 {
|
|
|
|
abstract public function test(int $x) : void;
|
|
|
|
}
|
|
|
|
|
|
|
|
abstract class P2 {
|
|
|
|
use T2;
|
|
|
|
}
|
|
|
|
|
|
|
|
class C2 extends P2 {
|
|
|
|
public function test(string $x) : void {}
|
|
|
|
}',
|
|
|
|
'error_message' => 'MethodSignatureMismatch',
|
|
|
|
],
|
|
|
|
'regularMethodMismatchFromChildUse' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2020-01-17 04:36:30 +01:00
|
|
|
trait T3 {
|
|
|
|
abstract public function test(int $x) : void;
|
|
|
|
}
|
|
|
|
|
|
|
|
class P3 {
|
|
|
|
public function test(string $x) : void {}
|
|
|
|
}
|
|
|
|
|
|
|
|
class C3 extends P3 {
|
|
|
|
use T3;
|
|
|
|
}',
|
|
|
|
'error_message' => 'MethodSignatureMismatch',
|
|
|
|
],
|
2020-01-17 06:28:08 +01:00
|
|
|
'traitMethodAccessLevel' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2020-01-17 06:28:08 +01:00
|
|
|
class A {}
|
|
|
|
class B extends A {}
|
|
|
|
|
|
|
|
trait T1 {
|
|
|
|
abstract protected static function test(A $x) : void;
|
|
|
|
}
|
|
|
|
|
|
|
|
class C1 {
|
|
|
|
use T1;
|
|
|
|
|
|
|
|
private static function test(B $x) : void {}
|
|
|
|
}',
|
|
|
|
'error_message' => 'TraitMethodSignatureMismatch',
|
|
|
|
],
|
2020-01-21 17:46:51 +01:00
|
|
|
'abstractClassReturnMismatch' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2020-01-21 17:46:51 +01:00
|
|
|
interface I {
|
|
|
|
function foo(): array;
|
|
|
|
}
|
|
|
|
|
|
|
|
abstract class C implements I {
|
|
|
|
public function foo(): void {}
|
|
|
|
}',
|
|
|
|
'error_message' => 'MethodSignatureMismatch',
|
|
|
|
],
|
|
|
|
'abstractClassParamMismatch' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2020-01-21 17:46:51 +01:00
|
|
|
interface I {
|
|
|
|
function foo(int $s): void;
|
|
|
|
}
|
|
|
|
|
|
|
|
abstract class C implements I {
|
|
|
|
public function foo(string $s): void {}
|
|
|
|
}',
|
|
|
|
'error_message' => 'MethodSignatureMismatch',
|
|
|
|
],
|
2020-04-03 21:11:37 +02:00
|
|
|
'preventTraitMatchIn73' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2020-04-03 21:11:37 +02:00
|
|
|
trait FooTrait {
|
|
|
|
/**
|
|
|
|
* @return static
|
|
|
|
*/
|
|
|
|
public function bar(): self {
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
interface FooInterface {
|
|
|
|
/**
|
|
|
|
* @return static
|
|
|
|
*/
|
|
|
|
public function bar(): self;
|
|
|
|
}
|
|
|
|
|
|
|
|
class FooClass implements FooInterface {
|
|
|
|
use FooTrait;
|
|
|
|
}',
|
|
|
|
'error_message' => 'MethodSignatureMismatch',
|
2022-01-13 19:49:37 +01:00
|
|
|
'ignored_issues' => [],
|
2022-12-18 17:15:15 +01:00
|
|
|
'php_version' => '7.3',
|
2020-04-03 21:11:37 +02:00
|
|
|
],
|
2020-08-10 18:26:25 +02:00
|
|
|
'inconsistentConstructorExplicitParentConstructorArgCount' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2020-08-06 01:39:27 +02:00
|
|
|
/**
|
|
|
|
* @psalm-consistent-constructor
|
|
|
|
*/
|
|
|
|
class A {
|
|
|
|
public function getInstance() : self
|
|
|
|
{
|
|
|
|
return new static();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function __construct() {}
|
|
|
|
}
|
|
|
|
|
|
|
|
class BadAChild extends A {
|
|
|
|
public function __construct(string $s) {}
|
|
|
|
}',
|
2020-08-10 18:26:25 +02:00
|
|
|
'error_message' => 'ConstructorSignatureMismatch',
|
|
|
|
],
|
|
|
|
'inconsistentConstructorExplicitParentConstructorType' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2020-08-10 18:26:25 +02:00
|
|
|
/**
|
|
|
|
* @psalm-consistent-constructor
|
|
|
|
*/
|
|
|
|
class A {
|
|
|
|
public function getInstance() : self
|
|
|
|
{
|
|
|
|
return new static(5);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function __construct(int $s) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
class BadAChild extends A {
|
|
|
|
public function __construct(string $s) {}
|
|
|
|
}',
|
|
|
|
'error_message' => 'ConstructorSignatureMismatch',
|
2020-08-06 01:39:27 +02:00
|
|
|
],
|
|
|
|
'inconsistentConstructorImplicitParentConstructor' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2020-08-06 01:39:27 +02:00
|
|
|
/**
|
|
|
|
* @psalm-consistent-constructor
|
|
|
|
*/
|
|
|
|
class A {
|
|
|
|
public function getInstance() : self {
|
|
|
|
return new static();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class BadAChild extends A {
|
|
|
|
public function __construct(string $s) {}
|
|
|
|
}',
|
2020-08-10 18:26:25 +02:00
|
|
|
'error_message' => 'ConstructorSignatureMismatch',
|
2020-08-06 01:39:27 +02:00
|
|
|
],
|
2020-09-07 22:42:25 +02:00
|
|
|
'inheritDocblockReturnFromInterface' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2020-09-07 22:42:25 +02:00
|
|
|
interface A {
|
|
|
|
/** @return ?string */
|
|
|
|
function foo();
|
|
|
|
}
|
|
|
|
|
|
|
|
class C implements A {
|
|
|
|
public function foo() : ?string {}
|
|
|
|
}',
|
|
|
|
'error_message' => 'InvalidReturnType',
|
|
|
|
],
|
2021-04-15 12:55:13 +02:00
|
|
|
'disableNamedArgumentsInDescendant' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2021-04-15 12:55:13 +02:00
|
|
|
interface Foo {
|
|
|
|
public function bar(string ...$_args): void;
|
|
|
|
}
|
|
|
|
final class Baz implements Foo {
|
|
|
|
/** @no-named-arguments */
|
|
|
|
public function bar(string ...$_args): void {}
|
|
|
|
}
|
|
|
|
',
|
|
|
|
'error_message' => 'MethodSignatureMismatch',
|
|
|
|
],
|
2022-02-11 21:53:29 +01:00
|
|
|
'SKIPPED-noMixedTypehintInDescendant' => [
|
2022-01-22 18:05:32 +01:00
|
|
|
'code' => '<?php
|
2022-01-10 13:50:16 +01:00
|
|
|
class a {
|
|
|
|
public function test(): mixed {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
class b extends a {
|
|
|
|
public function test() {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
',
|
2022-01-19 12:33:16 +01:00
|
|
|
'error_message' => 'MethodSignatureMismatch',
|
2022-01-22 18:05:32 +01:00
|
|
|
'ignored_issues' => [],
|
2022-12-18 17:15:15 +01:00
|
|
|
'php_version' => '8.0',
|
2022-01-10 13:50:16 +01:00
|
|
|
],
|
|
|
|
'noTypehintInNativeDescendant' => [
|
2022-01-22 18:05:32 +01:00
|
|
|
'code' => '<?php
|
2022-01-10 13:50:16 +01:00
|
|
|
class a implements JsonSerializable {
|
|
|
|
public function jsonSerialize() {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
',
|
2022-01-19 12:20:50 +01:00
|
|
|
'error_message' => 'MethodSignatureMustProvideReturnType',
|
2022-01-22 18:05:32 +01:00
|
|
|
'ignored_issues' => [],
|
2022-12-18 17:15:15 +01:00
|
|
|
'php_version' => '8.1',
|
2022-01-10 13:50:16 +01:00
|
|
|
],
|
2017-04-25 05:45:02 +02:00
|
|
|
];
|
|
|
|
}
|
2016-12-15 01:24:33 +01:00
|
|
|
}
|