Failed Conditions
Pull Request — master (#4007)
by Sergei
62:50
created

FetchUtils::iterateAssociativeByOne()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 2
nc 2
nop 1
dl 0
loc 4
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\DBAL\Driver;
6
7
use Traversable;
8
9
/**
10
 * @internal
11
 */
12
final class FetchUtils
13
{
14
    /**
15
     * @return mixed|false
16
     *
17
     * @throws DriverException
18
     */
19
    public static function fetchColumnFromNumeric(ResultStatement $stmt)
20
    {
21
        $row = $stmt->fetchNumeric();
22
23
        if ($row === false) {
24
            return false;
25
        }
26
27
        return $row[0];
28
    }
29
30
    /**
31
     * @return array<int,array<int,mixed>>
32
     *
33
     * @throws DriverException
34
     */
35
    public static function fetchAllNumericByOne(ResultStatement $stmt) : array
36
    {
37
        $rows = [];
38
39
        while (($row = $stmt->fetchNumeric()) !== false) {
40
            $rows[] = $row;
41
        }
42
43
        return $rows;
44
    }
45
46
    /**
47
     * @return array<int,array<string,mixed>>
48
     *
49
     * @throws DriverException
50
     */
51
    public static function fetchAllAssociativeByOne(ResultStatement $stmt) : array
52
    {
53
        $rows = [];
54
55
        while (($row = $stmt->fetchAssociative()) !== false) {
56
            $rows[] = $row;
57
        }
58
59
        return $rows;
60
    }
61
62
    /**
63
     * @return array<int,mixed>
64
     *
65
     * @throws DriverException
66
     */
67
    public static function fetchAllColumnByOne(ResultStatement $stmt) : array
68
    {
69
        $rows = [];
70
71
        while (($row = $stmt->fetchColumn()) !== false) {
72
            $rows[] = $row;
73
        }
74
75
        return $rows;
76
    }
77
78
    /**
79
     * @return Traversable<int,array<int,mixed>>
80
     *
81
     * @throws DriverException
82
     */
83
    public static function iterateNumericByOne(ResultStatement $stmt) : Traversable
84
    {
85
        while (($row = $stmt->fetchNumeric()) !== false) {
86
            yield $row;
87
        }
88
    }
89
90
    /**
91
     * @return Traversable<int,array<string,mixed>>
92
     *
93
     * @throws DriverException
94
     */
95
    public static function iterateAssociativeByOne(ResultStatement $stmt) : Traversable
96
    {
97
        while (($row = $stmt->fetchAssociative()) !== false) {
98
            yield $row;
99
        }
100
    }
101
102
    /**
103
     * @return Traversable<int,mixed>
104
     *
105
     * @throws DriverException
106
     */
107
    public static function iterateColumnByOne(ResultStatement $stmt) : Traversable
108
    {
109
        while (($row = $stmt->fetchColumn()) !== false) {
110
            yield $row;
111
        }
112
    }
113
}
114