Failed Conditions
Pull Request — master (#4007)
by Sergei
11:47
created

FetchUtils::iterateColumnByOne()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 2
nc 2
nop 1
dl 0
loc 4
ccs 0
cts 3
cp 0
crap 6
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 1830
    public static function fetchOneFromNumeric(ResultStatement $stmt)
20
    {
21 1830
        $row = $stmt->fetchNumeric();
22
23 1830
        if ($row === false) {
24 148
            return false;
25
        }
26
27 1776
        return $row[0];
28
    }
29
30
    /**
31
     * @return array<int,array<int,mixed>>
32
     *
33
     * @throws DriverException
34
     */
35 16
    public static function fetchAllNumericByOne(ResultStatement $stmt) : array
36
    {
37 16
        $rows = [];
38
39 16
        while (($row = $stmt->fetchNumeric()) !== false) {
40 16
            $rows[] = $row;
41
        }
42
43 16
        return $rows;
44
    }
45
46
    /**
47
     * @return array<int,array<string,mixed>>
48
     *
49
     * @throws DriverException
50
     */
51 951
    public static function fetchAllAssociativeByOne(ResultStatement $stmt) : array
52
    {
53 951
        $rows = [];
54
55 951
        while (($row = $stmt->fetchAssociative()) !== false) {
56 881
            $rows[] = $row;
57
        }
58
59 951
        return $rows;
60
    }
61
62
    /**
63
     * @return array<int,mixed>
64
     *
65
     * @throws DriverException
66
     */
67 94
    public static function fetchColumnByOne(ResultStatement $stmt) : array
68
    {
69 94
        $rows = [];
70
71 94
        while (($row = $stmt->fetchOne()) !== false) {
72 94
            $rows[] = $row;
73
        }
74
75 94
        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 53
    public static function iterateAssociativeByOne(ResultStatement $stmt) : Traversable
96
    {
97 53
        while (($row = $stmt->fetchAssociative()) !== false) {
98 53
            yield $row;
99
        }
100 53
    }
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->fetchOne()) !== false) {
110
            yield $row;
111
        }
112
    }
113
}
114