2016-12-12 05:41:11 +01:00
|
|
|
<?php
|
2021-12-15 04:58:32 +01:00
|
|
|
|
2023-10-19 13:12:06 +02:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2016-12-12 05:41:11 +01:00
|
|
|
namespace Psalm\Tests;
|
|
|
|
|
2021-12-03 20:11:20 +01:00
|
|
|
use Psalm\Context;
|
2021-12-04 21:55:53 +01:00
|
|
|
use Psalm\Tests\Traits\InvalidCodeAnalysisTestTrait;
|
|
|
|
use Psalm\Tests\Traits\ValidCodeAnalysisTestTrait;
|
2021-12-03 20:11:20 +01:00
|
|
|
|
2019-06-26 22:52:29 +02:00
|
|
|
use const DIRECTORY_SEPARATOR;
|
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
class MethodCallTest extends TestCase
|
2016-12-12 05:41:11 +01:00
|
|
|
{
|
2021-12-04 21:55:53 +01:00
|
|
|
use InvalidCodeAnalysisTestTrait;
|
|
|
|
use ValidCodeAnalysisTestTrait;
|
2016-12-31 15:20:10 +01:00
|
|
|
|
2021-11-26 20:59:41 +01:00
|
|
|
public function testExtendDocblockParamType(): void
|
2019-04-13 19:53:08 +02:00
|
|
|
{
|
|
|
|
$this->addFile(
|
|
|
|
'somefile.php',
|
|
|
|
'<?php
|
2022-12-18 17:15:15 +01:00
|
|
|
new SoapFault("1", "faultstring", "faultactor");',
|
2019-04-13 19:53:08 +02:00
|
|
|
);
|
|
|
|
|
2021-12-03 20:11:20 +01:00
|
|
|
$this->analyzeFile('somefile.php', new Context());
|
2019-04-13 19:53:08 +02:00
|
|
|
}
|
|
|
|
|
2020-09-12 17:24:05 +02:00
|
|
|
public function testMethodCallMemoize(): void
|
2020-06-04 22:07:00 +02:00
|
|
|
{
|
|
|
|
$this->project_analyzer->getConfig()->memoize_method_calls = true;
|
|
|
|
|
|
|
|
$this->addFile(
|
|
|
|
'somefile.php',
|
|
|
|
'<?php
|
|
|
|
class A {
|
|
|
|
function getFoo() : ?Foo {
|
|
|
|
return rand(0, 1) ? new Foo : null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
class Foo {
|
|
|
|
function getBar() : ?Bar {
|
|
|
|
return rand(0, 1) ? new Bar : null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
class Bar {
|
|
|
|
public function bat() : void {}
|
|
|
|
};
|
|
|
|
|
|
|
|
$a = new A();
|
|
|
|
|
|
|
|
if ($a->getFoo()) {
|
|
|
|
if ($a->getFoo()->getBar()) {
|
|
|
|
$a->getFoo()->getBar()->bat();
|
|
|
|
}
|
2022-12-18 17:15:15 +01:00
|
|
|
}',
|
2020-06-04 22:07:00 +02:00
|
|
|
);
|
|
|
|
|
2021-12-03 20:11:20 +01:00
|
|
|
$this->analyzeFile('somefile.php', new Context());
|
2020-06-04 22:07:00 +02:00
|
|
|
}
|
|
|
|
|
2020-09-12 17:24:05 +02:00
|
|
|
public function testPropertyMethodCallMemoize(): void
|
2020-06-04 22:15:07 +02:00
|
|
|
{
|
|
|
|
$this->project_analyzer->getConfig()->memoize_method_calls = true;
|
|
|
|
|
|
|
|
$this->addFile(
|
|
|
|
'somefile.php',
|
|
|
|
'<?php
|
|
|
|
class Foo
|
|
|
|
{
|
|
|
|
private ?string $bar;
|
|
|
|
|
|
|
|
public function __construct(?string $bar) {
|
|
|
|
$this->bar = $bar;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getBar(): ?string {
|
|
|
|
return $this->bar;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function doSomething(Foo $foo): string {
|
|
|
|
if ($foo->getBar() !== null){
|
|
|
|
return $foo->getBar();
|
|
|
|
}
|
|
|
|
|
|
|
|
return "hello";
|
2022-12-18 17:15:15 +01:00
|
|
|
}',
|
2020-06-04 22:15:07 +02:00
|
|
|
);
|
|
|
|
|
2021-12-03 20:11:20 +01:00
|
|
|
$this->analyzeFile('somefile.php', new Context());
|
2020-06-04 22:15:07 +02:00
|
|
|
}
|
|
|
|
|
2020-09-12 17:24:05 +02:00
|
|
|
public function testPropertyMethodCallMutationFreeMemoize(): void
|
2020-07-16 17:58:27 +02:00
|
|
|
{
|
|
|
|
$this->project_analyzer->getConfig()->memoize_method_calls = true;
|
|
|
|
|
|
|
|
$this->addFile(
|
|
|
|
'somefile.php',
|
|
|
|
'<?php
|
|
|
|
class Foo
|
|
|
|
{
|
|
|
|
private ?string $bar;
|
|
|
|
|
|
|
|
public function __construct(?string $bar) {
|
|
|
|
$this->bar = $bar;
|
|
|
|
}
|
2020-06-04 22:15:07 +02:00
|
|
|
|
2020-07-16 17:58:27 +02:00
|
|
|
/**
|
|
|
|
* @psalm-mutation-free
|
|
|
|
*/
|
|
|
|
public function getBar(): ?string {
|
|
|
|
return $this->bar;
|
|
|
|
}
|
|
|
|
}
|
2020-06-04 22:15:07 +02:00
|
|
|
|
2020-07-16 17:58:27 +02:00
|
|
|
function doSomething(Foo $foo): string {
|
|
|
|
if ($foo->getBar() !== null){
|
|
|
|
return $foo->getBar();
|
|
|
|
}
|
|
|
|
|
|
|
|
return "hello";
|
2022-12-18 17:15:15 +01:00
|
|
|
}',
|
2020-07-16 17:58:27 +02:00
|
|
|
);
|
|
|
|
|
2021-12-03 20:11:20 +01:00
|
|
|
$this->analyzeFile('somefile.php', new Context());
|
2020-07-16 17:58:27 +02:00
|
|
|
}
|
2020-06-04 22:15:07 +02:00
|
|
|
|
2020-09-12 17:24:05 +02:00
|
|
|
public function testUnchainedMethodCallMemoize(): void
|
2020-06-04 22:07:00 +02:00
|
|
|
{
|
|
|
|
$this->project_analyzer->getConfig()->memoize_method_calls = true;
|
|
|
|
|
|
|
|
$this->addFile(
|
|
|
|
'somefile.php',
|
|
|
|
'<?php
|
|
|
|
class SomeClass {
|
|
|
|
private ?int $int;
|
|
|
|
|
|
|
|
public function __construct() {
|
|
|
|
$this->int = 1;
|
|
|
|
}
|
|
|
|
|
2020-07-16 17:58:27 +02:00
|
|
|
final public function getInt(): ?int {
|
|
|
|
return $this->int;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function printInt(int $int): void {
|
|
|
|
echo $int;
|
|
|
|
}
|
|
|
|
|
|
|
|
$obj = new SomeClass();
|
|
|
|
|
|
|
|
if ($obj->getInt()) {
|
|
|
|
printInt($obj->getInt());
|
2022-12-18 17:15:15 +01:00
|
|
|
}',
|
2020-07-16 17:58:27 +02:00
|
|
|
);
|
|
|
|
|
2021-12-03 20:11:20 +01:00
|
|
|
$this->analyzeFile('somefile.php', new Context());
|
2020-07-16 17:58:27 +02:00
|
|
|
}
|
|
|
|
|
2020-09-12 17:24:05 +02:00
|
|
|
public function testUnchainedMutationFreeMethodCallMemoize(): void
|
2020-07-16 17:58:27 +02:00
|
|
|
{
|
|
|
|
$this->project_analyzer->getConfig()->memoize_method_calls = true;
|
|
|
|
|
|
|
|
$this->addFile(
|
|
|
|
'somefile.php',
|
|
|
|
'<?php
|
|
|
|
class SomeClass {
|
|
|
|
private ?int $int;
|
|
|
|
|
|
|
|
public function __construct() {
|
|
|
|
$this->int = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @psalm-mutation-free
|
|
|
|
*/
|
2020-06-04 22:07:00 +02:00
|
|
|
public function getInt(): ?int {
|
|
|
|
return $this->int;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function printInt(int $int): void {
|
|
|
|
echo $int;
|
|
|
|
}
|
|
|
|
|
|
|
|
$obj = new SomeClass();
|
|
|
|
|
|
|
|
if ($obj->getInt()) {
|
|
|
|
printInt($obj->getInt());
|
2022-12-18 17:15:15 +01:00
|
|
|
}',
|
2020-06-04 22:07:00 +02:00
|
|
|
);
|
|
|
|
|
2021-12-03 20:11:20 +01:00
|
|
|
$this->analyzeFile('somefile.php', new Context());
|
2020-06-04 22:07:00 +02:00
|
|
|
}
|
|
|
|
|
2020-09-12 17:24:05 +02:00
|
|
|
public function providerValidCodeParse(): iterable
|
2016-12-17 04:16:29 +01:00
|
|
|
{
|
2017-04-25 05:45:02 +02:00
|
|
|
return [
|
2017-07-09 20:36:06 +02:00
|
|
|
'notInCallMapTest' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2017-07-25 22:11:02 +02:00
|
|
|
new DOMImplementation();',
|
2017-07-09 20:36:06 +02:00
|
|
|
],
|
2017-04-25 05:45:02 +02:00
|
|
|
'parentStaticCall' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2017-04-25 05:45:02 +02:00
|
|
|
class A {
|
|
|
|
/** @return void */
|
|
|
|
public static function foo(){}
|
|
|
|
}
|
2017-07-09 20:36:06 +02:00
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
class B extends A {
|
|
|
|
/** @return void */
|
|
|
|
public static function bar(){
|
|
|
|
parent::foo();
|
|
|
|
}
|
2017-05-27 02:05:57 +02:00
|
|
|
}',
|
2017-04-25 05:45:02 +02:00
|
|
|
],
|
|
|
|
'nonStaticInvocation' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2017-04-25 05:45:02 +02:00
|
|
|
class Foo {
|
2018-01-11 21:50:45 +01:00
|
|
|
public static function barBar(): void {}
|
2017-04-25 05:45:02 +02:00
|
|
|
}
|
2017-07-09 20:36:06 +02:00
|
|
|
|
2017-05-27 02:05:57 +02:00
|
|
|
(new Foo())->barBar();',
|
2017-04-25 05:45:02 +02:00
|
|
|
],
|
|
|
|
'staticInvocation' => [
|
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 static function fooFoo(): void {}
|
2017-04-25 05:45:02 +02:00
|
|
|
}
|
2017-07-09 20:36:06 +02:00
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
class B extends A {
|
2017-07-09 20:36:06 +02:00
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
}
|
2017-07-09 20:36:06 +02:00
|
|
|
|
2017-05-27 02:05:57 +02:00
|
|
|
B::fooFoo();',
|
|
|
|
],
|
2017-11-06 21:37:49 +01:00
|
|
|
'staticCallOnVar' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2017-11-06 21:37:49 +01:00
|
|
|
class A {
|
2018-01-11 21:50:45 +01:00
|
|
|
public static function bar(): int {
|
2017-11-06 21:37:49 +01:00
|
|
|
return 5;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$foo = new A;
|
|
|
|
$b = $foo::bar();',
|
|
|
|
],
|
2017-11-15 03:56:29 +01:00
|
|
|
'uppercasedSelf' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2017-11-15 03:56:29 +01:00
|
|
|
class X33{
|
2018-01-11 21:50:45 +01:00
|
|
|
public static function main(): void {
|
2017-11-15 03:56:29 +01:00
|
|
|
echo SELF::class . "\n"; // Class or interface SELF does not exist
|
|
|
|
}
|
|
|
|
}
|
|
|
|
X33::main();',
|
|
|
|
],
|
2018-01-03 16:35:22 +01:00
|
|
|
'dateTimeImmutableStatic' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2018-01-03 16:35:22 +01:00
|
|
|
final class MyDate extends DateTimeImmutable {}
|
|
|
|
|
|
|
|
$today = new MyDate();
|
2018-01-05 17:50:27 +01:00
|
|
|
$yesterday = $today->sub(new DateInterval("P1D"));
|
|
|
|
|
|
|
|
$b = (new DateTimeImmutable())->modify("+3 hours");',
|
2018-01-03 16:35:22 +01:00
|
|
|
'assertions' => [
|
2022-10-14 01:59:54 +02:00
|
|
|
'$yesterday' => 'MyDate',
|
2023-01-24 11:32:09 +01:00
|
|
|
'$b' => 'DateTimeImmutable',
|
2018-01-03 16:35:22 +01:00
|
|
|
],
|
|
|
|
],
|
2018-01-22 06:17:16 +01:00
|
|
|
'magicCall' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2018-01-22 06:17:16 +01:00
|
|
|
class A {
|
2020-03-11 23:42:41 +01:00
|
|
|
public function __call(string $method_name, array $args) : string {
|
|
|
|
return "hello";
|
|
|
|
}
|
2018-01-22 06:17:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$a = new A;
|
2020-03-11 23:42:41 +01:00
|
|
|
$s = $a->bar();',
|
2022-01-13 19:49:37 +01:00
|
|
|
'assertions' => [
|
2020-03-11 23:42:41 +01:00
|
|
|
'$s' => 'string',
|
2022-12-18 17:15:15 +01:00
|
|
|
],
|
2018-01-22 06:17:16 +01:00
|
|
|
],
|
2018-03-04 19:23:40 +01:00
|
|
|
'canBeCalledOnMagic' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2018-03-04 19:23:40 +01:00
|
|
|
class A {
|
2018-07-17 04:48:53 +02:00
|
|
|
public function __call(string $method, array $args) {}
|
2018-03-04 19:23:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
class B {}
|
|
|
|
|
|
|
|
$a = rand(0, 1) ? new A : new B;
|
|
|
|
|
|
|
|
$a->maybeUndefinedMethod();',
|
|
|
|
'assertions' => [],
|
2022-01-13 19:49:37 +01:00
|
|
|
'ignored_issues' => ['PossiblyUndefinedMethod'],
|
2018-03-04 19:23:40 +01:00
|
|
|
],
|
2018-08-02 23:14:53 +02:00
|
|
|
'canBeCalledOnMagicWithMethod' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2018-08-02 23:14:53 +02:00
|
|
|
class A {
|
|
|
|
public function __call(string $method, array $args) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
class B {
|
|
|
|
public function bar() : void {}
|
|
|
|
}
|
|
|
|
|
|
|
|
$a = rand(0, 1) ? new A : new B;
|
|
|
|
|
|
|
|
$a->bar();',
|
|
|
|
'assertions' => [],
|
|
|
|
],
|
2018-04-01 00:57:13 +02:00
|
|
|
'invokeCorrectType' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2018-04-01 00:57:13 +02:00
|
|
|
class A {
|
|
|
|
public function __invoke(string $p): void {}
|
|
|
|
}
|
|
|
|
|
|
|
|
$q = new A;
|
|
|
|
$q("asda");',
|
|
|
|
],
|
2018-05-12 06:28:21 +02:00
|
|
|
'domDocumentAppendChild' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2018-05-12 06:28:21 +02:00
|
|
|
$doc = new DOMDocument("1.0");
|
|
|
|
$node = $doc->createElement("foo");
|
2019-04-11 17:02:46 +02:00
|
|
|
if ($node instanceof DOMElement) {
|
|
|
|
$newnode = $doc->appendChild($node);
|
|
|
|
$newnode->setAttribute("bar", "baz");
|
|
|
|
}',
|
2018-05-12 06:28:21 +02:00
|
|
|
],
|
2018-06-04 01:11:07 +02:00
|
|
|
'nonStaticSelfCall' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2018-06-04 01:11:07 +02:00
|
|
|
class A11 {
|
|
|
|
public function call() : self {
|
|
|
|
$result = self::method();
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function method() : self {
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$x = new A11();
|
|
|
|
var_export($x->call());',
|
|
|
|
],
|
2018-06-06 05:42:02 +02:00
|
|
|
'simpleXml' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2018-06-06 05:42:02 +02:00
|
|
|
$xml = new SimpleXMLElement("<a><b></b></a>");
|
|
|
|
$a = $xml->asXML();
|
|
|
|
$b = $xml->asXML("foo.xml");',
|
|
|
|
'assertions' => [
|
2019-10-17 07:14:33 +02:00
|
|
|
'$a' => 'false|string',
|
2019-04-11 17:02:46 +02:00
|
|
|
'$b' => 'bool',
|
2018-06-06 05:42:02 +02:00
|
|
|
],
|
|
|
|
],
|
2018-06-18 16:07:05 +02:00
|
|
|
'datetimeformatNotFalse' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2018-06-18 16:07:05 +02:00
|
|
|
$format = random_bytes(10);
|
|
|
|
$dt = new DateTime;
|
|
|
|
$formatted = $dt->format($format);
|
|
|
|
if (false !== $formatted) {}
|
|
|
|
function takesString(string $s) : void {}
|
2019-03-23 19:27:54 +01:00
|
|
|
takesString($formatted);',
|
2021-07-03 07:19:37 +02:00
|
|
|
'assertions' => [],
|
2022-01-13 19:49:37 +01:00
|
|
|
'ignored_issues' => [],
|
2022-12-18 17:15:15 +01:00
|
|
|
'php_version' => '7.4',
|
2018-06-18 16:07:05 +02:00
|
|
|
],
|
2018-07-06 05:02:09 +02:00
|
|
|
'domElement' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2018-07-06 05:02:09 +02:00
|
|
|
function foo(DOMElement $e) : ?string {
|
|
|
|
$a = $e->getElementsByTagName("bar");
|
|
|
|
$b = $a->item(0);
|
|
|
|
if (!$b) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return $b->getAttribute("bat");
|
|
|
|
}',
|
|
|
|
],
|
2019-01-26 22:58:49 +01:00
|
|
|
'domElementIteratorOrEmptyArray' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2022-01-17 23:52:58 +01:00
|
|
|
/** @param non-empty-string $XML */
|
2019-01-26 22:58:49 +01:00
|
|
|
function foo(string $XML) : void {
|
|
|
|
$dom = new DOMDocument();
|
|
|
|
$dom->loadXML($XML);
|
|
|
|
|
|
|
|
$elements = rand(0, 1) ? $dom->getElementsByTagName("bar") : [];
|
|
|
|
foreach ($elements as $element) {
|
|
|
|
$element->getElementsByTagName("bat");
|
|
|
|
}
|
2019-03-23 19:27:54 +01:00
|
|
|
}',
|
2019-01-26 22:58:49 +01:00
|
|
|
],
|
2018-07-17 14:45:42 +02:00
|
|
|
'reflectionParameter' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2018-07-17 14:45:42 +02:00
|
|
|
function getTypeName(ReflectionParameter $parameter): string {
|
|
|
|
$type = $parameter->getType();
|
|
|
|
|
|
|
|
if ($type === null) {
|
|
|
|
return "mixed";
|
|
|
|
}
|
|
|
|
|
2021-01-24 19:31:10 +01:00
|
|
|
if ($type instanceof ReflectionUnionType) {
|
|
|
|
return "union";
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($type instanceof ReflectionNamedType) {
|
|
|
|
return $type->getName();
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new RuntimeException("unexpected type");
|
2019-03-23 19:27:54 +01:00
|
|
|
}',
|
2021-01-24 19:31:10 +01:00
|
|
|
'assertions' => [],
|
2022-01-13 19:49:37 +01:00
|
|
|
'ignored_issues' => [],
|
2022-12-18 17:15:15 +01:00
|
|
|
'php_version' => '8.0',
|
2018-07-17 14:45:42 +02:00
|
|
|
],
|
2018-11-11 02:56:31 +01:00
|
|
|
'PDOMethod' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2018-11-11 02:56:31 +01:00
|
|
|
function md5_and_reverse(string $string) : string {
|
|
|
|
return strrev(md5($string));
|
|
|
|
}
|
|
|
|
|
|
|
|
$db = new PDO("sqlite:sqlitedb");
|
|
|
|
$db->sqliteCreateFunction("md5rev", "md5_and_reverse", 1);',
|
|
|
|
],
|
2018-12-11 00:33:26 +01:00
|
|
|
'dontConvertedMaybeMixedAfterCall' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2018-12-11 00:33:26 +01:00
|
|
|
class B {
|
|
|
|
public function foo() : void {}
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* @param array<B> $b
|
|
|
|
*/
|
|
|
|
function foo(array $a, array $b) : void {
|
|
|
|
$c = array_merge($b, $a);
|
|
|
|
|
|
|
|
foreach ($c as $d) {
|
|
|
|
$d->foo();
|
|
|
|
if ($d instanceof B) {}
|
|
|
|
}
|
|
|
|
}',
|
2022-01-13 19:49:37 +01:00
|
|
|
'assertions' => [],
|
|
|
|
'ignored_issues' => ['MixedAssignment', 'MixedMethodCall'],
|
2018-12-11 00:33:26 +01:00
|
|
|
],
|
2019-01-06 15:36:25 +01:00
|
|
|
'methodResolution' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2019-01-06 15:36:25 +01:00
|
|
|
interface ReturnsString {
|
|
|
|
public function getId(): string;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param mixed $a
|
|
|
|
*/
|
|
|
|
function foo(ReturnsString $user, $a): string {
|
|
|
|
strlen($user->getId());
|
|
|
|
|
2022-11-09 08:49:27 +01:00
|
|
|
(is_object($a) && method_exists($a, "getS")) ? (string)$a->GETS() : "";
|
2019-01-06 15:36:25 +01:00
|
|
|
|
|
|
|
return $user->getId();
|
2019-03-23 19:27:54 +01:00
|
|
|
}',
|
2019-01-06 15:36:25 +01:00
|
|
|
],
|
2019-01-07 18:24:44 +01:00
|
|
|
'defineVariableCreatedInArgToMixed' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2019-01-07 18:24:44 +01:00
|
|
|
function bar($a) : void {
|
2020-11-25 18:04:48 +01:00
|
|
|
if ($a->foo($b = (int) "5")) {
|
2019-01-07 18:24:44 +01:00
|
|
|
echo $b;
|
|
|
|
}
|
|
|
|
}',
|
2022-01-13 19:49:37 +01:00
|
|
|
'assertions' => [],
|
|
|
|
'ignored_issues' => ['MixedMethodCall', 'MissingParamType'],
|
2019-01-07 18:24:44 +01:00
|
|
|
],
|
2019-01-23 21:50:12 +01:00
|
|
|
'staticCallAfterMethodExists' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2019-01-23 21:50:12 +01:00
|
|
|
class A
|
|
|
|
{
|
|
|
|
protected static function existing() : string
|
|
|
|
{
|
|
|
|
return "hello";
|
|
|
|
}
|
|
|
|
|
|
|
|
protected static function foo() : string
|
|
|
|
{
|
|
|
|
if (!method_exists(static::class, "maybeExists")) {
|
|
|
|
return "hello";
|
|
|
|
}
|
|
|
|
|
|
|
|
self::maybeExists();
|
|
|
|
|
|
|
|
return static::existing();
|
|
|
|
}
|
2019-03-23 19:27:54 +01:00
|
|
|
}',
|
2019-01-23 21:50:12 +01:00
|
|
|
],
|
2019-02-01 14:58:52 +01:00
|
|
|
'varSelfCall' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2019-02-01 14:58:52 +01:00
|
|
|
class Foo {
|
|
|
|
/** @var self */
|
|
|
|
public static $current;
|
|
|
|
public function bar() : void {}
|
|
|
|
}
|
|
|
|
|
|
|
|
Foo::$current->bar();',
|
|
|
|
],
|
2019-03-29 18:26:13 +01:00
|
|
|
'pdoStatementSetFetchMode' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2019-03-29 18:26:13 +01:00
|
|
|
class A {
|
|
|
|
/** @var ?string */
|
|
|
|
public $a;
|
|
|
|
}
|
2023-07-27 00:40:26 +02:00
|
|
|
class B extends A {}
|
2019-03-29 18:26:13 +01:00
|
|
|
|
|
|
|
$db = new PDO("sqlite::memory:");
|
|
|
|
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
2023-07-27 15:59:31 +02:00
|
|
|
$db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
|
2019-03-29 18:26:13 +01:00
|
|
|
$stmt = $db->prepare("select \"a\" as a");
|
|
|
|
$stmt->setFetchMode(PDO::FETCH_CLASS, A::class);
|
2023-07-27 15:53:05 +02:00
|
|
|
$stmt2 = $db->prepare("select \"a\" as a");
|
|
|
|
$stmt2->setFetchMode(PDO::FETCH_ASSOC);
|
2023-07-27 15:59:31 +02:00
|
|
|
$stmt3 = $db->prepare("select \"a\" as a");
|
|
|
|
$stmt3->setFetchMode(PDO::ATTR_DEFAULT_FETCH_MODE);
|
2019-03-29 18:26:13 +01:00
|
|
|
$stmt->execute();
|
2023-07-27 15:53:05 +02:00
|
|
|
$stmt2->execute();
|
|
|
|
/** @psalm-suppress MixedAssignment */
|
2023-07-27 00:40:26 +02:00
|
|
|
$a = $stmt->fetch();
|
|
|
|
$b = $stmt->fetchAll();
|
|
|
|
$c = $stmt->fetch(PDO::FETCH_CLASS);
|
|
|
|
$d = $stmt->fetchAll(PDO::FETCH_CLASS);
|
|
|
|
$e = $stmt->fetchAll(PDO::FETCH_CLASS, B::class);
|
|
|
|
$f = $stmt->fetch(PDO::FETCH_ASSOC);
|
2023-07-27 15:53:05 +02:00
|
|
|
$g = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
/** @psalm-suppress MixedAssignment */
|
|
|
|
$h = $stmt2->fetch();
|
|
|
|
$i = $stmt2->fetchAll();
|
|
|
|
$j = $stmt2->fetch(PDO::FETCH_BOTH);
|
2023-07-27 15:59:31 +02:00
|
|
|
$k = $stmt2->fetchAll(PDO::FETCH_BOTH);
|
|
|
|
/** @psalm-suppress MixedAssignment */
|
|
|
|
$l = $stmt3->fetch();',
|
2023-07-27 00:40:26 +02:00
|
|
|
'assertions' => [
|
2023-07-27 15:53:05 +02:00
|
|
|
'$a' => 'mixed',
|
|
|
|
'$b' => 'array<array-key, mixed>|false',
|
|
|
|
'$c' => 'false|object',
|
|
|
|
'$d' => 'list<object>',
|
2023-07-27 00:40:26 +02:00
|
|
|
'$e' => 'list<B>',
|
|
|
|
'$f' => 'array<string, null|scalar>|false',
|
|
|
|
'$g' => 'list<array<string, null|scalar>>',
|
2023-07-27 15:53:05 +02:00
|
|
|
'$h' => 'mixed',
|
|
|
|
'$i' => 'array<array-key, mixed>|false',
|
|
|
|
'$j' => 'array<array-key, null|scalar>|false',
|
|
|
|
'$k' => 'list<array<array-key, null|scalar>>',
|
2023-07-27 15:59:31 +02:00
|
|
|
'$l' => 'mixed',
|
2023-07-27 00:40:26 +02:00
|
|
|
],
|
2019-03-29 18:26:13 +01:00
|
|
|
],
|
|
|
|
'datePeriodConstructor' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2019-03-29 18:26:13 +01:00
|
|
|
function foo(DateTime $d1, DateTime $d2) : void {
|
|
|
|
new DatePeriod(
|
|
|
|
$d1,
|
|
|
|
DateInterval::createFromDateString("1 month"),
|
|
|
|
$d2
|
|
|
|
);
|
2019-07-05 22:24:00 +02:00
|
|
|
}',
|
2019-03-29 18:26:13 +01:00
|
|
|
],
|
2019-08-19 04:27:19 +02:00
|
|
|
'callMethodAfterCheckingExistence' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2019-08-19 04:27:19 +02:00
|
|
|
class A {}
|
|
|
|
|
|
|
|
function foo(A $a) : void {
|
|
|
|
if (method_exists($a, "bar")) {
|
|
|
|
/** @psalm-suppress MixedArgument */
|
|
|
|
echo $a->bar();
|
|
|
|
}
|
2022-12-18 17:15:15 +01:00
|
|
|
}',
|
2019-08-19 04:27:19 +02:00
|
|
|
],
|
|
|
|
'callMethodAfterCheckingExistenceInClosure' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2019-08-19 04:27:19 +02:00
|
|
|
class A {}
|
|
|
|
|
|
|
|
function foo(A $a) : void {
|
|
|
|
if (method_exists($a, "bar")) {
|
|
|
|
(function() use ($a) : void {
|
|
|
|
/** @psalm-suppress MixedArgument */
|
|
|
|
echo $a->bar();
|
|
|
|
})();
|
|
|
|
|
|
|
|
}
|
2022-12-18 17:15:15 +01:00
|
|
|
}',
|
2019-08-19 04:27:19 +02:00
|
|
|
],
|
2019-08-19 16:08:21 +02:00
|
|
|
'callManyMethodsAfterCheckingExistence' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2019-08-19 16:08:21 +02:00
|
|
|
function foo(object $object) : void {
|
|
|
|
if (!method_exists($object, "foo")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!method_exists($object, "bar")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$object->foo();
|
|
|
|
$object->bar();
|
2022-12-18 17:15:15 +01:00
|
|
|
}',
|
2019-08-19 16:08:21 +02:00
|
|
|
],
|
2019-08-20 06:00:20 +02:00
|
|
|
'callManyMethodsAfterCheckingExistenceChained' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2019-08-20 06:00:20 +02:00
|
|
|
function foo(object $object) : void {
|
|
|
|
if (method_exists($object, "foo") && method_exists($object, "bar")) {
|
|
|
|
$object->foo();
|
2019-08-20 06:33:59 +02:00
|
|
|
$object->bar();
|
|
|
|
}
|
2022-12-18 17:15:15 +01:00
|
|
|
}',
|
2019-08-20 06:33:59 +02:00
|
|
|
],
|
|
|
|
'callManyMethodsOnKnownObjectAfterCheckingExistenceChained' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2019-08-20 06:33:59 +02:00
|
|
|
class A {}
|
|
|
|
function foo(A $object) : void {
|
|
|
|
if (method_exists($object, "foo") && method_exists($object, "bar")) {
|
|
|
|
$object->foo();
|
2019-08-20 06:00:20 +02:00
|
|
|
$object->bar();
|
|
|
|
}
|
2022-12-18 17:15:15 +01:00
|
|
|
}',
|
2019-08-20 06:00:20 +02:00
|
|
|
],
|
2019-08-29 20:27:25 +02:00
|
|
|
'preserveMethodExistsType' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2019-08-29 20:27:25 +02:00
|
|
|
/**
|
|
|
|
* @param class-string $foo
|
|
|
|
*/
|
|
|
|
function foo(string $foo): string {
|
|
|
|
if (!method_exists($foo, "something")) {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
return $foo;
|
2022-12-18 17:15:15 +01:00
|
|
|
}',
|
2019-08-29 20:27:25 +02:00
|
|
|
],
|
|
|
|
'methodDoesNotExistOnClass' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2019-08-29 20:27:25 +02:00
|
|
|
class A {}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param class-string<A> $foo
|
|
|
|
*/
|
|
|
|
function foo(string $foo): string {
|
|
|
|
if (!method_exists($foo, "something")) {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
return $foo;
|
2022-12-18 17:15:15 +01:00
|
|
|
}',
|
2019-08-29 20:27:25 +02:00
|
|
|
],
|
2023-07-27 01:39:21 +02:00
|
|
|
'pdoStatementFetchColumn' => [
|
|
|
|
'code' => '<?php
|
|
|
|
/** @return scalar|null|false */
|
|
|
|
function fetch_column() {
|
|
|
|
$p = new PDO("sqlite::memory:");
|
|
|
|
$sth = $p->prepare("SELECT 1");
|
|
|
|
$sth->execute();
|
|
|
|
return $sth->fetch(PDO::FETCH_COLUMN);
|
|
|
|
}',
|
|
|
|
],
|
|
|
|
'pdoStatementFetchAllColumn' => [
|
|
|
|
'code' => '<?php
|
|
|
|
/** @return list<scalar|null> */
|
|
|
|
function fetch_column() {
|
|
|
|
$p = new PDO("sqlite::memory:");
|
|
|
|
$sth = $p->prepare("SELECT 1");
|
|
|
|
$sth->execute();
|
|
|
|
return $sth->fetchAll(PDO::FETCH_COLUMN);
|
|
|
|
}',
|
|
|
|
],
|
|
|
|
'pdoStatementFetchKeyPair' => [
|
|
|
|
'code' => '<?php
|
|
|
|
/** @return array<array-key,scalar|null> */
|
|
|
|
function fetch_column() {
|
|
|
|
$p = new PDO("sqlite::memory:");
|
|
|
|
$sth = $p->prepare("SELECT 1");
|
|
|
|
$sth->execute();
|
|
|
|
return $sth->fetch(PDO::FETCH_KEY_PAIR);
|
|
|
|
}',
|
|
|
|
],
|
|
|
|
'pdoStatementFetchAllKeyPair' => [
|
|
|
|
'code' => '<?php
|
|
|
|
/** @return array<array-key,scalar|null> */
|
|
|
|
function fetch_column() {
|
|
|
|
$p = new PDO("sqlite::memory:");
|
|
|
|
$sth = $p->prepare("SELECT 1");
|
|
|
|
$sth->execute();
|
|
|
|
return $sth->fetchAll(PDO::FETCH_KEY_PAIR);
|
|
|
|
}',
|
|
|
|
],
|
2019-12-30 17:34:24 +01:00
|
|
|
'pdoStatementFetchAssoc' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2020-11-24 00:41:12 +01:00
|
|
|
/** @return array<string,null|scalar>|false */
|
2020-01-17 14:48:08 +01:00
|
|
|
function fetch_assoc() {
|
2020-01-06 22:41:52 +01:00
|
|
|
$p = new PDO("sqlite::memory:");
|
|
|
|
$sth = $p->prepare("SELECT 1");
|
|
|
|
$sth->execute();
|
|
|
|
return $sth->fetch(PDO::FETCH_ASSOC);
|
2022-12-18 17:15:15 +01:00
|
|
|
}',
|
2020-01-06 22:41:52 +01:00
|
|
|
],
|
2023-07-27 00:40:26 +02:00
|
|
|
'pdoStatementFetchAllAssoc' => [
|
|
|
|
'code' => '<?php
|
|
|
|
/** @return list<array<string,null|scalar>> */
|
|
|
|
function fetch_assoc() : array {
|
|
|
|
$p = new PDO("sqlite::memory:");
|
|
|
|
$sth = $p->prepare("SELECT 1");
|
|
|
|
$sth->execute();
|
|
|
|
return $sth->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
}',
|
|
|
|
],
|
2020-01-06 22:41:52 +01:00
|
|
|
'pdoStatementFetchBoth' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2020-11-24 00:41:12 +01:00
|
|
|
/** @return array<null|scalar>|false */
|
2020-01-17 14:48:08 +01:00
|
|
|
function fetch_both() {
|
2020-01-06 22:41:52 +01:00
|
|
|
$p = new PDO("sqlite::memory:");
|
|
|
|
$sth = $p->prepare("SELECT 1");
|
|
|
|
$sth->execute();
|
|
|
|
return $sth->fetch(PDO::FETCH_BOTH);
|
2022-12-18 17:15:15 +01:00
|
|
|
}',
|
2020-01-06 22:41:52 +01:00
|
|
|
],
|
2023-07-27 00:40:26 +02:00
|
|
|
'pdoStatementFetchAllBoth' => [
|
|
|
|
'code' => '<?php
|
|
|
|
/** @return list<array<null|scalar>> */
|
|
|
|
function fetch_both() : array {
|
|
|
|
$p = new PDO("sqlite::memory:");
|
|
|
|
$sth = $p->prepare("SELECT 1");
|
|
|
|
$sth->execute();
|
|
|
|
return $sth->fetchAll(PDO::FETCH_BOTH);
|
|
|
|
}',
|
|
|
|
],
|
2020-01-06 22:41:52 +01:00
|
|
|
'pdoStatementFetchBound' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2020-01-17 14:48:08 +01:00
|
|
|
/** @return bool */
|
2020-01-06 22:41:52 +01:00
|
|
|
function fetch_both() : bool {
|
|
|
|
$p = new PDO("sqlite::memory:");
|
|
|
|
$sth = $p->prepare("SELECT 1");
|
|
|
|
$sth->execute();
|
|
|
|
return $sth->fetch(PDO::FETCH_BOUND);
|
2022-12-18 17:15:15 +01:00
|
|
|
}',
|
2020-01-06 22:41:52 +01:00
|
|
|
],
|
2023-07-27 00:40:26 +02:00
|
|
|
'pdoStatementFetchAllBound' => [
|
|
|
|
'code' => '<?php
|
|
|
|
/** @return list<bool> */
|
|
|
|
function fetch_both() : array {
|
|
|
|
$p = new PDO("sqlite::memory:");
|
|
|
|
$sth = $p->prepare("SELECT 1");
|
|
|
|
$sth->execute();
|
|
|
|
return $sth->fetchAll(PDO::FETCH_BOUND);
|
|
|
|
}',
|
|
|
|
],
|
2020-01-06 22:41:52 +01:00
|
|
|
'pdoStatementFetchClass' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2020-01-17 14:48:08 +01:00
|
|
|
/** @return object|false */
|
|
|
|
function fetch_class() {
|
2020-01-06 22:41:52 +01:00
|
|
|
$p = new PDO("sqlite::memory:");
|
|
|
|
$sth = $p->prepare("SELECT 1");
|
|
|
|
$sth->execute();
|
|
|
|
return $sth->fetch(PDO::FETCH_CLASS);
|
2022-12-18 17:15:15 +01:00
|
|
|
}',
|
2020-01-06 22:41:52 +01:00
|
|
|
],
|
2023-07-27 00:40:26 +02:00
|
|
|
'pdoStatementFetchAllClass' => [
|
|
|
|
'code' => '<?php
|
|
|
|
/** @return list<object> */
|
|
|
|
function fetch_class() : array {
|
|
|
|
$p = new PDO("sqlite::memory:");
|
|
|
|
$sth = $p->prepare("SELECT 1");
|
|
|
|
$sth->execute();
|
|
|
|
return $sth->fetchAll(PDO::FETCH_CLASS);
|
|
|
|
}',
|
|
|
|
],
|
|
|
|
'pdoStatementFetchAllNamedClass' => [
|
|
|
|
'code' => '<?php
|
|
|
|
class Foo {}
|
|
|
|
|
|
|
|
/** @return list<Foo> */
|
|
|
|
function fetch_class() : array {
|
|
|
|
$p = new PDO("sqlite::memory:");
|
|
|
|
$sth = $p->prepare("SELECT 1");
|
|
|
|
$sth->execute();
|
|
|
|
return $sth->fetchAll(PDO::FETCH_CLASS, Foo::class);
|
|
|
|
}',
|
|
|
|
],
|
2020-01-06 22:41:52 +01:00
|
|
|
'pdoStatementFetchLazy' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2020-01-17 14:48:08 +01:00
|
|
|
/** @return object|false */
|
|
|
|
function fetch_lazy() {
|
2020-01-06 22:41:52 +01:00
|
|
|
$p = new PDO("sqlite::memory:");
|
|
|
|
$sth = $p->prepare("SELECT 1");
|
|
|
|
$sth->execute();
|
|
|
|
return $sth->fetch(PDO::FETCH_LAZY);
|
2022-12-18 17:15:15 +01:00
|
|
|
}',
|
2020-01-06 22:41:52 +01:00
|
|
|
],
|
|
|
|
'pdoStatementFetchNamed' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2023-07-27 01:39:21 +02:00
|
|
|
/** @return array<string,scalar|null|list<scalar|null>>|false */
|
2020-01-17 14:48:08 +01:00
|
|
|
function fetch_named() {
|
2020-01-06 22:41:52 +01:00
|
|
|
$p = new PDO("sqlite::memory:");
|
|
|
|
$sth = $p->prepare("SELECT 1");
|
|
|
|
$sth->execute();
|
|
|
|
return $sth->fetch(PDO::FETCH_NAMED);
|
2022-12-18 17:15:15 +01:00
|
|
|
}',
|
2020-01-06 22:41:52 +01:00
|
|
|
],
|
2023-07-27 00:40:26 +02:00
|
|
|
'pdoStatementFetchAllNamed' => [
|
|
|
|
'code' => '<?php
|
2023-07-27 01:39:21 +02:00
|
|
|
/** @return list<array<string,scalar|null|list<scalar|null>>> */
|
2023-07-27 00:40:26 +02:00
|
|
|
function fetch_named() : array {
|
|
|
|
$p = new PDO("sqlite::memory:");
|
|
|
|
$sth = $p->prepare("SELECT 1");
|
|
|
|
$sth->execute();
|
|
|
|
return $sth->fetchAll(PDO::FETCH_NAMED);
|
|
|
|
}',
|
|
|
|
],
|
2020-01-06 22:41:52 +01:00
|
|
|
'pdoStatementFetchNum' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2020-11-24 00:41:12 +01:00
|
|
|
/** @return list<null|scalar>|false */
|
2020-01-17 14:48:08 +01:00
|
|
|
function fetch_named() {
|
2020-01-06 22:41:52 +01:00
|
|
|
$p = new PDO("sqlite::memory:");
|
|
|
|
$sth = $p->prepare("SELECT 1");
|
|
|
|
$sth->execute();
|
|
|
|
return $sth->fetch(PDO::FETCH_NUM);
|
2022-12-18 17:15:15 +01:00
|
|
|
}',
|
2020-01-06 22:41:52 +01:00
|
|
|
],
|
2023-07-27 00:40:26 +02:00
|
|
|
'pdoStatementFetchAllNum' => [
|
|
|
|
'code' => '<?php
|
|
|
|
/** @return list<list<null|scalar>> */
|
|
|
|
function fetch_named() : array {
|
|
|
|
$p = new PDO("sqlite::memory:");
|
|
|
|
$sth = $p->prepare("SELECT 1");
|
|
|
|
$sth->execute();
|
|
|
|
return $sth->fetchAll(PDO::FETCH_NUM);
|
|
|
|
}',
|
|
|
|
],
|
2020-01-06 22:41:52 +01:00
|
|
|
'pdoStatementFetchObj' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2020-01-17 14:48:08 +01:00
|
|
|
/** @return stdClass|false */
|
|
|
|
function fetch_named() {
|
2020-01-06 22:41:52 +01:00
|
|
|
$p = new PDO("sqlite::memory:");
|
|
|
|
$sth = $p->prepare("SELECT 1");
|
|
|
|
$sth->execute();
|
|
|
|
return $sth->fetch(PDO::FETCH_OBJ);
|
2022-12-18 17:15:15 +01:00
|
|
|
}',
|
2019-12-30 17:34:24 +01:00
|
|
|
],
|
2023-07-27 00:40:26 +02:00
|
|
|
'pdoStatementFetchAllObj' => [
|
|
|
|
'code' => '<?php
|
|
|
|
/** @return list<stdClass> */
|
|
|
|
function fetch_named() : array {
|
|
|
|
$p = new PDO("sqlite::memory:");
|
|
|
|
$sth = $p->prepare("SELECT 1");
|
|
|
|
$sth->execute();
|
|
|
|
return $sth->fetchAll(PDO::FETCH_OBJ);
|
|
|
|
}',
|
|
|
|
],
|
2020-01-10 21:53:15 +01:00
|
|
|
'dateTimeSecondArg' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2020-01-10 21:53:15 +01:00
|
|
|
$date = new DateTime(null, new DateTimeZone("Pacific/Nauru"));
|
2022-12-18 17:15:15 +01:00
|
|
|
echo $date->format("Y-m-d H:i:sP") . "\n";',
|
2020-01-10 21:53:15 +01:00
|
|
|
],
|
2020-02-27 14:59:43 +01:00
|
|
|
'noCrashOnGetClassMethodCallWithNull' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2020-02-27 14:59:43 +01:00
|
|
|
class User {
|
|
|
|
/**
|
|
|
|
* @psalm-suppress NullArgument
|
|
|
|
*/
|
|
|
|
public function give(): void{
|
|
|
|
$model = null;
|
|
|
|
$class = \get_class($model);
|
|
|
|
$class::foo();
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
],
|
2020-03-06 05:40:47 +01:00
|
|
|
'unknownMethodCallWithProperty' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2020-03-06 05:40:47 +01:00
|
|
|
class A {
|
|
|
|
private string $b = "c";
|
|
|
|
|
|
|
|
public function passesByRef(object $a): void {
|
|
|
|
/** @psalm-suppress MixedMethodCall */
|
|
|
|
$a->passedByRef($this->b);
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
],
|
2020-03-15 18:44:00 +01:00
|
|
|
'maybeNotTooManyArgumentsToInstance' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2020-03-15 18:44:00 +01:00
|
|
|
class A {
|
|
|
|
public function fooFoo(int $a): void {}
|
|
|
|
}
|
|
|
|
|
|
|
|
class B {
|
|
|
|
public function fooFoo(int $a, string $s): void {}
|
|
|
|
}
|
|
|
|
|
|
|
|
(rand(0, 1) ? new A : new B)->fooFoo(5, "dfd");',
|
|
|
|
],
|
2020-03-15 19:01:33 +01:00
|
|
|
'interfaceMethodCallCheck' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2020-03-15 19:01:33 +01:00
|
|
|
interface A {
|
|
|
|
function foo() : void;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface B extends A {
|
|
|
|
function foo(string $a = "") : void;
|
|
|
|
}
|
|
|
|
|
|
|
|
class C implements B {
|
|
|
|
public function foo(string $a = "") : void {}
|
|
|
|
}
|
|
|
|
|
|
|
|
function takesWithoutArguments(A $a) : void {
|
|
|
|
if ($a instanceof B) {
|
|
|
|
$a->foo("");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-18 17:15:15 +01:00
|
|
|
takesWithoutArguments(new C);',
|
2020-03-15 19:01:33 +01:00
|
|
|
],
|
2020-04-12 14:40:24 +02:00
|
|
|
'getterAutomagicAssertion' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2020-04-12 14:40:24 +02:00
|
|
|
class A {
|
|
|
|
/** @var string|null */
|
|
|
|
public $a;
|
2020-04-12 20:13:42 +02:00
|
|
|
|
2020-04-12 14:40:24 +02:00
|
|
|
/** @return string|null */
|
2020-07-16 17:58:27 +02:00
|
|
|
final public function getA() {
|
2020-04-12 20:13:42 +02:00
|
|
|
return $this->a;
|
2020-04-12 14:40:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$a = new A();
|
2020-04-12 20:13:42 +02:00
|
|
|
|
2020-04-12 14:40:24 +02:00
|
|
|
if ($a->getA()) {
|
|
|
|
echo strlen($a->getA());
|
2022-12-18 17:15:15 +01:00
|
|
|
}',
|
2020-04-12 20:13:42 +02:00
|
|
|
],
|
|
|
|
'ignorePossiblyNull' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2020-04-12 20:13:42 +02:00
|
|
|
class Foo {
|
|
|
|
protected ?string $type = null;
|
|
|
|
|
|
|
|
public function prepend(array $arr) : string {
|
|
|
|
return $this->getType();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @psalm-ignore-nullable-return
|
|
|
|
*/
|
|
|
|
public function getType() : ?string
|
|
|
|
{
|
|
|
|
return $this->type;
|
|
|
|
}
|
2022-12-18 17:15:15 +01:00
|
|
|
}',
|
2020-04-12 14:40:24 +02:00
|
|
|
],
|
2020-05-03 03:57:53 +02:00
|
|
|
'abstractMethodExistsOnChild' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2020-05-03 03:57:53 +02:00
|
|
|
abstract class Foo {}
|
|
|
|
|
|
|
|
abstract class FooChild extends Foo {}
|
|
|
|
|
|
|
|
abstract class AbstractTestCase {
|
|
|
|
abstract public function createFoo(): Foo;
|
|
|
|
}
|
|
|
|
|
|
|
|
abstract class AbstractChildTestCase extends AbstractTestCase {
|
|
|
|
abstract public function createFoo(): FooChild;
|
|
|
|
|
|
|
|
public function testFoo(): FooChild {
|
|
|
|
return $this->createFoo();
|
|
|
|
}
|
|
|
|
}',
|
2022-01-13 19:49:37 +01:00
|
|
|
'assertions' => [],
|
|
|
|
'ignored_issues' => [],
|
2022-12-18 17:15:15 +01:00
|
|
|
'php_version' => '7.4',
|
2020-05-03 03:57:53 +02:00
|
|
|
],
|
2020-06-27 00:26:06 +02:00
|
|
|
'pdoQueryTwoArgs' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2020-06-27 00:26:06 +02:00
|
|
|
$pdo = new PDO("test");
|
2022-12-18 17:15:15 +01:00
|
|
|
$pdo->query("SELECT * FROM projects", PDO::FETCH_NAMED);',
|
2020-06-27 00:26:06 +02:00
|
|
|
],
|
2020-07-16 17:58:27 +02:00
|
|
|
'unchainedInferredMutationFreeMethodCallMemoize' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2020-07-16 17:58:27 +02:00
|
|
|
class SomeClass {
|
|
|
|
private ?int $int;
|
|
|
|
|
|
|
|
public function __construct() {
|
|
|
|
$this->int = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @psalm-mutation-free
|
|
|
|
*/
|
|
|
|
public function getInt(): ?int {
|
|
|
|
return $this->int;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function printInt(int $int): void {
|
|
|
|
echo $int;
|
|
|
|
}
|
|
|
|
|
|
|
|
$obj = new SomeClass();
|
|
|
|
|
|
|
|
if ($obj->getInt()) {
|
|
|
|
printInt($obj->getInt());
|
|
|
|
}',
|
|
|
|
],
|
|
|
|
'unchainedInferredInferredFinalMutationFreeMethodCallMemoize' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2020-07-16 17:58:27 +02:00
|
|
|
class SomeClass {
|
|
|
|
private ?int $int;
|
|
|
|
|
|
|
|
public function __construct() {
|
|
|
|
$this->int = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
final public function getInt(): ?int {
|
|
|
|
return $this->int;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function printInt(int $int): void {
|
|
|
|
echo $int;
|
|
|
|
}
|
|
|
|
|
|
|
|
$obj = new SomeClass();
|
|
|
|
|
|
|
|
if ($obj->getInt()) {
|
|
|
|
printInt($obj->getInt());
|
|
|
|
}',
|
|
|
|
],
|
2020-12-12 16:26:14 +01:00
|
|
|
'privateInferredMutationFreeMethodCallMemoize' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2020-12-12 16:26:14 +01:00
|
|
|
class PropertyClass {
|
|
|
|
public function test() : void {
|
|
|
|
echo "test";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
class SomeClass {
|
|
|
|
private ?PropertyClass $property = null;
|
|
|
|
|
|
|
|
private function getProperty(): ?PropertyClass {
|
|
|
|
return $this->property;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function test(int $int): void {
|
|
|
|
if ($this->getProperty() !== null) {
|
|
|
|
$this->getProperty()->test();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
],
|
2020-07-16 18:42:59 +02:00
|
|
|
'inferredFinalMethod' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2020-07-16 18:42:59 +02:00
|
|
|
class PropertyClass {
|
|
|
|
public function test() : bool {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class MainClass {
|
|
|
|
private ?PropertyClass $property = null;
|
|
|
|
|
|
|
|
final public function getProperty(): ?PropertyClass {
|
|
|
|
return $this->property;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$main = new MainClass();
|
|
|
|
|
2022-12-18 17:15:15 +01:00
|
|
|
if ($main->getProperty() !== null && $main->getProperty()->test()) {}',
|
2020-07-16 18:42:59 +02:00
|
|
|
],
|
2020-07-16 18:59:49 +02:00
|
|
|
'getterTypeInferring' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2020-07-16 18:59:49 +02:00
|
|
|
class A {
|
|
|
|
/** @var int|string|null */
|
|
|
|
public $a;
|
|
|
|
|
|
|
|
/** @return int|string|null */
|
|
|
|
final public function getValue() {
|
|
|
|
return $this->a;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$a = new A();
|
|
|
|
|
|
|
|
if (is_string($a->getValue())) {
|
|
|
|
echo strlen($a->getValue());
|
|
|
|
}',
|
|
|
|
],
|
2020-08-25 17:52:21 +02:00
|
|
|
'newSplObjectStorageDefaultEmpty' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2020-08-25 17:52:21 +02:00
|
|
|
$a = new SplObjectStorage();',
|
2022-01-13 19:49:37 +01:00
|
|
|
'assertions' => [
|
2021-10-13 19:37:47 +02:00
|
|
|
'$a' => 'SplObjectStorage<never, never>',
|
2022-12-18 17:15:15 +01:00
|
|
|
],
|
2020-08-25 17:52:21 +02:00
|
|
|
],
|
2020-09-07 17:40:36 +02:00
|
|
|
'allowIteratorToBeNull' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2020-09-07 17:40:36 +02:00
|
|
|
/**
|
|
|
|
* @return Iterator<string>
|
|
|
|
*/
|
|
|
|
function buildIterator(int $size): Iterator {
|
|
|
|
|
|
|
|
$values = [];
|
|
|
|
for ($i = 0; $i < $size; $i++) {
|
|
|
|
$values[] = "Item $i\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
return new ArrayIterator($values);
|
|
|
|
}
|
|
|
|
|
|
|
|
$it = buildIterator(2);
|
|
|
|
|
2022-12-18 17:15:15 +01:00
|
|
|
if ($it->current() === null) {}',
|
2020-09-07 17:40:36 +02:00
|
|
|
],
|
2021-04-06 18:35:02 +02:00
|
|
|
'resolveFinalInParentCall' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2021-04-06 18:35:02 +02:00
|
|
|
abstract class A {
|
|
|
|
protected static function create() : static {
|
|
|
|
return new static();
|
|
|
|
}
|
|
|
|
|
|
|
|
final private function __construct() {}
|
|
|
|
}
|
|
|
|
|
|
|
|
final class B extends A {
|
|
|
|
public static function new() : self {
|
|
|
|
return parent::create();
|
|
|
|
}
|
2022-12-18 17:15:15 +01:00
|
|
|
}',
|
2021-04-06 18:35:02 +02:00
|
|
|
],
|
2021-05-13 18:40:39 +02:00
|
|
|
'noCrashWhenCallingParent' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2021-05-13 18:40:39 +02:00
|
|
|
namespace FooBar;
|
|
|
|
|
|
|
|
class Datetime extends \DateTime
|
|
|
|
{
|
2022-10-16 14:23:31 +02:00
|
|
|
public static function createFromInterface(\DateTimeInterface $datetime): static
|
2021-05-13 18:40:39 +02:00
|
|
|
{
|
|
|
|
return parent::createFromInterface($datetime);
|
|
|
|
}
|
|
|
|
}',
|
2022-01-13 19:49:37 +01:00
|
|
|
'assertions' => [],
|
|
|
|
'ignored_issues' => ['MixedReturnStatement', 'MixedInferredReturnType'],
|
2022-12-18 17:15:15 +01:00
|
|
|
'php_version' => '8.0',
|
2021-06-01 22:06:12 +02:00
|
|
|
],
|
|
|
|
'nullsafeShortCircuit' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2021-06-01 22:06:12 +02:00
|
|
|
interface Bar {
|
|
|
|
public function doBaz(): void;
|
|
|
|
}
|
|
|
|
interface Foo {
|
|
|
|
public function getBar(): Bar;
|
|
|
|
}
|
|
|
|
function fooOrNull(): ?Foo {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
fooOrNull()?->getBar()->doBaz();',
|
2022-01-13 19:49:37 +01:00
|
|
|
'assertions' => [],
|
|
|
|
'ignored_issues' => [],
|
2022-12-18 17:15:15 +01:00
|
|
|
'php_version' => '8.0',
|
2021-06-01 22:06:12 +02:00
|
|
|
],
|
2022-01-18 09:34:05 +01:00
|
|
|
'parentMagicMethodCall' => [
|
2022-01-26 21:06:25 +01:00
|
|
|
'code' => '<?php
|
2022-01-18 09:34:05 +01:00
|
|
|
class Model {
|
|
|
|
/**
|
|
|
|
* @return static
|
|
|
|
*/
|
2022-01-24 09:17:29 +01:00
|
|
|
public function __call(string $method, array $args) {
|
2022-01-18 09:34:05 +01:00
|
|
|
/** @psalm-suppress UnsafeInstantiation */
|
|
|
|
return new static;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class BlahModel extends Model {
|
|
|
|
/**
|
|
|
|
* @param mixed $input
|
|
|
|
*/
|
|
|
|
public function create($input): BlahModel
|
|
|
|
{
|
|
|
|
return parent::create([]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$m = new BlahModel();
|
|
|
|
$n = $m->create([]);',
|
2022-01-26 21:06:25 +01:00
|
|
|
'assertions' => [
|
2022-01-18 09:34:05 +01:00
|
|
|
'$n' => 'BlahModel',
|
2022-12-18 17:15:15 +01:00
|
|
|
],
|
2022-01-18 09:34:05 +01:00
|
|
|
],
|
2023-06-01 16:35:32 +02:00
|
|
|
'methodLevelGenericsWillBeInherited' => [
|
|
|
|
'code' => '<?php
|
|
|
|
interface I
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @template TResult
|
|
|
|
* @param TResult $value
|
|
|
|
* @return TResult
|
|
|
|
*/
|
|
|
|
public function method(mixed $value): mixed;
|
|
|
|
}
|
|
|
|
final class A implements I
|
|
|
|
{
|
|
|
|
public function method(mixed $value): mixed
|
|
|
|
{
|
|
|
|
return $value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$_v = (new A)->method("a");
|
|
|
|
/** @psalm-check-type-exact $_v = "a" */',
|
|
|
|
'assertions' => [],
|
|
|
|
'ignored_issues' => [],
|
|
|
|
'php_version' => '8.0',
|
|
|
|
],
|
2023-08-12 12:28:23 +02:00
|
|
|
'phpdocObjectTypeAndReferenceInParameter' => [
|
|
|
|
'code' => '<?php
|
|
|
|
class Foo {
|
|
|
|
/**
|
|
|
|
* @param object $object
|
|
|
|
*/
|
|
|
|
public function bar(&$object): void {}
|
|
|
|
}
|
|
|
|
$x = new Foo();
|
|
|
|
$x->bar($x);',
|
|
|
|
],
|
2017-04-25 05:45:02 +02:00
|
|
|
];
|
2016-12-17 04:16:29 +01:00
|
|
|
}
|
2017-02-12 06:50:37 +01:00
|
|
|
|
2020-09-12 17:24:05 +02:00
|
|
|
public function providerInvalidCodeParse(): iterable
|
2017-02-12 06:50:37 +01:00
|
|
|
{
|
2017-04-25 05:45:02 +02:00
|
|
|
return [
|
|
|
|
'staticInvocation' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2017-04-25 05:45:02 +02:00
|
|
|
class Foo {
|
2018-01-11 21:50:45 +01:00
|
|
|
public function barBar(): void {}
|
2017-04-25 05:45:02 +02:00
|
|
|
}
|
2017-07-09 20:36:06 +02:00
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
Foo::barBar();',
|
2017-05-27 02:05:57 +02:00
|
|
|
'error_message' => 'InvalidStaticInvocation',
|
2017-04-25 05:45:02 +02:00
|
|
|
],
|
|
|
|
'parentStaticCall' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2017-04-25 05:45:02 +02:00
|
|
|
class A {
|
|
|
|
/** @return void */
|
|
|
|
public function foo(){}
|
|
|
|
}
|
2017-07-09 20:36:06 +02:00
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
class B extends A {
|
|
|
|
/** @return void */
|
|
|
|
public static function bar(){
|
|
|
|
parent::foo();
|
|
|
|
}
|
|
|
|
}',
|
2017-05-27 02:05:57 +02:00
|
|
|
'error_message' => 'InvalidStaticInvocation',
|
2017-04-25 05:45:02 +02:00
|
|
|
],
|
|
|
|
'mixedMethodCall' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2017-04-25 05:45:02 +02:00
|
|
|
class Foo {
|
2018-01-11 21:50:45 +01:00
|
|
|
public static function barBar(): void {}
|
2017-04-25 05:45:02 +02:00
|
|
|
}
|
2017-07-09 20:36:06 +02:00
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
/** @var mixed */
|
|
|
|
$a = (new Foo());
|
2017-07-09 20:36:06 +02:00
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
$a->barBar();',
|
|
|
|
'error_message' => 'MixedMethodCall',
|
2022-01-13 19:49:37 +01:00
|
|
|
'ignored_issues' => [
|
2017-04-25 05:45:02 +02:00
|
|
|
'MissingPropertyType',
|
2017-05-27 02:05:57 +02:00
|
|
|
'MixedAssignment',
|
|
|
|
],
|
2017-04-25 05:45:02 +02:00
|
|
|
],
|
2017-11-15 17:34:40 +01:00
|
|
|
'invalidMethodCall' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2017-11-15 17:34:40 +01:00
|
|
|
("hello")->someMethod();',
|
|
|
|
'error_message' => 'InvalidMethodCall',
|
|
|
|
],
|
|
|
|
'possiblyInvalidMethodCall' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2017-11-15 17:34:40 +01:00
|
|
|
class A1 {
|
|
|
|
public function methodOfA(): void {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @param A1|string $x */
|
2018-05-05 23:30:18 +02:00
|
|
|
function example($x, bool $isObject) : void {
|
2017-11-15 17:34:40 +01:00
|
|
|
if ($isObject) {
|
|
|
|
$x->methodOfA();
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
'error_message' => 'PossiblyInvalidMethodCall',
|
|
|
|
],
|
2017-04-25 05:45:02 +02:00
|
|
|
'selfNonStaticInvocation' => [
|
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(): void {}
|
2017-07-09 20:36:06 +02:00
|
|
|
|
2018-06-04 01:11:07 +02:00
|
|
|
public static function barBar(): void {
|
2017-04-25 05:45:02 +02:00
|
|
|
self::fooFoo();
|
|
|
|
}
|
|
|
|
}',
|
2017-05-27 02:05:57 +02:00
|
|
|
'error_message' => 'NonStaticSelfCall',
|
2017-04-25 05:45:02 +02:00
|
|
|
],
|
|
|
|
'noParent' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2017-04-25 05:45:02 +02:00
|
|
|
class Foo {
|
2018-01-11 21:50:45 +01:00
|
|
|
public function barBar(): void {
|
2017-04-25 05:45:02 +02:00
|
|
|
parent::barBar();
|
|
|
|
}
|
|
|
|
}',
|
2017-05-27 02:05:57 +02:00
|
|
|
'error_message' => 'ParentNotFound',
|
2017-04-25 05:45:02 +02:00
|
|
|
],
|
|
|
|
'coercedClass' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2017-04-25 05:45:02 +02:00
|
|
|
class NullableClass {
|
|
|
|
}
|
2017-07-09 20:36:06 +02:00
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
class NullableBug {
|
|
|
|
/**
|
2018-11-12 18:03:55 +01:00
|
|
|
* @param class-string|null $className
|
2017-04-25 05:45:02 +02:00
|
|
|
* @return object|null
|
|
|
|
*/
|
|
|
|
public static function mock($className) {
|
|
|
|
if (!$className) { return null; }
|
|
|
|
return new $className();
|
|
|
|
}
|
2017-07-09 20:36:06 +02:00
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
/**
|
2018-01-05 03:36:16 +01:00
|
|
|
* @return ?NullableClass
|
2017-04-25 05:45:02 +02:00
|
|
|
*/
|
|
|
|
public function returns_nullable_class() {
|
2020-08-30 17:44:14 +02:00
|
|
|
/** @psalm-suppress ArgumentTypeCoercion */
|
2017-04-25 05:45:02 +02:00
|
|
|
return self::mock("NullableClass");
|
|
|
|
}
|
|
|
|
}',
|
2017-12-07 21:50:25 +01:00
|
|
|
'error_message' => 'LessSpecificReturnStatement',
|
2022-01-13 19:49:37 +01:00
|
|
|
'ignored_issues' => ['MixedInferredReturnType', 'MixedReturnStatement', 'MixedMethodCall'],
|
2017-05-27 02:05:57 +02:00
|
|
|
],
|
2017-11-06 21:37:49 +01:00
|
|
|
'undefinedVariableStaticCall' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2017-11-06 21:37:49 +01:00
|
|
|
$foo::bar();',
|
2017-12-06 06:56:00 +01:00
|
|
|
'error_message' => 'UndefinedGlobalVariable',
|
2017-11-06 21:37:49 +01:00
|
|
|
],
|
|
|
|
'staticCallOnString' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2017-11-06 21:37:49 +01:00
|
|
|
class A {
|
2018-01-11 21:50:45 +01:00
|
|
|
public static function bar(): int {
|
2017-11-06 21:37:49 +01:00
|
|
|
return 5;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$foo = "A";
|
2018-11-12 18:03:55 +01:00
|
|
|
/** @psalm-suppress InvalidStringClass */
|
2017-11-06 21:37:49 +01:00
|
|
|
$b = $foo::bar();',
|
|
|
|
'error_message' => 'MixedAssignment',
|
|
|
|
],
|
2018-01-22 06:17:16 +01:00
|
|
|
'possiblyNullFunctionCall' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2018-01-22 06:17:16 +01:00
|
|
|
$this->foo();',
|
|
|
|
'error_message' => 'InvalidScope',
|
|
|
|
],
|
|
|
|
'possiblyFalseReference' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2018-01-22 06:17:16 +01:00
|
|
|
class A {
|
|
|
|
public function bar(): void {}
|
|
|
|
}
|
|
|
|
|
|
|
|
$a = rand(0, 1) ? new A : false;
|
|
|
|
$a->bar();',
|
|
|
|
'error_message' => 'PossiblyFalseReference',
|
|
|
|
],
|
2018-02-14 17:21:43 +01:00
|
|
|
'undefinedParentClass' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2018-02-14 17:21:43 +01:00
|
|
|
/**
|
|
|
|
* @psalm-suppress UndefinedClass
|
|
|
|
*/
|
|
|
|
class B extends A {}
|
|
|
|
|
|
|
|
$b = new B();',
|
2018-04-13 01:42:24 +02:00
|
|
|
'error_message' => 'MissingDependency - src' . DIRECTORY_SEPARATOR . 'somefile.php:7',
|
2018-02-14 17:21:43 +01:00
|
|
|
],
|
2018-02-17 23:16:22 +01:00
|
|
|
'variableMethodCallOnArray' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2018-02-17 23:16:22 +01:00
|
|
|
$arr = [];
|
|
|
|
$b = "foo";
|
|
|
|
$arr->$b();',
|
|
|
|
'error_message' => 'InvalidMethodCall',
|
|
|
|
],
|
2018-03-06 17:20:54 +01:00
|
|
|
'intVarStaticCall' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2018-03-06 17:20:54 +01:00
|
|
|
$a = 5;
|
|
|
|
$a::bar();',
|
2018-03-06 18:19:50 +01:00
|
|
|
'error_message' => 'UndefinedClass',
|
2018-03-06 17:20:54 +01:00
|
|
|
],
|
|
|
|
'intVarNewCall' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2018-03-06 17:20:54 +01:00
|
|
|
$a = 5;
|
|
|
|
new $a();',
|
2018-03-06 18:19:50 +01:00
|
|
|
'error_message' => 'UndefinedClass',
|
2018-03-06 17:20:54 +01:00
|
|
|
],
|
2018-04-01 00:57:13 +02:00
|
|
|
'invokeTypeMismatch' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2018-04-01 00:57:13 +02:00
|
|
|
class A {
|
|
|
|
public function __invoke(string $p): void {}
|
|
|
|
}
|
|
|
|
|
|
|
|
$q = new A;
|
|
|
|
$q(1);',
|
|
|
|
'error_message' => 'InvalidScalarArgument',
|
|
|
|
],
|
|
|
|
'explicitInvokeTypeMismatch' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2018-04-01 00:57:13 +02:00
|
|
|
class A {
|
|
|
|
public function __invoke(string $p): void {}
|
|
|
|
}
|
|
|
|
(new A)->__invoke(1);',
|
|
|
|
'error_message' => 'InvalidScalarArgument',
|
|
|
|
],
|
2018-06-27 05:11:16 +02:00
|
|
|
'undefinedMethodPassedAsArg' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2018-06-27 05:11:16 +02:00
|
|
|
class A {
|
|
|
|
public function __call(string $method, array $args) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
$q = new A;
|
|
|
|
$q->foo(bar());',
|
2019-03-23 19:27:54 +01:00
|
|
|
'error_message' => 'UndefinedFunction',
|
2018-06-27 05:11:16 +02:00
|
|
|
],
|
2018-07-16 17:52:38 +02:00
|
|
|
'noIntersectionMethod' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2018-07-16 17:52:38 +02:00
|
|
|
interface A {}
|
|
|
|
interface B {}
|
|
|
|
|
|
|
|
/** @param B&A $p */
|
|
|
|
function f($p): void {
|
|
|
|
$p->zugzug();
|
|
|
|
}',
|
2019-03-23 19:27:54 +01:00
|
|
|
'error_message' => 'UndefinedInterfaceMethod - src' . DIRECTORY_SEPARATOR . 'somefile.php:7:29 - Method (B&A)::zugzug does not exist',
|
2018-07-16 17:52:38 +02:00
|
|
|
],
|
2018-12-17 23:48:13 +01:00
|
|
|
'noInstanceCallAsStatic' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2018-12-17 23:48:13 +01:00
|
|
|
class C {
|
|
|
|
public function foo() : void {}
|
|
|
|
}
|
|
|
|
|
|
|
|
(new C)::foo();',
|
|
|
|
'error_message' => 'InvalidStaticInvocation',
|
|
|
|
],
|
2019-01-28 07:12:41 +01:00
|
|
|
'noExceptionOnMissingClass' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2019-01-28 07:12:41 +01:00
|
|
|
/** @psalm-suppress UndefinedClass */
|
|
|
|
class A
|
|
|
|
{
|
|
|
|
/** @var class-string<Foo> */
|
|
|
|
protected $bar;
|
|
|
|
|
|
|
|
public function foo(string $s): void
|
|
|
|
{
|
|
|
|
$bar = $this->bar;
|
|
|
|
$bar::baz();
|
|
|
|
}
|
|
|
|
}',
|
2021-05-04 04:26:56 +02:00
|
|
|
'error_message' => 'MissingConstructor',
|
2019-01-28 07:12:41 +01:00
|
|
|
],
|
2019-04-18 19:51:34 +02:00
|
|
|
'checkMixedMethodCallStaticMethodCallArg' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2019-04-18 19:51:34 +02:00
|
|
|
class B {}
|
|
|
|
/** @param mixed $a */
|
|
|
|
function foo($a) : void {
|
|
|
|
/** @psalm-suppress MixedMethodCall */
|
|
|
|
$a->bar(B::bat());
|
|
|
|
}',
|
|
|
|
'error_message' => 'UndefinedMethod',
|
|
|
|
],
|
2019-07-12 20:39:06 +02:00
|
|
|
'complainAboutUndefinedPropertyOnMixedCall' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2019-07-12 20:39:06 +02:00
|
|
|
class C {
|
|
|
|
/** @param mixed $a */
|
|
|
|
public function foo($a) : void {
|
|
|
|
/** @psalm-suppress MixedMethodCall */
|
|
|
|
$a->bar($this->d);
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
'error_message' => 'UndefinedThisPropertyFetch',
|
|
|
|
],
|
2019-07-23 00:04:52 +02:00
|
|
|
'complainAboutUndefinedPropertyOnMixedCallConcatOp' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2019-07-23 00:04:52 +02:00
|
|
|
class A {
|
|
|
|
/**
|
|
|
|
* @psalm-suppress MixedMethodCall
|
|
|
|
*/
|
|
|
|
public function foo(object $a) : void {
|
|
|
|
$a->bar("bat" . $this->baz);
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
'error_message' => 'UndefinedThisPropertyFetch',
|
|
|
|
],
|
2019-08-20 06:00:20 +02:00
|
|
|
'alreadyHasmethod' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2019-08-20 06:00:20 +02:00
|
|
|
class A {
|
|
|
|
public function foo() : void {}
|
|
|
|
}
|
|
|
|
|
|
|
|
function foo(A $a) : void {
|
|
|
|
if (method_exists($a, "foo")) {
|
|
|
|
$object->foo();
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
'error_message' => 'RedundantCondition',
|
|
|
|
],
|
2019-08-23 05:26:04 +02:00
|
|
|
'possiblyNullOrMixedArg' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2019-08-23 05:26:04 +02:00
|
|
|
class A {
|
|
|
|
/**
|
|
|
|
* @var mixed
|
|
|
|
*/
|
|
|
|
public $foo;
|
|
|
|
}
|
|
|
|
|
|
|
|
function takesString(string $s) : void {}
|
|
|
|
|
|
|
|
function takesA(?A $a) : void {
|
|
|
|
/**
|
|
|
|
* @psalm-suppress PossiblyNullPropertyFetch
|
|
|
|
* @psalm-suppress MixedArgument
|
|
|
|
*/
|
|
|
|
takesString($a->foo);
|
|
|
|
}',
|
|
|
|
'error_message' => 'PossiblyNullArgument',
|
|
|
|
],
|
2019-11-01 14:05:28 +01:00
|
|
|
'callOnVoid' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2019-11-01 14:05:28 +01:00
|
|
|
class A {
|
|
|
|
public function foo(): void {}
|
|
|
|
}
|
|
|
|
|
|
|
|
$p = new A();
|
|
|
|
$p->foo()->bar();',
|
2022-12-18 17:15:15 +01:00
|
|
|
'error_message' => 'NullReference',
|
2019-11-01 14:05:28 +01:00
|
|
|
],
|
2020-01-10 21:53:15 +01:00
|
|
|
'dateTimeNullFirstArg' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2020-01-10 21:53:15 +01:00
|
|
|
$date = new DateTime(null);',
|
2022-12-18 17:15:15 +01:00
|
|
|
'error_message' => 'NullArgument',
|
2020-01-10 21:53:15 +01:00
|
|
|
],
|
2020-02-10 20:44:33 +01:00
|
|
|
'noCrashOnGetClassMethodCall' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2020-02-10 20:44:33 +01:00
|
|
|
class User {
|
|
|
|
/**
|
|
|
|
* @psalm-suppress MixedArgument
|
|
|
|
*/
|
|
|
|
public function give(): void{
|
|
|
|
/** @var mixed */
|
|
|
|
$model = null;
|
|
|
|
$class = \get_class($model);
|
|
|
|
$class::foo();
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
'error_message' => 'InvalidStringClass',
|
|
|
|
],
|
2020-03-11 15:18:40 +01:00
|
|
|
'preventAbstractMethodCall' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2020-03-11 15:18:40 +01:00
|
|
|
abstract class Base {
|
|
|
|
public static function callAbstract() : void {
|
|
|
|
static::bar();
|
|
|
|
}
|
|
|
|
|
|
|
|
abstract static function bar() : void;
|
|
|
|
}
|
|
|
|
|
|
|
|
Base::bar();',
|
|
|
|
'error_message' => 'AbstractMethodCall',
|
|
|
|
],
|
2020-03-15 18:44:00 +01:00
|
|
|
'tooManyArgumentsToStatic' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2020-03-15 18:44:00 +01:00
|
|
|
class A {
|
|
|
|
public static function fooFoo(int $a): void {}
|
|
|
|
}
|
|
|
|
|
|
|
|
A::fooFoo(5, "dfd");',
|
|
|
|
'error_message' => 'TooManyArguments',
|
|
|
|
],
|
|
|
|
'tooFewArgumentsToStatic' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2020-03-15 18:44:00 +01:00
|
|
|
class A {
|
|
|
|
public static function fooFoo(int $a): void {}
|
|
|
|
}
|
|
|
|
|
|
|
|
A::fooFoo();',
|
|
|
|
'error_message' => 'TooFewArguments',
|
|
|
|
],
|
|
|
|
'tooManyArgumentsToInstance' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2020-03-15 18:44:00 +01:00
|
|
|
class A {
|
|
|
|
public function fooFoo(int $a): void {}
|
|
|
|
}
|
|
|
|
|
|
|
|
(new A)->fooFoo(5, "dfd");',
|
|
|
|
'error_message' => 'TooManyArguments',
|
|
|
|
],
|
|
|
|
'tooFewArgumentsToInstance' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2020-03-15 18:44:00 +01:00
|
|
|
class A {
|
|
|
|
public function fooFoo(int $a): void {}
|
|
|
|
}
|
|
|
|
|
|
|
|
(new A)->fooFoo();',
|
|
|
|
'error_message' => 'TooFewArguments',
|
|
|
|
],
|
2020-04-12 14:40:24 +02:00
|
|
|
'getterAutomagicOverridden' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2020-04-12 14:40:24 +02:00
|
|
|
class A {
|
|
|
|
/** @var string|null */
|
|
|
|
public $a;
|
2020-04-12 20:13:42 +02:00
|
|
|
|
2020-04-12 14:40:24 +02:00
|
|
|
/** @return string|null */
|
|
|
|
function getA() {
|
2020-04-12 20:13:42 +02:00
|
|
|
return $this->a;
|
2020-04-12 14:40:24 +02:00
|
|
|
}
|
|
|
|
}
|
2020-04-12 20:13:42 +02:00
|
|
|
|
2020-04-12 14:40:24 +02:00
|
|
|
class AChild extends A {
|
|
|
|
function getA() {
|
|
|
|
return rand(0, 1) ? $this->a : null;
|
|
|
|
}
|
|
|
|
}
|
2020-04-12 20:13:42 +02:00
|
|
|
|
2020-04-12 14:40:24 +02:00
|
|
|
function foo(A $a) : void {
|
|
|
|
if ($a->getA()) {
|
|
|
|
echo strlen($a->getA());
|
|
|
|
}
|
|
|
|
}
|
2020-04-12 20:13:42 +02:00
|
|
|
|
2020-04-12 14:40:24 +02:00
|
|
|
foo(new AChild());',
|
2022-12-18 17:15:15 +01:00
|
|
|
'error_message' => 'PossiblyNullArgument',
|
2020-04-12 14:40:24 +02:00
|
|
|
],
|
|
|
|
'getterAutomagicOverriddenWithAssertion' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2020-04-12 14:40:24 +02:00
|
|
|
class A {
|
|
|
|
/** @var string|null */
|
|
|
|
public $a;
|
2020-04-12 20:13:42 +02:00
|
|
|
|
2020-04-12 14:40:24 +02:00
|
|
|
/** @psalm-assert-if-true string $this->a */
|
|
|
|
function hasA() {
|
2020-04-12 20:13:42 +02:00
|
|
|
return is_string($this->a);
|
2020-04-12 14:40:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/** @return string|null */
|
|
|
|
function getA() {
|
2020-04-12 20:13:42 +02:00
|
|
|
return $this->a;
|
2020-04-12 14:40:24 +02:00
|
|
|
}
|
|
|
|
}
|
2020-04-12 20:13:42 +02:00
|
|
|
|
2020-04-12 14:40:24 +02:00
|
|
|
class AChild extends A {
|
|
|
|
function getA() {
|
|
|
|
return rand(0, 1) ? $this->a : null;
|
|
|
|
}
|
|
|
|
}
|
2020-04-12 20:13:42 +02:00
|
|
|
|
2020-04-12 14:40:24 +02:00
|
|
|
function foo(A $a) : void {
|
|
|
|
if ($a->hasA()) {
|
|
|
|
echo strlen($a->getA());
|
|
|
|
}
|
|
|
|
}
|
2020-04-12 20:13:42 +02:00
|
|
|
|
2020-04-12 14:40:24 +02:00
|
|
|
foo(new AChild());',
|
2022-12-18 17:15:15 +01:00
|
|
|
'error_message' => 'PossiblyNullArgument',
|
2020-05-03 04:13:59 +02:00
|
|
|
],
|
|
|
|
'checkVariableInUnknownClassConstructor' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2020-05-03 04:13:59 +02:00
|
|
|
/** @psalm-suppress UndefinedClass */
|
|
|
|
new Missing($class_arg);',
|
|
|
|
'error_message' => 'PossiblyUndefinedVariable',
|
|
|
|
],
|
2020-07-16 17:58:27 +02:00
|
|
|
'unchainedInferredInferredMutationFreeMethodCallDontMemoize' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2020-07-16 17:58:27 +02:00
|
|
|
class SomeClass {
|
|
|
|
private ?int $int;
|
|
|
|
|
|
|
|
public function __construct() {
|
|
|
|
$this->int = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getInt(): ?int {
|
|
|
|
return $this->int;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function printInt(int $int): void {
|
|
|
|
echo $int;
|
|
|
|
}
|
|
|
|
|
|
|
|
$obj = new SomeClass();
|
|
|
|
|
|
|
|
if ($obj->getInt()) {
|
|
|
|
printInt($obj->getInt());
|
|
|
|
}',
|
|
|
|
'error_message' => 'PossiblyNullArgument',
|
|
|
|
],
|
2020-07-16 18:59:49 +02:00
|
|
|
'getterTypeInferringWithChange' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2020-07-16 18:59:49 +02:00
|
|
|
class A {
|
|
|
|
/** @var int|string|null */
|
|
|
|
public $val;
|
|
|
|
|
|
|
|
/** @return int|string|null */
|
|
|
|
final public function getValue() {
|
|
|
|
return $this->val;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$a = new A();
|
|
|
|
|
|
|
|
if (is_string($a->getValue())) {
|
|
|
|
$a->val = 5;
|
|
|
|
echo strlen($a->getValue());
|
|
|
|
}',
|
|
|
|
'error_message' => 'InvalidScalarArgument',
|
|
|
|
],
|
2021-05-21 13:35:01 +02:00
|
|
|
'possiblyNullReferenceInInvokedCall' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2021-05-21 13:35:01 +02:00
|
|
|
interface Location {
|
|
|
|
public function getId(): int;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @psalm-immutable */
|
|
|
|
interface Application {
|
|
|
|
public function getLocation(): ?Location;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface TakesId {
|
|
|
|
public function __invoke(int $location): int;
|
|
|
|
}
|
|
|
|
|
|
|
|
function f(TakesId $takesId, Application $application): void {
|
|
|
|
($takesId)($application->getLocation()->getId());
|
|
|
|
}',
|
|
|
|
'error_message' => 'PossiblyNullReference',
|
2021-06-01 22:06:12 +02:00
|
|
|
],
|
|
|
|
'nullsafeShortCircuitInVariable' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2021-06-01 22:06:12 +02:00
|
|
|
interface Bar {
|
|
|
|
public function doBaz(): void;
|
|
|
|
}
|
|
|
|
interface Foo {
|
|
|
|
public function getBar(): Bar;
|
|
|
|
}
|
|
|
|
function fooOrNull(): ?Foo {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
$a = fooOrNull()?->getBar();
|
|
|
|
$a->doBaz();',
|
|
|
|
'error_message' => 'PossiblyNullReference',
|
2022-01-13 19:49:37 +01:00
|
|
|
'ignored_issues' => [],
|
2022-12-18 17:15:15 +01:00
|
|
|
'php_version' => '8.0',
|
2021-06-01 22:06:12 +02:00
|
|
|
],
|
2022-01-24 09:17:29 +01:00
|
|
|
'undefinedMethodOnParentCallWithMethodExistsOnSelf' => [
|
2022-01-26 21:06:25 +01:00
|
|
|
'code' => '<?php
|
2022-01-24 09:17:29 +01:00
|
|
|
class A {}
|
|
|
|
class B extends A {
|
|
|
|
public function foo(): string {
|
|
|
|
return parent::foo();
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
'error_message' => 'UndefinedMethod',
|
|
|
|
],
|
2023-02-16 06:28:47 +01:00
|
|
|
'incorrectCallableParamDefault' => [
|
|
|
|
'code' => '<?php
|
|
|
|
class A {
|
|
|
|
public function foo(callable $_a = "strlen"): void {}
|
|
|
|
}
|
|
|
|
',
|
|
|
|
'error_message' => 'InvalidParamDefault',
|
|
|
|
],
|
2017-04-25 05:45:02 +02:00
|
|
|
];
|
2017-02-12 06:50:37 +01:00
|
|
|
}
|
2016-12-12 05:41:11 +01:00
|
|
|
}
|