Skip to content

Commit

Permalink
Add __benevolent return types to doctrine Result stub
Browse files Browse the repository at this point in the history
  • Loading branch information
kamil-zacek authored and ondrejmirtes committed Apr 18, 2024
1 parent 664e380 commit 1e59c4e
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ insert_final_newline = true
charset = utf-8
trim_trailing_whitespace = true

[*.{php,phpt}]
[*.{php,phpt,stub}]
indent_style = tab
indent_size = 4

Expand Down
1 change: 1 addition & 0 deletions extension.neon
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ parameters:
- stubs/DBAL/Exception/UniqueConstraintViolationException.stub
- stubs/DBAL/Types/Type.stub
- stubs/DBAL/Exception.stub
- stubs/DBAL/FetchMode.stub
- stubs/DBAL/Result.stub
- stubs/DocumentManager.stub
- stubs/DocumentRepository.stub
Expand Down
20 changes: 20 additions & 0 deletions stubs/DBAL/FetchMode.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Doctrine\DBAL;

/**
* Legacy Class that keeps BC for using the legacy APIs fetch()/fetchAll().
*
* @deprecated Use the dedicated fetch*() methods for the desired fetch mode instead.
*/
class FetchMode
{
/** @link PDO::FETCH_ASSOC */
public const ASSOCIATIVE = 2;

/** @link PDO::FETCH_NUM */
public const NUMERIC = 3;

/** @link PDO::FETCH_COLUMN */
public const COLUMN = 7;
}
88 changes: 88 additions & 0 deletions stubs/DBAL/Result.stub
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,95 @@

namespace Doctrine\DBAL;

use Traversable;

class Result
{

/**
* @return list<__benevolent<float|int|string|null>>|false
*/
public function fetchNumeric();

/**
* @return array<string, __benevolent<float|int|string|null>>|false
*/
public function fetchAssociative();

/**
* @return __benevolent<float|int|string|false|null>
*/
public function fetchOne();

/**
* @return list<list<__benevolent<float|int|string|null>>>
*/
public function fetchAllNumeric(): array;

/**
* @return list<array<string, __benevolent<float|int|string|null>>>
*/
public function fetchAllAssociative(): array;

/**
* @return array<mixed, __benevolent<float|int|string|null>>
*/
public function fetchAllKeyValue(): array;

/**
* @return array<mixed,array<string, __benevolent<float|int|string|null>>>
*/
public function fetchAllAssociativeIndexed(): array;

/**
* @return list<__benevolent<float|int|string|null>>
*/
public function fetchFirstColumn(): array;

/**
* @return Traversable<int, list<__benevolent<float|int|string|null>>>
*/
public function iterateNumeric(): Traversable;

/**
* @return Traversable<int, array<string, __benevolent<float|int|string|null>>>
*/
public function iterateAssociative(): Traversable;

/**
* @return Traversable<__benevolent<float|int|string|null>, __benevolent<float|int|string|null>>
*/
public function iterateKeyValue(): Traversable;

/**
* @return Traversable<__benevolent<float|int|string|null>, array<string, __benevolent<float|int|string|null>>>
*/
public function iterateAssociativeIndexed(): Traversable;

/**
* @return Traversable<int, __benevolent<float|int|string|null>>
*/
public function iterateColumn(): Traversable;

public function rowCount(): int;

public function columnCount(): int;

public function free(): void;

/**
* @deprecated Use {@see fetchNumeric()}, {@see fetchAssociative()} or {@see fetchOne()} instead.
*
* @phpstan-param FetchMode::* $mode
* @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>))
*/
public function fetch(int $mode = FetchMode::ASSOCIATIVE);

/**
* @deprecated Use {@see fetchAllNumeric()}, {@see fetchAllAssociative()} or {@see fetchOne()} instead.
*
* @phpstan-param FetchMode::* $mode
* @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>>))
*/
public function fetchAll(int $mode = FetchMode::ASSOCIATIVE): array;
}

0 comments on commit 1e59c4e

Please sign in to comment.