Skip to content

Commit 5e252bd

Browse files
Fix 10367
1 parent 9dbff97 commit 5e252bd

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

src/Type/Php/ArrayColumnHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ private function getOffsetOrProperty(Type $type, Type $offsetOrProperty, Scope $
145145
if (!$type->canAccessProperties()->no()) {
146146
$propertyTypes = $offsetOrProperty->getConstantStrings();
147147
if ($propertyTypes === []) {
148-
return new MixedType();
148+
return $allowMaybe ? new MixedType() : null;
149149
}
150150
foreach ($propertyTypes as $propertyType) {
151151
$propertyName = $propertyType->getValue();

tests/PHPStan/Rules/Variables/EmptyRuleTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,13 @@ public function testBug12658(): void
207207
$this->analyse([__DIR__ . '/data/bug-12658.php'], []);
208208
}
209209

210+
public function testBug10367(): void
211+
{
212+
$this->treatPhpDocTypesAsCertain = true;
213+
214+
$this->analyse([__DIR__ . '/data/bug-10367.php'], []);
215+
}
216+
210217
#[RequiresPhp('>= 8.0')]
211218
public function testIssetAfterRememberedConstructor(): void
212219
{
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug10367;
4+
5+
final class PackingSlipPdf
6+
{
7+
public function __construct(array $packingSlipItems, string $fullName)
8+
{
9+
if (empty($packingSlipItems)) {
10+
error_log('$packingSlipItems is empty: check company: ' . $fullName);
11+
} else {
12+
$freightNumbers = array_column($packingSlipItems, 3);
13+
if (empty($freightNumbers)) {
14+
error_log('$freightNumbers is empty: check company: ' . $fullName);
15+
error_log('$freightNumbers is empty: check dataset: ' . print_r($packingSlipItems[0], true));
16+
} elseif (empty($freightNumbers[0])) {
17+
error_log('$freightNumbers[0] is empty: check company: ' . $fullName);
18+
error_log('$freightNumbers[0] is empty: check freigthnumbers: ' . print_r($freightNumbers, true));
19+
error_log('$freightNumbers[0] is empty: check dataset: ' . print_r($packingSlipItems[0], true));
20+
}
21+
}
22+
}
23+
}
24+
25+
$testArray = [
26+
[1 => 123, 2 => 413, 4 => 132],
27+
[1 => 123, 2 => 413, 4 => 132],
28+
];
29+
30+
$packingSlipPdf = new PackingSlipPdf($testArray, "TestName");

0 commit comments

Comments
 (0)