• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

brick / lock / 17475241346

04 Sep 2025 07:59PM UTC coverage: 5.5%. Remained the same
17475241346

push

github

BenMorel
Apply coding standard

11 of 200 relevant lines covered (5.5%)

3.8 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/Database/Connection/PdoConnection.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Brick\Lock\Database\Connection;
6

7
use Brick\Lock\Database\ConnectionInterface;
8
use Brick\Lock\Database\QueryException;
9
use Override;
10
use PDO;
11
use PDOException;
12

13
use function count;
14
use function sprintf;
15

16
/**
17
 * Wraps a PDO connection.
18
 */
19
final readonly class PdoConnection implements ConnectionInterface
20
{
21
    public function __construct(
22
        private PDO $pdo,
23
    ) {
24
    }
×
25

26
    #[Override]
27
    public function querySingleValue(string $sql, array $params = []): mixed
28
    {
29
        /** @phpstan-ignore missingType.checkedException */
30
        $previousErrorMode = $this->pdo->getAttribute(PDO::ATTR_ERRMODE);
×
31

32
        /** @phpstan-ignore missingType.checkedException */
33
        $this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
×
34

35
        try {
36
            $statement = $this->pdo->prepare($sql);
×
37
            $statement->execute($params);
×
38

39
            /** @var list<list<scalar|null>> $rows */
40
            $rows = $statement->fetchAll(PDO::FETCH_NUM);
×
41
        } catch (PDOException $e) {
×
42
            throw new QueryException(sprintf('An error occurred while executing the query "%s"', $sql), $e);
×
43
        } finally {
44
            /** @phpstan-ignore missingType.checkedException */
45
            $this->pdo->setAttribute(PDO::ATTR_ERRMODE, $previousErrorMode);
×
46
        }
47

48
        if (count($rows) !== 1) {
×
49
            throw new QueryException(sprintf('Query "%s" returned %d rows, expected 1.', $sql, count($rows)));
×
50
        }
51

52
        $columns = $rows[0];
×
53

54
        if (count($columns) !== 1) {
×
55
            throw new QueryException(sprintf('Query "%s" returned %d columns, expected 1.', $sql, count($columns)));
×
56
        }
57

58
        /** @var scalar|null */
59
        return $columns[0];
×
60
    }
61

62
    #[Override]
63
    public function beginTransaction(): void
64
    {
65
        $this->pdo->beginTransaction();
×
66
    }
67

68
    #[Override]
69
    public function commit(): void
70
    {
71
        $this->pdo->commit();
×
72
    }
73

74
    #[Override]
75
    public function rollBack(): void
76
    {
77
        $this->pdo->rollBack();
×
78
    }
79
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc