Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 90 additions & 0 deletions tests/PHPStan/Analyser/nsrt/bug-11488.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?php

namespace Bug11488Nsrt;

use function PHPStan\Testing\assertType;

class Foo
{
/**
* @param array{mixed}|array{mixed, string|null, mixed} $row
*/
protected function test(array $row): string
{
if (count($row) !== 1) {
assertType('array{mixed, string|null, mixed}', $row);

[$field, $operator, $value] = $row;
assertType('string|null', $operator);
} else {
assertType('array{mixed}', $row);
}

if (count($row) === 1) {
assertType('array{mixed}', $row);
} else {
assertType('array{mixed, string|null, mixed}', $row);
}

if (count($row) === 2) {
assertType('*NEVER*', $row);
} else {
assertType('array{mixed, string|null, mixed}|array{mixed}', $row);
}

if (count($row) !== 2) {
assertType('array{mixed, string|null, mixed}|array{mixed}', $row);
} else {
assertType('*NEVER*', $row);
}

if (count($row) === 3) {
assertType('array{mixed, string|null, mixed}', $row);
} else {
assertType('array{mixed}', $row);
}

return '';
}

/**
* @param array{bool}|array{mixed, string|null, mixed} $row
*/
protected function test2(array $row): string
{
if (count($row) !== 1) {
assertType('array{mixed, string|null, mixed}', $row);

[$field, $operator, $value] = $row;
assertType('string|null', $operator);
} else {
assertType('array{bool}', $row);
}

if (count($row) === 1) {
assertType('array{bool}', $row);
} else {
assertType('array{mixed, string|null, mixed}', $row);
}

if (count($row) === 2) {
assertType('*NEVER*', $row);
} else {
assertType('array{bool}|array{mixed, string|null, mixed}', $row);
}

if (count($row) !== 2) {
assertType('array{bool}|array{mixed, string|null, mixed}', $row);
} else {
assertType('*NEVER*', $row);
}

if (count($row) === 3) {
assertType('array{mixed, string|null, mixed}', $row);
} else {
assertType('array{bool}', $row);
}

return '';
}
}
5 changes: 5 additions & 0 deletions tests/PHPStan/Rules/Variables/NullCoalesceRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,11 @@ public function testBug14213(): void
]);
}

public function testBug11488(): void
{
$this->analyse([__DIR__ . '/data/bug-11488.php'], []);
}

public function testBug13921(): void
{
$this->analyse([__DIR__ . '/data/bug-13921.php'], [
Expand Down
19 changes: 19 additions & 0 deletions tests/PHPStan/Rules/Variables/data/bug-11488.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Bug11488;

class Foo
{
/**
* @param array{mixed}|array{mixed, string|null, mixed} $row
*/
protected function test(array $row): string
{
if (count($row) !== 1) {
[$field, $operator, $value] = $row;
return $operator ?? '=';
}

return '';
}
}
Loading