2019-09-25 16:39:16 +02:00
|
|
|
<?php
|
|
|
|
namespace Psalm\Tests;
|
|
|
|
|
|
|
|
class DocblockInheritanceTest extends TestCase
|
|
|
|
{
|
|
|
|
use Traits\InvalidCodeAnalysisTestTrait;
|
|
|
|
use Traits\ValidCodeAnalysisTestTrait;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return iterable<string,array{string,assertions?:array<string,string>,error_levels?:string[]}>
|
|
|
|
*/
|
2020-09-12 17:24:05 +02:00
|
|
|
public function providerValidCodeParse(): iterable
|
2019-09-25 16:39:16 +02:00
|
|
|
{
|
|
|
|
return [
|
|
|
|
'inheritParentReturnDocbblock' => [
|
|
|
|
'<?php
|
|
|
|
class Foo {
|
|
|
|
/**
|
|
|
|
* @return int[]
|
|
|
|
*/
|
|
|
|
public function doFoo() {
|
|
|
|
return [1, 2, 3];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class Bar extends Foo {
|
|
|
|
public function doFoo(): array {
|
|
|
|
return [4, 5, 6];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$b = (new Bar)->doFoo();',
|
|
|
|
[
|
|
|
|
'$b' => 'array<array-key, int>',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'inheritedSelfAnnotation' => [
|
|
|
|
'<?php
|
|
|
|
interface I {
|
|
|
|
/**
|
|
|
|
* @param self $i
|
|
|
|
* @return self
|
|
|
|
*/
|
|
|
|
function foo(self $i) : self;
|
|
|
|
}
|
|
|
|
|
|
|
|
class C implements I {
|
|
|
|
public function foo(I $i) : I {
|
|
|
|
return $i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function takeI(I $i) : I {
|
|
|
|
return (new C)->foo($i);
|
|
|
|
}',
|
|
|
|
],
|
2019-09-25 18:02:50 +02:00
|
|
|
'inheritTwice' => [
|
|
|
|
'<?php
|
|
|
|
class Foo {
|
|
|
|
/**
|
|
|
|
* @return string[]
|
|
|
|
*/
|
|
|
|
public function aa() {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class Bar extends Foo {
|
|
|
|
public function aa() {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class Baz extends Bar {
|
|
|
|
public function aa() {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
}'
|
|
|
|
],
|
|
|
|
'inheritTwiceWithArrayType' => [
|
|
|
|
'<?php
|
|
|
|
class Foo {
|
|
|
|
/**
|
|
|
|
* @return string[]
|
|
|
|
*/
|
|
|
|
public function aa() : array {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class Bar extends Foo {
|
|
|
|
public function aa() : array {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class Baz extends Bar {
|
|
|
|
public function aa() : array {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
}'
|
|
|
|
],
|
2019-09-25 16:39:16 +02:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return iterable<string,array{string,error_message:string,2?:string[],3?:bool,4?:string}>
|
|
|
|
*/
|
2020-09-12 17:24:05 +02:00
|
|
|
public function providerInvalidCodeParse(): iterable
|
2019-09-25 16:39:16 +02:00
|
|
|
{
|
|
|
|
return [
|
|
|
|
'automaticInheritDoc' => [
|
|
|
|
'<?php
|
|
|
|
class Y {
|
|
|
|
/**
|
|
|
|
* @param string[] $arr
|
|
|
|
*/
|
|
|
|
public function boo(array $arr) : void {}
|
|
|
|
}
|
|
|
|
|
|
|
|
class X extends Y {
|
|
|
|
public function boo(array $arr) : void {}
|
|
|
|
}
|
|
|
|
|
|
|
|
(new X())->boo([1, 2]);',
|
|
|
|
'error_message' => 'InvalidScalarArgument',
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|