2016-10-25 01:20:28 +02:00
|
|
|
<?php
|
|
|
|
namespace Psalm\Tests;
|
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
class InterfaceTest extends TestCase
|
2016-10-25 01:20:28 +02:00
|
|
|
{
|
2017-04-25 05:45:02 +02:00
|
|
|
use Traits\FileCheckerInvalidCodeParseTestTrait;
|
|
|
|
use Traits\FileCheckerValidCodeParseTestTrait;
|
2017-01-12 17:16:00 +01:00
|
|
|
|
2017-01-31 00:38:23 +01:00
|
|
|
/**
|
2017-04-25 05:45:02 +02:00
|
|
|
* @return array
|
2017-01-31 00:38:23 +01:00
|
|
|
*/
|
2017-04-25 05:45:02 +02:00
|
|
|
public function providerFileCheckerValidCodeParse()
|
2017-01-31 00:38:23 +01:00
|
|
|
{
|
2017-04-25 05:45:02 +02:00
|
|
|
return [
|
|
|
|
'extendsAndImplements' => [
|
|
|
|
'<?php
|
|
|
|
interface A
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function fooFoo();
|
|
|
|
}
|
2017-06-29 16:22:49 +02:00
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
interface B
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function barBar();
|
|
|
|
}
|
2017-06-29 16:22:49 +02:00
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
interface C extends A, B
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function baz();
|
|
|
|
}
|
2017-06-29 16:22:49 +02:00
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
class D implements C
|
|
|
|
{
|
2017-11-26 22:03:17 +01:00
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
2017-04-25 05:45:02 +02:00
|
|
|
public function fooFoo()
|
|
|
|
{
|
|
|
|
return "hello";
|
|
|
|
}
|
2017-06-29 16:22:49 +02:00
|
|
|
|
2017-11-26 22:03:17 +01:00
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
2017-04-25 05:45:02 +02:00
|
|
|
public function barBar()
|
|
|
|
{
|
|
|
|
return "goodbye";
|
|
|
|
}
|
2017-06-29 16:22:49 +02:00
|
|
|
|
2017-11-26 22:03:17 +01:00
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
2017-04-25 05:45:02 +02:00
|
|
|
public function baz()
|
|
|
|
{
|
|
|
|
return "hello again";
|
|
|
|
}
|
|
|
|
}
|
2017-06-29 16:22:49 +02:00
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
$cee = (new D())->baz();
|
|
|
|
$dee = (new D())->fooFoo();',
|
|
|
|
'assertions' => [
|
2017-06-29 16:22:49 +02:00
|
|
|
'$cee' => 'string',
|
|
|
|
'$dee' => 'string',
|
2017-05-27 02:05:57 +02:00
|
|
|
],
|
2017-04-25 05:45:02 +02:00
|
|
|
],
|
|
|
|
'isExtendedInterface' => [
|
|
|
|
'<?php
|
2017-07-25 22:11:02 +02:00
|
|
|
interface A {}
|
|
|
|
class B implements A {}
|
2017-06-29 16:22:49 +02:00
|
|
|
|
2017-07-25 22:11:02 +02:00
|
|
|
/**
|
|
|
|
* @param A $a
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function qux(A $a) { }
|
2017-06-29 16:22:49 +02:00
|
|
|
|
2017-07-25 22:11:02 +02:00
|
|
|
qux(new B());',
|
|
|
|
],
|
|
|
|
'isDoubleExtendedInterface' => [
|
|
|
|
'<?php
|
|
|
|
interface A {}
|
|
|
|
interface B extends A {}
|
|
|
|
class C implements B {}
|
2017-06-29 16:22:49 +02:00
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
/**
|
|
|
|
* @param A $a
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function qux(A $a) {
|
|
|
|
}
|
2017-06-29 16:22:49 +02:00
|
|
|
|
2017-05-27 02:05:57 +02:00
|
|
|
qux(new C());',
|
2017-04-25 05:45:02 +02:00
|
|
|
],
|
|
|
|
'extendsWithMethod' => [
|
|
|
|
'<?php
|
|
|
|
interface A
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function fooFoo();
|
|
|
|
}
|
2017-06-29 16:22:49 +02:00
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
interface B extends A
|
|
|
|
{
|
|
|
|
public function barBar();
|
|
|
|
}
|
2017-06-29 16:22:49 +02:00
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
/** @return void */
|
|
|
|
function mux(B $b) {
|
|
|
|
$b->fooFoo();
|
2017-05-27 02:05:57 +02:00
|
|
|
}',
|
2017-04-25 05:45:02 +02:00
|
|
|
],
|
|
|
|
'correctInterfaceMethodSignature' => [
|
|
|
|
'<?php
|
|
|
|
interface A {
|
2018-01-11 21:50:45 +01:00
|
|
|
public function fooFoo(int $a): void;
|
2017-04-25 05:45:02 +02:00
|
|
|
}
|
2017-06-29 16:22:49 +02:00
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
class B implements A {
|
2018-01-11 21:50:45 +01:00
|
|
|
public function fooFoo(int $a): void {
|
2017-06-29 16:22:49 +02:00
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
}
|
2017-05-27 02:05:57 +02:00
|
|
|
}',
|
2017-04-25 05:45:02 +02:00
|
|
|
],
|
|
|
|
'interfaceMethodImplementedInParent' => [
|
|
|
|
'<?php
|
|
|
|
interface MyInterface {
|
2018-01-11 21:50:45 +01:00
|
|
|
public function fooFoo(int $a): void;
|
2017-04-25 05:45:02 +02:00
|
|
|
}
|
2017-06-29 16:22:49 +02:00
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
class B {
|
2018-01-11 21:50:45 +01:00
|
|
|
public function fooFoo(int $a): void {
|
2017-06-29 16:22:49 +02:00
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
}
|
|
|
|
}
|
2017-06-29 16:22:49 +02:00
|
|
|
|
2017-05-27 02:05:57 +02:00
|
|
|
class C extends B implements MyInterface { }',
|
2017-04-25 05:45:02 +02:00
|
|
|
],
|
|
|
|
'interfaceMethodSignatureInTrait' => [
|
|
|
|
'<?php
|
|
|
|
interface A {
|
2018-01-11 21:50:45 +01:00
|
|
|
public function fooFoo(int $a, int $b): void;
|
2017-04-25 05:45:02 +02:00
|
|
|
}
|
2017-06-29 16:22:49 +02:00
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
trait T {
|
2018-01-11 21:50:45 +01:00
|
|
|
public function fooFoo(int $a, int $b): void {
|
2017-04-25 05:45:02 +02:00
|
|
|
}
|
|
|
|
}
|
2017-06-29 16:22:49 +02:00
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
class B implements A {
|
|
|
|
use T;
|
2017-05-27 02:05:57 +02:00
|
|
|
}',
|
2017-04-25 05:45:02 +02:00
|
|
|
],
|
|
|
|
'delayedInterface' => [
|
|
|
|
'<?php
|
|
|
|
// fails in PHP, whatcha gonna do
|
|
|
|
$c = new C;
|
2017-06-29 16:22:49 +02:00
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
class A { }
|
2017-06-29 16:22:49 +02:00
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
interface B { }
|
2017-06-29 16:22:49 +02:00
|
|
|
|
2017-05-27 02:05:57 +02:00
|
|
|
class C extends A implements B { }',
|
2017-04-25 05:45:02 +02:00
|
|
|
],
|
|
|
|
'typeDoesNotContainType' => [
|
|
|
|
'<?php
|
|
|
|
interface A { }
|
|
|
|
interface B {
|
|
|
|
function foo();
|
|
|
|
}
|
2018-01-11 21:50:45 +01:00
|
|
|
function bar(A $a): void {
|
2017-04-25 05:45:02 +02:00
|
|
|
if ($a instanceof B) {
|
|
|
|
$a->foo();
|
|
|
|
}
|
2017-05-27 02:05:57 +02:00
|
|
|
}',
|
2017-04-25 05:45:02 +02:00
|
|
|
],
|
|
|
|
'abstractInterfaceImplements' => [
|
|
|
|
'<?php
|
|
|
|
interface I {
|
|
|
|
public function fnc();
|
|
|
|
}
|
2017-06-29 16:22:49 +02:00
|
|
|
|
2017-05-27 02:05:57 +02:00
|
|
|
abstract class A implements I {}',
|
2017-04-25 05:45:02 +02:00
|
|
|
],
|
|
|
|
'abstractInterfaceImplementsButCallMethod' => [
|
|
|
|
'<?php
|
|
|
|
interface I {
|
|
|
|
public function foo();
|
|
|
|
}
|
2017-06-29 16:22:49 +02:00
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
abstract class A implements I {
|
2018-01-11 21:50:45 +01:00
|
|
|
public function bar(): void {
|
2017-04-25 05:45:02 +02:00
|
|
|
$this->foo();
|
|
|
|
}
|
2017-05-27 02:05:57 +02:00
|
|
|
}',
|
2017-04-25 05:45:02 +02:00
|
|
|
],
|
|
|
|
'implementsPartialInterfaceMethods' => [
|
|
|
|
'<?php
|
|
|
|
namespace Bat;
|
2017-06-29 16:22:49 +02:00
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
interface I {
|
|
|
|
public function foo();
|
|
|
|
public function bar();
|
|
|
|
}
|
|
|
|
abstract class A implements I {
|
|
|
|
public function foo() {
|
|
|
|
return "hello";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
class B extends A {
|
|
|
|
public function bar() {
|
|
|
|
return "goodbye";
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
'assertions' => [],
|
2017-05-27 02:05:57 +02:00
|
|
|
'error_levels' => ['MissingReturnType'],
|
2017-04-25 05:45:02 +02:00
|
|
|
],
|
|
|
|
'interfaceConstants' => [
|
|
|
|
'<?php
|
|
|
|
interface I1 {
|
|
|
|
const A = 5;
|
|
|
|
const B = "two";
|
|
|
|
const C = 3.0;
|
|
|
|
}
|
2017-06-29 16:22:49 +02:00
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
interface I2 extends I1 {
|
|
|
|
const D = 5;
|
|
|
|
const E = "two";
|
|
|
|
}
|
2017-06-29 16:22:49 +02:00
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
class A implements I2 {
|
|
|
|
/** @var int */
|
|
|
|
public $foo = I1::A;
|
2017-06-29 16:22:49 +02:00
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
/** @var string */
|
|
|
|
public $bar = self::B;
|
2017-06-29 16:22:49 +02:00
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
/** @var float */
|
|
|
|
public $bar2 = I2::C;
|
2017-06-29 16:22:49 +02:00
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
/** @var int */
|
|
|
|
public $foo2 = I2::D;
|
2017-06-29 16:22:49 +02:00
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
/** @var string */
|
|
|
|
public $bar3 = self::E;
|
2017-05-27 02:05:57 +02:00
|
|
|
}',
|
2017-04-25 05:45:02 +02:00
|
|
|
],
|
|
|
|
'interfaceExtendsReturnType' => [
|
|
|
|
'<?php
|
|
|
|
interface A {}
|
|
|
|
interface B extends A {}
|
2017-06-29 16:22:49 +02:00
|
|
|
|
2018-01-11 21:50:45 +01:00
|
|
|
function foo(B $a): A {
|
2017-04-25 05:45:02 +02:00
|
|
|
return $a;
|
2017-05-27 02:05:57 +02:00
|
|
|
}',
|
|
|
|
],
|
2017-11-28 00:07:38 +01:00
|
|
|
'interfaceInstanceofReturningInitial' => [
|
2017-07-10 16:34:45 +02:00
|
|
|
'<?php
|
|
|
|
interface A {}
|
|
|
|
interface B {}
|
|
|
|
|
2017-11-27 22:49:59 +01:00
|
|
|
class C implements A, B {}
|
|
|
|
|
2018-01-11 21:50:45 +01:00
|
|
|
function takesB(B $b): void {}
|
2017-11-28 00:07:38 +01:00
|
|
|
|
2018-01-11 21:50:45 +01:00
|
|
|
function foo(A $i): A {
|
2017-11-27 22:49:59 +01:00
|
|
|
if ($i instanceof B) {
|
2017-11-28 00:07:38 +01:00
|
|
|
takesB($i);
|
2017-11-27 22:49:59 +01:00
|
|
|
return $i;
|
|
|
|
}
|
2017-07-10 16:34:45 +02:00
|
|
|
return $i;
|
2017-11-27 22:49:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
foo(new C);',
|
|
|
|
],
|
|
|
|
'interfaceInstanceofAndReturn' => [
|
|
|
|
'<?php
|
|
|
|
interface A {}
|
|
|
|
interface B {}
|
|
|
|
|
|
|
|
class C implements A, B {}
|
|
|
|
|
2018-01-11 21:50:45 +01:00
|
|
|
function foo(A $i): B {
|
2017-11-27 22:49:59 +01:00
|
|
|
if ($i instanceof B) {
|
|
|
|
return $i;
|
|
|
|
}
|
|
|
|
throw new \Exception("bad");
|
|
|
|
}
|
|
|
|
|
|
|
|
foo(new C);',
|
2017-07-10 16:34:45 +02:00
|
|
|
],
|
2017-11-27 17:43:06 +01:00
|
|
|
'extendIteratorIterator' => [
|
|
|
|
'<?php
|
|
|
|
class SomeIterator extends IteratorIterator {}',
|
|
|
|
],
|
2017-11-30 06:07:36 +01:00
|
|
|
'suppressMismatch' => [
|
|
|
|
'<?php
|
|
|
|
interface I {
|
|
|
|
/**
|
2018-01-10 06:07:47 +01:00
|
|
|
* @return int
|
2017-11-30 06:07:36 +01:00
|
|
|
*/
|
|
|
|
public function check();
|
|
|
|
}
|
|
|
|
|
|
|
|
class C implements I
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @psalm-suppress ImplementedReturnTypeMismatch
|
|
|
|
*/
|
|
|
|
public function check(): bool
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2018-01-23 07:32:16 +01:00
|
|
|
}',
|
|
|
|
],
|
|
|
|
'implementStaticReturn' => [
|
|
|
|
'<?php
|
|
|
|
class A {}
|
|
|
|
interface I {
|
|
|
|
/** @return A */
|
|
|
|
public function foo();
|
|
|
|
}
|
|
|
|
|
|
|
|
class B extends A implements I {
|
|
|
|
/** @return static */
|
|
|
|
public function foo() {
|
|
|
|
return $this;
|
|
|
|
}
|
2018-03-22 22:55:36 +01:00
|
|
|
}',
|
|
|
|
],
|
|
|
|
'implementThisReturn' => [
|
|
|
|
'<?php
|
|
|
|
class A {}
|
|
|
|
interface I {
|
|
|
|
/** @return A */
|
|
|
|
public function foo();
|
|
|
|
}
|
|
|
|
|
|
|
|
class B extends A implements I {
|
|
|
|
/** @return $this */
|
|
|
|
public function foo() {
|
|
|
|
return $this;
|
|
|
|
}
|
2017-11-30 06:07:36 +01:00
|
|
|
}',
|
|
|
|
],
|
2018-01-26 17:50:29 +01:00
|
|
|
'inheritMultipleInterfacesWithDocblocks' => [
|
|
|
|
'<?php
|
|
|
|
interface I1 {
|
|
|
|
/** @return string */
|
|
|
|
public function foo();
|
|
|
|
}
|
|
|
|
interface I2 {
|
|
|
|
/** @return string */
|
|
|
|
public function bar();
|
|
|
|
}
|
|
|
|
class A implements I1, I2 {
|
|
|
|
public function foo() {
|
|
|
|
return "hello";
|
|
|
|
}
|
|
|
|
public function bar() {
|
|
|
|
return "goodbye";
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
],
|
|
|
|
'interfaceReturnType' => [
|
|
|
|
'<?php
|
|
|
|
interface A {
|
|
|
|
/** @return string|null */
|
|
|
|
public function blah();
|
|
|
|
}
|
|
|
|
|
|
|
|
class B implements A {
|
|
|
|
public function blah() {
|
|
|
|
return rand(0, 10) === 4 ? "blah" : null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$blah = (new B())->blah();',
|
|
|
|
],
|
2018-01-26 20:08:45 +01:00
|
|
|
'interfaceExtendsTraversible' => [
|
|
|
|
'<?php
|
|
|
|
interface Collection extends Countable, IteratorAggregate, ArrayAccess {}
|
|
|
|
|
|
|
|
function takesCollection(Collection $c): void {
|
|
|
|
takesIterable($c);
|
|
|
|
}
|
|
|
|
|
|
|
|
function takesIterable(iterable $i): void {}',
|
|
|
|
],
|
2017-04-25 05:45:02 +02:00
|
|
|
];
|
2017-01-31 00:38:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-04-25 05:45:02 +02:00
|
|
|
* @return array
|
2017-01-31 00:38:23 +01:00
|
|
|
*/
|
2017-04-25 05:45:02 +02:00
|
|
|
public function providerFileCheckerInvalidCodeParse()
|
2017-01-31 00:38:23 +01:00
|
|
|
{
|
2017-04-25 05:45:02 +02:00
|
|
|
return [
|
2017-07-25 22:11:02 +02:00
|
|
|
'invalidInterface' => [
|
|
|
|
'<?php
|
|
|
|
class C2 implements A { }',
|
|
|
|
'error_message' => 'UndefinedClass',
|
|
|
|
],
|
2017-04-25 05:45:02 +02:00
|
|
|
'noInterfaceProperties' => [
|
|
|
|
'<?php
|
|
|
|
interface A { }
|
2017-06-29 16:22:49 +02:00
|
|
|
|
2018-01-11 21:50:45 +01:00
|
|
|
function fooFoo(A $a): void {
|
2017-04-25 05:45:02 +02:00
|
|
|
if ($a->bar) {
|
2017-06-29 16:22:49 +02:00
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
}
|
|
|
|
}',
|
2017-05-27 02:05:57 +02:00
|
|
|
'error_message' => 'NoInterfaceProperties',
|
2017-04-25 05:45:02 +02:00
|
|
|
],
|
|
|
|
'unimplementedInterfaceMethod' => [
|
|
|
|
'<?php
|
|
|
|
interface A {
|
|
|
|
public function fooFoo();
|
|
|
|
}
|
2017-06-29 16:22:49 +02:00
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
class B implements A { }',
|
2017-05-27 02:05:57 +02:00
|
|
|
'error_message' => 'UnimplementedInterfaceMethod',
|
2017-04-25 05:45:02 +02:00
|
|
|
],
|
|
|
|
'mismatchingInterfaceMethodSignature' => [
|
|
|
|
'<?php
|
|
|
|
interface A {
|
2018-01-11 21:50:45 +01:00
|
|
|
public function fooFoo(int $a): void;
|
2017-04-25 05:45:02 +02:00
|
|
|
}
|
2017-06-29 16:22:49 +02:00
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
class B implements A {
|
2018-01-11 21:50:45 +01:00
|
|
|
public function fooFoo(string $a): void {
|
2017-06-29 16:22:49 +02:00
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
}
|
|
|
|
}',
|
2017-05-27 02:05:57 +02:00
|
|
|
'error_message' => 'MethodSignatureMismatch',
|
2017-04-25 05:45:02 +02:00
|
|
|
],
|
|
|
|
'mismatchingInterfaceMethodSignatureInTrait' => [
|
|
|
|
'<?php
|
|
|
|
interface A {
|
2018-01-11 21:50:45 +01:00
|
|
|
public function fooFoo(int $a, int $b): void;
|
2017-04-25 05:45:02 +02:00
|
|
|
}
|
2017-06-29 16:22:49 +02:00
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
trait T {
|
2018-01-11 21:50:45 +01:00
|
|
|
public function fooFoo(int $a): void {
|
2017-04-25 05:45:02 +02:00
|
|
|
}
|
|
|
|
}
|
2017-06-29 16:22:49 +02:00
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
class B implements A {
|
|
|
|
use T;
|
|
|
|
}',
|
2017-05-27 02:05:57 +02:00
|
|
|
'error_message' => 'MethodSignatureMismatch',
|
2017-04-25 05:45:02 +02:00
|
|
|
],
|
|
|
|
'mismatchingInterfaceMethodSignatureInImplementer' => [
|
|
|
|
'<?php
|
|
|
|
interface A {
|
2018-01-11 21:50:45 +01:00
|
|
|
public function fooFoo(int $a, int $b): void;
|
2017-04-25 05:45:02 +02:00
|
|
|
}
|
2017-06-29 16:22:49 +02:00
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
trait T {
|
2018-01-11 21:50:45 +01:00
|
|
|
public function fooFoo(int $a, int $b): void {
|
2017-04-25 05:45:02 +02:00
|
|
|
}
|
|
|
|
}
|
2017-06-29 16:22:49 +02:00
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
class B implements A {
|
|
|
|
use T;
|
2017-06-29 16:22:49 +02:00
|
|
|
|
2018-01-11 21:50:45 +01:00
|
|
|
public function fooFoo(int $a): void {
|
2017-04-25 05:45:02 +02:00
|
|
|
}
|
|
|
|
}',
|
2017-05-27 02:05:57 +02:00
|
|
|
'error_message' => 'MethodSignatureMismatch',
|
2017-04-25 05:45:02 +02:00
|
|
|
],
|
2017-11-26 22:03:17 +01:00
|
|
|
'mismatchingReturnTypes' => [
|
|
|
|
'<?php
|
|
|
|
interface I1 {
|
2018-01-11 21:50:45 +01:00
|
|
|
public function foo(): string;
|
2017-11-26 22:03:17 +01:00
|
|
|
}
|
|
|
|
interface I2 {
|
2018-01-11 21:50:45 +01:00
|
|
|
public function foo(): int;
|
2017-11-26 22:03:17 +01:00
|
|
|
}
|
|
|
|
class A implements I1, I2 {
|
2018-01-11 21:50:45 +01:00
|
|
|
public function foo(): string {
|
2017-11-26 22:03:17 +01:00
|
|
|
return "hello";
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
'error_message' => 'MethodSignatureMismatch',
|
|
|
|
],
|
|
|
|
'mismatchingDocblockReturnTypes' => [
|
|
|
|
'<?php
|
|
|
|
interface I1 {
|
|
|
|
/** @return string */
|
|
|
|
public function foo();
|
|
|
|
}
|
|
|
|
interface I2 {
|
|
|
|
/** @return int */
|
|
|
|
public function foo();
|
|
|
|
}
|
|
|
|
class A implements I1, I2 {
|
|
|
|
/** @return string */
|
|
|
|
public function foo() {
|
|
|
|
return "hello";
|
|
|
|
}
|
|
|
|
}',
|
2017-11-30 06:01:41 +01:00
|
|
|
'error_message' => 'ImplementedReturnTypeMismatch',
|
2017-11-26 22:03:17 +01:00
|
|
|
],
|
2017-04-25 05:45:02 +02:00
|
|
|
'abstractInterfaceImplementsButCallUndefinedMethod' => [
|
|
|
|
'<?php
|
|
|
|
interface I {
|
|
|
|
public function foo();
|
|
|
|
}
|
2017-06-29 16:22:49 +02:00
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
abstract class A implements I {
|
2018-01-11 21:50:45 +01:00
|
|
|
public function bar(): void {
|
2017-04-25 05:45:02 +02:00
|
|
|
$this->foo2();
|
|
|
|
}
|
|
|
|
}',
|
2017-05-27 02:05:57 +02:00
|
|
|
'error_message' => 'UndefinedMethod',
|
2017-04-25 05:45:02 +02:00
|
|
|
],
|
|
|
|
'abstractInterfaceImplementsWithSubclass' => [
|
|
|
|
'<?php
|
|
|
|
interface I {
|
|
|
|
public function fnc();
|
|
|
|
}
|
2017-06-29 16:22:49 +02:00
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
abstract class A implements I {}
|
2017-06-29 16:22:49 +02:00
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
class B extends A {}',
|
2017-05-27 02:05:57 +02:00
|
|
|
'error_message' => 'UnimplementedInterfaceMethod',
|
2017-04-25 05:45:02 +02:00
|
|
|
],
|
2017-12-07 21:50:25 +01:00
|
|
|
'lessSpecificReturnStatement' => [
|
2017-04-25 05:45:02 +02:00
|
|
|
'<?php
|
|
|
|
interface A {}
|
|
|
|
interface B extends A {}
|
2017-06-29 16:22:49 +02:00
|
|
|
|
2018-01-11 21:50:45 +01:00
|
|
|
function foo(A $a): B {
|
2017-04-25 05:45:02 +02:00
|
|
|
return $a;
|
|
|
|
}',
|
2017-12-07 21:50:25 +01:00
|
|
|
'error_message' => 'LessSpecificReturnStatement',
|
2017-05-27 02:05:57 +02:00
|
|
|
],
|
2017-11-28 01:15:01 +01:00
|
|
|
'interfaceInstanceofAndTwoReturns' => [
|
2017-11-28 00:07:38 +01:00
|
|
|
'<?php
|
|
|
|
interface A {}
|
|
|
|
interface B {}
|
|
|
|
|
|
|
|
class C implements A, B {}
|
|
|
|
|
2018-01-11 21:50:45 +01:00
|
|
|
function foo(A $i): B {
|
2017-11-28 00:07:38 +01:00
|
|
|
if ($i instanceof B) {
|
|
|
|
return $i;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $i;
|
|
|
|
}
|
|
|
|
|
|
|
|
foo(new C);',
|
2017-12-07 21:50:25 +01:00
|
|
|
'error_message' => 'InvalidReturnStatement',
|
2017-11-28 00:07:38 +01:00
|
|
|
],
|
2018-01-23 15:09:43 +01:00
|
|
|
'deprecatedInterface' => [
|
|
|
|
'<?php
|
|
|
|
/** @deprecated */
|
|
|
|
interface Container {}
|
|
|
|
|
|
|
|
class A implements Container {}',
|
|
|
|
'error_message' => 'DeprecatedInterface',
|
|
|
|
],
|
2018-01-26 17:50:29 +01:00
|
|
|
'inheritMultipleInterfacesWithConflictingDocblocks' => [
|
|
|
|
'<?php
|
|
|
|
interface I1 {
|
|
|
|
/** @return string */
|
|
|
|
public function foo();
|
|
|
|
}
|
|
|
|
interface I2 {
|
|
|
|
/** @return int */
|
|
|
|
public function foo();
|
|
|
|
}
|
|
|
|
class A implements I1, I2 {
|
|
|
|
public function foo() {
|
|
|
|
return "hello";
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
'error_message' => 'InvalidReturnType',
|
|
|
|
],
|
2018-02-18 00:53:02 +01:00
|
|
|
'interfaceInstantiation' => [
|
|
|
|
'<?php
|
|
|
|
interface myInterface{}
|
|
|
|
new myInterface();',
|
|
|
|
'error_message' => 'InterfaceInstantiation',
|
|
|
|
],
|
2017-04-25 05:45:02 +02:00
|
|
|
];
|
2017-01-31 00:38:23 +01:00
|
|
|
}
|
2016-10-25 01:20:28 +02:00
|
|
|
}
|