Skip to content

Commit 1e59c4e

Browse files
kamil-zacekondrejmirtes
authored andcommitted
Add __benevolent return types to doctrine Result stub
1 parent 664e380 commit 1e59c4e

File tree

4 files changed

+110
-1
lines changed

4 files changed

+110
-1
lines changed

.editorconfig

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ insert_final_newline = true
66
charset = utf-8
77
trim_trailing_whitespace = true
88

9-
[*.{php,phpt}]
9+
[*.{php,phpt,stub}]
1010
indent_style = tab
1111
indent_size = 4
1212

extension.neon

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ parameters:
2424
- stubs/DBAL/Exception/UniqueConstraintViolationException.stub
2525
- stubs/DBAL/Types/Type.stub
2626
- stubs/DBAL/Exception.stub
27+
- stubs/DBAL/FetchMode.stub
2728
- stubs/DBAL/Result.stub
2829
- stubs/DocumentManager.stub
2930
- stubs/DocumentRepository.stub

stubs/DBAL/FetchMode.stub

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace Doctrine\DBAL;
4+
5+
/**
6+
* Legacy Class that keeps BC for using the legacy APIs fetch()/fetchAll().
7+
*
8+
* @deprecated Use the dedicated fetch*() methods for the desired fetch mode instead.
9+
*/
10+
class FetchMode
11+
{
12+
/** @link PDO::FETCH_ASSOC */
13+
public const ASSOCIATIVE = 2;
14+
15+
/** @link PDO::FETCH_NUM */
16+
public const NUMERIC = 3;
17+
18+
/** @link PDO::FETCH_COLUMN */
19+
public const COLUMN = 7;
20+
}

stubs/DBAL/Result.stub

+88
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,95 @@
22

33
namespace Doctrine\DBAL;
44

5+
use Traversable;
6+
57
class Result
68
{
79

10+
/**
11+
* @return list<__benevolent<float|int|string|null>>|false
12+
*/
13+
public function fetchNumeric();
14+
15+
/**
16+
* @return array<string, __benevolent<float|int|string|null>>|false
17+
*/
18+
public function fetchAssociative();
19+
20+
/**
21+
* @return __benevolent<float|int|string|false|null>
22+
*/
23+
public function fetchOne();
24+
25+
/**
26+
* @return list<list<__benevolent<float|int|string|null>>>
27+
*/
28+
public function fetchAllNumeric(): array;
29+
30+
/**
31+
* @return list<array<string, __benevolent<float|int|string|null>>>
32+
*/
33+
public function fetchAllAssociative(): array;
34+
35+
/**
36+
* @return array<mixed, __benevolent<float|int|string|null>>
37+
*/
38+
public function fetchAllKeyValue(): array;
39+
40+
/**
41+
* @return array<mixed,array<string, __benevolent<float|int|string|null>>>
42+
*/
43+
public function fetchAllAssociativeIndexed(): array;
44+
45+
/**
46+
* @return list<__benevolent<float|int|string|null>>
47+
*/
48+
public function fetchFirstColumn(): array;
49+
50+
/**
51+
* @return Traversable<int, list<__benevolent<float|int|string|null>>>
52+
*/
53+
public function iterateNumeric(): Traversable;
54+
55+
/**
56+
* @return Traversable<int, array<string, __benevolent<float|int|string|null>>>
57+
*/
58+
public function iterateAssociative(): Traversable;
59+
60+
/**
61+
* @return Traversable<__benevolent<float|int|string|null>, __benevolent<float|int|string|null>>
62+
*/
63+
public function iterateKeyValue(): Traversable;
64+
65+
/**
66+
* @return Traversable<__benevolent<float|int|string|null>, array<string, __benevolent<float|int|string|null>>>
67+
*/
68+
public function iterateAssociativeIndexed(): Traversable;
69+
70+
/**
71+
* @return Traversable<int, __benevolent<float|int|string|null>>
72+
*/
73+
public function iterateColumn(): Traversable;
74+
75+
public function rowCount(): int;
76+
77+
public function columnCount(): int;
78+
79+
public function free(): void;
80+
81+
/**
82+
* @deprecated Use {@see fetchNumeric()}, {@see fetchAssociative()} or {@see fetchOne()} instead.
83+
*
84+
* @phpstan-param FetchMode::* $mode
85+
* @return ($mode is 2 ? array<string, __benevolent<float|int|string|null>>|false : ($mode is 3 ? list<__benevolent<float|int|string|null>>|false : __benevolent<float|int|string|false|null>))
86+
*/
87+
public function fetch(int $mode = FetchMode::ASSOCIATIVE);
88+
89+
/**
90+
* @deprecated Use {@see fetchAllNumeric()}, {@see fetchAllAssociative()} or {@see fetchOne()} instead.
91+
*
92+
* @phpstan-param FetchMode::* $mode
93+
* @return ($mode is 2 ? list<array<string, __benevolent<float|int|string|null>>> : ($mode is 3 ? list<list<__benevolent<float|int|string|null>>> : list<__benevolent<float|int|string|null>>))
94+
*/
95+
public function fetchAll(int $mode = FetchMode::ASSOCIATIVE): array;
896
}

0 commit comments

Comments
 (0)