Skip to content

Commit 7200468

Browse files
committed
Typed conditional returns for non-empty-array typed methods
1 parent 7cdc396 commit 7200468

File tree

2 files changed

+95
-8
lines changed

2 files changed

+95
-8
lines changed

src/Portability/Converter.php

+26-8
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,27 @@ public function __construct(bool $convertEmptyStringToNull, bool $rightTrimStrin
5151
}
5252

5353
/**
54-
* @param non-empty-list<mixed>|false $row
54+
* @param list<mixed>|false $row
5555
*
56-
* @return non-empty-list<mixed>|false
56+
* @return list<mixed>|false
57+
* @psalm-return (
58+
* $row is non-empty-list<mixed> ? non-empty-list<mixed> :
59+
* ($row is list<mixed> ? list<mixed> : false)
60+
* )
5761
*/
5862
public function convertNumeric(array|false $row): array|false
5963
{
6064
return ($this->convertNumeric)($row);
6165
}
6266

6367
/**
64-
* @param non-empty-array<string,mixed>|false $row
68+
* @param array<string, mixed>|false $row
6569
*
66-
* @return non-empty-array<string, mixed>|false
70+
* @return array<string, mixed>|false
71+
* @psalm-return (
72+
* $row is non-empty-array<string, mixed> ? non-empty-array<string, mixed> :
73+
* ($row is array<string, mixed> ? array<string, mixed> : false)
74+
* )
6775
*/
6876
public function convertAssociative(array|false $row): array|false
6977
{
@@ -76,19 +84,29 @@ public function convertOne(mixed $value): mixed
7684
}
7785

7886
/**
79-
* @param list<non-empty-list<mixed>> $data
87+
* @param list<list<mixed>> $data
8088
*
81-
* @return list<non-empty-list<mixed>>
89+
* @return list<list<mixed>>
90+
* @psalm-return (
91+
* $data is list<non-empty-list<mixed>>
92+
* ? list<non-empty-list<mixed>>
93+
* : list<list<mixed>>
94+
* )
8295
*/
8396
public function convertAllNumeric(array $data): array
8497
{
8598
return ($this->convertAllNumeric)($data);
8699
}
87100

88101
/**
89-
* @param list<non-empty-array<string,mixed>> $data
102+
* @param list<array<string,mixed>> $data
90103
*
91-
* @return list<non-empty-array<string,mixed>>
104+
* @return list<array<string,mixed>>
105+
* @psalm-return (
106+
* $data is list<non-empty-array<string,mixed>>
107+
* ? list<non-empty-array<string,mixed>>
108+
* : list<array<string,mixed>>
109+
* )
92110
*/
93111
public function convertAllAssociative(array $data): array
94112
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Doctrine\StaticAnalysis\DBAL;
6+
7+
use Doctrine\DBAL\Portability\Converter;
8+
9+
/** @return false */
10+
function convertNumericFalse(Converter $converter): bool
11+
{
12+
return $converter->convertNumeric(false);
13+
}
14+
15+
/** @return list<mixed> */
16+
function convertNumericEmptyArray(Converter $converter): array
17+
{
18+
return $converter->convertNumeric([]);
19+
}
20+
21+
/** @return non-empty-list<mixed> */
22+
function convertNumericNonEmptyArray(Converter $converter): array
23+
{
24+
return $converter->convertNumeric(['foo']);
25+
}
26+
27+
/** @return false */
28+
function convertAssociativeFalse(Converter $converter): bool
29+
{
30+
return $converter->convertAssociative(false);
31+
}
32+
33+
/** @return array<string, mixed> */
34+
function convertAssociativeEmptyArray(Converter $converter): array
35+
{
36+
return $converter->convertAssociative([]);
37+
}
38+
39+
/** @return non-empty-array<string, mixed> */
40+
function convertAssociativeNonEmptyArray(Converter $converter): array
41+
{
42+
return $converter->convertAssociative(['foo' => 'bar']);
43+
}
44+
45+
/** @return list<list<mixed>> */
46+
function convertAllNumericEmptyArray(Converter $converter): array
47+
{
48+
return $converter->convertAllNumeric([[]]);
49+
}
50+
51+
/** @return list<non-empty-list<mixed>> */
52+
function convertAllNumericNonEmptyArray(Converter $converter): array
53+
{
54+
return $converter->convertAllNumeric([['foo']]);
55+
}
56+
57+
58+
/** @return list<array<string, mixed>> */
59+
function convertAllAssociativeEmptyArray(Converter $converter): array
60+
{
61+
return $converter->convertAllAssociative([[]]);
62+
}
63+
64+
/** @return list<non-empty-array<string, mixed>> */
65+
function convertAllAssociativeNonEmptyArray(Converter $converter): array
66+
{
67+
return $converter->convertAllAssociative([['foo' => 'bar']]);
68+
}
69+

0 commit comments

Comments
 (0)