2019-05-02 18:15:38 +02:00
|
|
|
<?php
|
|
|
|
namespace Psalm\Tests\FileManipulation;
|
|
|
|
|
2021-01-11 23:30:33 +01:00
|
|
|
class ParamTypeManipulationTest extends FileManipulationTestCase
|
2019-05-02 18:15:38 +02:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @return array<string,array{string,string,string,string[],bool}>
|
|
|
|
*/
|
2020-09-12 17:24:05 +02:00
|
|
|
public function providerValidCodeParse(): array
|
2019-05-02 18:15:38 +02:00
|
|
|
{
|
|
|
|
return [
|
|
|
|
'fixMismatchingDocblockParamType70' => [
|
|
|
|
'<?php
|
|
|
|
/**
|
|
|
|
* @param int $s
|
|
|
|
*/
|
|
|
|
function foo(string $s): string {
|
|
|
|
return "hello";
|
|
|
|
}',
|
|
|
|
'<?php
|
|
|
|
/**
|
|
|
|
* @param string $s
|
|
|
|
*/
|
|
|
|
function foo(string $s): string {
|
|
|
|
return "hello";
|
|
|
|
}',
|
|
|
|
'7.0',
|
|
|
|
['MismatchingDocblockParamType'],
|
|
|
|
true,
|
|
|
|
],
|
|
|
|
'fixNamespacedMismatchingDocblockParamsType70' => [
|
|
|
|
'<?php
|
|
|
|
namespace Foo\Bar {
|
|
|
|
class A {
|
|
|
|
/**
|
|
|
|
* @param \B $b
|
|
|
|
* @param \C $c
|
|
|
|
*/
|
|
|
|
function foo(B $b, C $c): string {
|
|
|
|
return "hello";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
class B {}
|
|
|
|
class C {}
|
|
|
|
}',
|
|
|
|
'<?php
|
|
|
|
namespace Foo\Bar {
|
|
|
|
class A {
|
|
|
|
/**
|
|
|
|
* @param B $b
|
|
|
|
* @param C $c
|
|
|
|
*/
|
|
|
|
function foo(B $b, C $c): string {
|
|
|
|
return "hello";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
class B {}
|
|
|
|
class C {}
|
|
|
|
}',
|
|
|
|
'7.0',
|
|
|
|
['MismatchingDocblockParamType'],
|
|
|
|
true,
|
|
|
|
],
|
|
|
|
'noStringParamType' => [
|
2019-12-03 07:49:43 +01:00
|
|
|
'<?php
|
|
|
|
class C {
|
|
|
|
public function fooFoo($a): void {}
|
|
|
|
}
|
|
|
|
|
|
|
|
(new C)->fooFoo("hello");',
|
|
|
|
'<?php
|
|
|
|
class C {
|
|
|
|
public function fooFoo(string $a): void {}
|
|
|
|
}
|
|
|
|
|
|
|
|
(new C)->fooFoo("hello");',
|
|
|
|
'7.1',
|
|
|
|
['MissingParamType'],
|
|
|
|
true,
|
|
|
|
],
|
2019-12-03 07:59:36 +01:00
|
|
|
'noStringParamTypeWithVariableCall' => [
|
|
|
|
'<?php
|
|
|
|
class C {
|
|
|
|
public function fooFoo($a): void {}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @var mixed */
|
|
|
|
$c = null;
|
|
|
|
$c->fooFoo("hello");
|
|
|
|
|
|
|
|
(new C)->fooFoo("hello");',
|
|
|
|
'<?php
|
|
|
|
class C {
|
|
|
|
/**
|
|
|
|
* @param string $a
|
|
|
|
*/
|
|
|
|
public function fooFoo($a): void {}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @var mixed */
|
|
|
|
$c = null;
|
|
|
|
$c->fooFoo("hello");
|
|
|
|
|
|
|
|
(new C)->fooFoo("hello");',
|
|
|
|
'7.1',
|
|
|
|
['MissingParamType'],
|
|
|
|
true,
|
|
|
|
],
|
2019-12-03 07:52:18 +01:00
|
|
|
'noStringParamTypeWithDocblockCall' => [
|
|
|
|
'<?php
|
|
|
|
class C {
|
|
|
|
public function fooFoo($a): void {}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $a
|
|
|
|
*/
|
|
|
|
function callsWithString($a): void {
|
|
|
|
(new C)->fooFoo($a);
|
|
|
|
}',
|
|
|
|
'<?php
|
|
|
|
class C {
|
|
|
|
/**
|
|
|
|
* @param string $a
|
|
|
|
*/
|
|
|
|
public function fooFoo($a): void {}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $a
|
|
|
|
*/
|
|
|
|
function callsWithString($a): void {
|
|
|
|
(new C)->fooFoo($a);
|
|
|
|
}',
|
|
|
|
'7.1',
|
|
|
|
['MissingParamType'],
|
|
|
|
true,
|
|
|
|
],
|
2019-12-03 07:49:43 +01:00
|
|
|
'noStringParamType56' => [
|
2019-05-02 18:15:38 +02:00
|
|
|
'<?php
|
2019-05-31 07:47:35 +02:00
|
|
|
class C {
|
|
|
|
public function fooFoo($a): void {}
|
2019-05-02 18:15:38 +02:00
|
|
|
}
|
|
|
|
|
2019-05-31 07:47:35 +02:00
|
|
|
(new C)->fooFoo("hello");',
|
2019-05-02 18:15:38 +02:00
|
|
|
'<?php
|
2019-05-31 07:47:35 +02:00
|
|
|
class C {
|
|
|
|
/**
|
|
|
|
* @param string $a
|
|
|
|
*/
|
|
|
|
public function fooFoo($a): void {}
|
2019-05-02 18:15:38 +02:00
|
|
|
}
|
|
|
|
|
2019-05-31 07:47:35 +02:00
|
|
|
(new C)->fooFoo("hello");',
|
2019-12-03 07:49:43 +01:00
|
|
|
'5.6',
|
2019-05-02 18:15:38 +02:00
|
|
|
['MissingParamType'],
|
|
|
|
true,
|
|
|
|
],
|
2019-05-31 17:55:24 +02:00
|
|
|
'noBoolParamTypeWithDefault' => [
|
|
|
|
'<?php
|
|
|
|
class C {
|
|
|
|
public function fooFoo($a = true): void {}
|
|
|
|
}
|
|
|
|
|
|
|
|
(new C)->fooFoo(false);',
|
|
|
|
'<?php
|
|
|
|
class C {
|
2019-12-03 07:49:43 +01:00
|
|
|
public function fooFoo(bool $a = true): void {}
|
2019-05-31 17:55:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
(new C)->fooFoo(false);',
|
|
|
|
'7.1',
|
|
|
|
['MissingParamType'],
|
|
|
|
true,
|
|
|
|
],
|
2019-05-31 16:37:26 +02:00
|
|
|
'noStringParamTypeParent' => [
|
|
|
|
'<?php
|
|
|
|
class C {
|
|
|
|
public function fooFoo($a): void {}
|
|
|
|
}
|
|
|
|
|
|
|
|
class D extends C {}
|
|
|
|
|
|
|
|
(new D)->fooFoo("hello");',
|
|
|
|
'<?php
|
|
|
|
class C {
|
2019-12-03 07:49:43 +01:00
|
|
|
public function fooFoo(string $a): void {}
|
2019-05-31 16:37:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
class D extends C {}
|
|
|
|
|
|
|
|
(new D)->fooFoo("hello");',
|
|
|
|
'7.1',
|
|
|
|
['MissingParamType'],
|
|
|
|
true,
|
|
|
|
],
|
2019-05-31 07:47:35 +02:00
|
|
|
'stringParamTypeNoOp' => [
|
2019-05-02 18:15:38 +02:00
|
|
|
'<?php
|
2019-05-31 07:47:35 +02:00
|
|
|
class C {
|
|
|
|
public function fooFoo(string $a): void {}
|
2019-05-02 18:15:38 +02:00
|
|
|
}
|
|
|
|
|
2019-05-31 07:47:35 +02:00
|
|
|
(new C)->fooFoo("hello");',
|
2019-05-02 18:15:38 +02:00
|
|
|
'<?php
|
2019-05-31 07:47:35 +02:00
|
|
|
class C {
|
|
|
|
public function fooFoo(string $a): void {}
|
2019-05-02 18:15:38 +02:00
|
|
|
}
|
|
|
|
|
2019-05-31 07:47:35 +02:00
|
|
|
(new C)->fooFoo("hello");',
|
2019-05-02 18:15:38 +02:00
|
|
|
'7.1',
|
|
|
|
['MissingParamType'],
|
|
|
|
true,
|
|
|
|
],
|
2020-02-21 06:42:52 +01:00
|
|
|
'addMissingByRefParamType' => [
|
|
|
|
'<?php
|
|
|
|
class C {
|
|
|
|
public function foo(&$bar) : void {
|
|
|
|
$bar .= " me";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$a = "hello";
|
|
|
|
(new C)->foo($a);',
|
|
|
|
'<?php
|
|
|
|
class C {
|
|
|
|
public function foo(string &$bar) : void {
|
|
|
|
$bar .= " me";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$a = "hello";
|
|
|
|
(new C)->foo($a);',
|
|
|
|
'7.1',
|
|
|
|
['MissingParamType'],
|
|
|
|
true,
|
|
|
|
],
|
2019-05-02 18:15:38 +02:00
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|