Passed
Pull Request — main (#122)
by Andreas
02:21
created

Result::fetchAllNumeric()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Crate\DBAL\Driver\PDOCrate;
6
7
use Doctrine\DBAL\Driver\FetchUtils;
8
use Doctrine\DBAL\Driver\Result as ResultInterface;
9
use PDO;
10
use PDOException;
11
12
final class Result implements ResultInterface
13
{
14
    private CrateStatement $statement;
15
16
    /** @internal The result can be only instantiated by its driver connection or statement. */
17
    public function __construct(CrateStatement $statement)
18
    {
19
        $this->statement = $statement;
20
    }
21
22
    /**
23
     * {@inheritDoc}
24
     */
25
    public function fetchNumeric()
26
    {
27
        return $this->fetch(PDO::FETCH_NUM);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->fetch(PDO::FETCH_NUM) also could return the type array|boolean|stdClass which is incompatible with the return type mandated by Doctrine\DBAL\Driver\Result::fetchNumeric() of Doctrine\DBAL\Driver\list.
Loading history...
28
    }
29
30
    /**
31
     * {@inheritDoc}
32
     */
33
    public function fetchAssociative()
34
    {
35
        return $this->fetch(PDO::FETCH_ASSOC);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->fetch(PDO::FETCH_ASSOC) also could return the type boolean|stdClass which is incompatible with the return type mandated by Doctrine\DBAL\Driver\Result::fetchAssociative() of array<string,mixed>|false.
Loading history...
36
    }
37
38
    /**
39
     * {@inheritDoc}
40
     */
41
    public function fetchOne()
42
    {
43
        return FetchUtils::fetchOne($this);
44
    }
45
46
    /**
47
     * {@inheritDoc}
48
     */
49
    public function fetchAllNumeric(): array
50
    {
51
        return FetchUtils::fetchAllNumeric($this);
52
    }
53
54
    /**
55
     * {@inheritDoc}
56
     */
57
    public function fetchAllAssociative(): array
58
    {
59
        return FetchUtils::fetchAllAssociative($this);
60
    }
61
62
    /**
63
     * {@inheritDoc}
64
     */
65
    public function fetchFirstColumn(): array
66
    {
67
        return FetchUtils::fetchFirstColumn($this);
68
    }
69
70
    public function rowCount(): int
71
    {
72
        try {
73
            return $this->statement->rowCount();
74
        } catch (PDOException $exception) {
75
            throw Exception::new($exception);
76
        }
77
    }
78
79
    public function columnCount(): int
80
    {
81
        try {
82
            return $this->statement->columnCount();
83
        } catch (PDOException $exception) {
84
            throw Exception::new($exception);
85
        }
86
    }
87
88
    public function free(): void
89
    {
90
        $this->statement->closeCursor();
91
    }
92
93
    /**
94
     * @phpstan-param PDO::FETCH_* $mode
95
     *
96
     * @return mixed
97
     *
98
     * @throws Exception
99
     */
100
    private function fetch(int $mode)
101
    {
102
        try {
103
            return $this->statement->fetch($mode);
104
        } catch (PDOException $exception) {
105
            throw Exception::new($exception);
106
        }
107
    }
108
}
109