Skip to content
Open
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
7 changes: 5 additions & 2 deletions src/Type/Accessory/OversizedArrayType.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
use PHPStan\Type\Traits\NonGenericTypeTrait;
use PHPStan\Type\Traits\NonObjectTypeTrait;
use PHPStan\Type\Traits\NonRemoveableTypeTrait;
use PHPStan\Type\Traits\TruthyBooleanTypeTrait;
use PHPStan\Type\Traits\UndecidedComparisonCompoundTypeTrait;
use PHPStan\Type\Type;
use PHPStan\Type\UnionType;
Expand All @@ -32,7 +31,6 @@ class OversizedArrayType implements CompoundType, AccessoryType

use MaybeCallableTypeTrait;
use NonObjectTypeTrait;
use TruthyBooleanTypeTrait;
use NonGenericTypeTrait;
use UndecidedComparisonCompoundTypeTrait;
use NonRemoveableTypeTrait;
Expand Down Expand Up @@ -414,6 +412,11 @@ public function toAbsoluteNumber(): Type
return new ErrorType();
}

public function toBoolean(): BooleanType
{
return new BooleanType();
}

public function toInteger(): Type
{
return new ConstantIntegerType(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,12 @@ public function testBug8797(): void
$this->analyse([__DIR__ . '/data/bug-8797.php'], []);
}

public function testBug13797(): void
{
$this->treatPhpDocTypesAsCertain = true;
$this->analyse([__DIR__ . '/data/bug-13797.php'], []);
}

public function testBug7937(): void
{
$this->treatPhpDocTypesAsCertain = true;
Expand Down
82 changes: 82 additions & 0 deletions tests/PHPStan/Rules/Comparison/data/bug-13797.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php declare(strict_types = 1);

namespace Bug13797;

/** @return ?array<string, mixed> */
function alert(): ?array
{
$alerts = [];

if (rand()) {
$alerts[] = [
'message' => "Foo",
'details' => "bar",
'duration' => rand() ?: null,
'severity' => 100,
];
}

if (rand()) {
$alerts[] = [
'message' => 'Offline',
'duration' => rand() ?: null,
'severity' => 99,
];
}

if (rand()) {
$alerts[] = [
'message' => 'Running W/O Operator',
'duration' => rand() ?: null,
'severity' => 75,
];
}

if (rand()) {
$alerts[] = [
'message' => 'No Queue',
'duration' => rand() ?: null,
'severity' => 60,
];
}

if (rand()) {
if (rand()) {
$alerts[] = [
'message' => 'Not Scheduled',
'duration' => null,
'severity' => 25,
];
}

if (rand()) {
$alerts[] = [
'message' => 'On Lunch',
'duration' => rand() ?: null,
'severity' => 24,
];
}

if (rand()) {
$alerts[] = [
'message' => 'On Break',
'duration' => rand() ?: null,
'severity' => 24,
];
}
}

if (rand()) {
$alerts[] = [
'message' => 'Idle',
'duration' => rand() ?: null,
'severity' => 23,
];
}

if (!$alerts) {
return null;
}

return $alerts[0];
}
Loading