Skip to content

Commit f75ec2d

Browse files
Fix
1 parent 9696f45 commit f75ec2d

4 files changed

Lines changed: 39 additions & 77 deletions

File tree

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
1-
<?php declare(strict_types = 1);
1+
<?php // lint >= 8.0
22

3-
namespace Bug11006;
3+
declare(strict_types = 1);
44

5-
class StringOrNullAttributeDto
6-
{
7-
public function __construct(
8-
public ?string $data,
9-
) {
10-
}
11-
}
5+
namespace Bug11006;
126

13-
class StringAttributeDto
7+
class ProductParentPayloadDto
148
{
9+
/** @param null|'size_uk'|'size_us' $SizeAttributeCode */
1510
public function __construct(
16-
public string $data,
11+
public ?string $SizeAttributeCode,
1712
) {
1813
}
1914
}
@@ -34,33 +29,46 @@ public function __construct(
3429
}
3530
}
3631

37-
class ProductParentPayloadDto
32+
class StringOrNullAttributeDto
3833
{
39-
/**
40-
* @param 'size_uk'|'size_us' $SizeAttributeCode
41-
*/
4234
public function __construct(
43-
public string $SizeAttributeCode,
35+
public ?string $data,
4436
) {
4537
}
4638
}
4739

40+
class StringAttributeDto
41+
{
42+
public function __construct(
43+
public string $data,
44+
) {
45+
}
46+
}
47+
48+
4849
class PhpStanProblem
4950
{
50-
public function example(ProductParentPayloadDto $parentPayload): void
51+
public function example(ProductParentPayloadDto $productParentPayloadDto): void
5152
{
53+
if (null === $productParentPayloadDto->SizeAttributeCode) {
54+
return;
55+
}
56+
5257
$values = [
5358
'ean' => [
5459
new StringOrNullAttributeDto(''),
5560
],
56-
$parentPayload->SizeAttributeCode => [
61+
$productParentPayloadDto->SizeAttributeCode => [
5762
new StringOrNullAttributeDto(''),
5863
],
64+
// This part goes wrong
5965
'osa_sizes' => [
6066
new StringAttributeDto(''),
6167
],
6268
];
6369

64-
new AkeneoUpdateProductDto($values);
70+
$productData = new AkeneoUpdateProductDto(
71+
values: $values,
72+
);
6573
}
6674
}

tests/PHPStan/Rules/Operators/data/bug-14080.php

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,18 @@
22

33
namespace Bug14080;
44

5-
class Foo
6-
{
7-
/**
8-
* @param list<array{sql: string, time: int}> $queries
9-
*/
10-
public function doFoo(array $queries): void
11-
{
12-
$queryTotals = ['all' => 0, 'duplicates' => 0];
13-
$queryTypes = ['select', 'update', 'delete', 'insert'];
5+
$queryTotals = ['all' => 0, 'duplicates' => 0];
6+
$queryTypes = ['select', 'update', 'delete', 'insert'];
7+
$queries = [['sql' => 'select', 'time' => 8234], ['sql' => 'select', 'time' => 4558], ['sql' => 'insert', 'time' => 9928]];
148

15-
$queryTotals['time'] = array_sum(array_column($queries, 'time'));
9+
$queryTotals['time'] = array_sum(array_column($queries, 'time'));
1610

17-
foreach ($queryTypes as $type) {
18-
$tq = array_filter($queries, fn ($v) => str_starts_with(strtolower($v['sql']), $type));
19-
$queryTotals['all'] += count($tq);
20-
$queryTotals[$type] = [
21-
'count' => count($tq),
22-
];
23-
}
24-
}
11+
foreach ($queryTypes as $type) {
12+
$tq = array_filter($queries, fn ($v) => str_starts_with(strtolower($v['sql']), $type));
13+
$tq_time = array_sum(array_column($tq, 'time'));
14+
$queryTotals['all'] += count($tq);
15+
$queryTotals[$type] = [
16+
'count' => count($tq),
17+
'time' => $tq_time / $queryTotals['time'] * 100,
18+
];
2519
}

tests/PHPStan/Rules/Variables/NullCoalesceRuleTest.php

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -372,22 +372,4 @@ public function testBug13921(): void
372372
]);
373373
}
374374

375-
public function testBug13623(): void
376-
{
377-
$this->analyse([__DIR__ . '/data/bug-13623.php'], [
378-
[
379-
'Offset \'new_invoice\' on array{balance_forward: 0, new_invoice: 0, payments: 0, balance: float} on left side of ??= always exists and is not nullable.',
380-
18,
381-
],
382-
[
383-
'Offset \'payments\' on array{balance_forward: 0, new_invoice: 0, payments: 0, balance: float} on left side of ??= always exists and is not nullable.',
384-
19,
385-
],
386-
[
387-
'Offset \'balance\' on array{balance_forward: 0, new_invoice: 0, payments: 0, balance: float} on left side of ??= always exists and is not nullable.',
388-
20,
389-
],
390-
]);
391-
}
392-
393375
}

tests/PHPStan/Rules/Variables/data/bug-13623.php

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)