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

FetchUtils   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 99
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 23
dl 0
loc 99
rs 10
c 1
b 0
f 0
wmc 14

7 Methods

Rating   Name   Duplication   Size   Complexity  
A fetchAllAssociative() 0 9 2
A fetchAllNumeric() 0 9 2
A iterateColumn() 0 4 2
A iterateAssociative() 0 4 2
A fetchOne() 0 9 2
A iterateNumeric() 0 4 2
A fetchColumn() 0 9 2
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 fetchOne(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 fetchAllNumeric(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 fetchAllAssociative(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 fetchColumn(ResultStatement $stmt) : array
68
    {
69
        $rows = [];
70
71
        while (($row = $stmt->fetchOne()) !== 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 iterateNumeric(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 iterateAssociative(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 iterateColumn(ResultStatement $stmt) : Traversable
108
    {
109
        while (($row = $stmt->fetchOne()) !== false) {
110
            yield $row;
111
        }
112
    }
113
}
114