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

Result   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 94
Duplicated Lines 0 %

Test Coverage

Coverage 64.29%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 14
eloc 22
c 1
b 0
f 0
dl 0
loc 94
ccs 18
cts 28
cp 0.6429
rs 10

11 Methods

Rating   Name   Duplication   Size   Complexity  
A rowCount() 0 6 2
A fetchAllAssociative() 0 3 1
A fetchAllNumeric() 0 3 1
A fetchAssociative() 0 3 1
A fetchNumeric() 0 3 1
A columnCount() 0 6 2
A fetchOne() 0 3 1
A free() 0 3 1
A __construct() 0 3 1
A fetch() 0 6 2
A fetchFirstColumn() 0 3 1
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 108
    public function __construct(CrateStatement $statement)
18
    {
19 108
        $this->statement = $statement;
20
    }
21
22
    /**
23
     * {@inheritDoc}
24
     */
25 28
    public function fetchNumeric()
26
    {
27 28
        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 56
    public function fetchAssociative()
34
    {
35 56
        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 20
    public function fetchOne()
42
    {
43 20
        return FetchUtils::fetchOne($this);
44
    }
45
46
    /**
47
     * {@inheritDoc}
48
     */
49 4
    public function fetchAllNumeric(): array
50
    {
51 4
        return FetchUtils::fetchAllNumeric($this);
52
    }
53
54
    /**
55
     * {@inheritDoc}
56
     */
57 44
    public function fetchAllAssociative(): array
58
    {
59 44
        return FetchUtils::fetchAllAssociative($this);
60
    }
61
62
    /**
63
     * {@inheritDoc}
64
     */
65 2
    public function fetchFirstColumn(): array
66
    {
67 2
        return FetchUtils::fetchFirstColumn($this);
68
    }
69
70 90
    public function rowCount(): int
71
    {
72
        try {
73 90
            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 74
    private function fetch(int $mode)
101
    {
102
        try {
103 74
            return $this->statement->fetch($mode);
104
        } catch (PDOException $exception) {
105
            throw Exception::new($exception);
106
        }
107
    }
108
}
109