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

tempestphp / tempest-framework / 14049246919

24 Mar 2025 09:42PM UTC coverage: 79.353% (-0.04%) from 79.391%
14049246919

push

github

web-flow
feat(support): support array parameters in string manipulations (#1073)

48 of 48 new or added lines in 2 files covered. (100.0%)

735 existing lines in 126 files now uncovered.

10492 of 13222 relevant lines covered (79.35%)

90.78 hits per line

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

92.5
/src/Tempest/Database/src/GenericDatabase.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Tempest\Database;
6

7
use BackedEnum;
8
use DateTimeInterface;
9
use PDO;
10
use PDOException;
11
use Tempest\Database\Connection\Connection;
12
use Tempest\Database\Exceptions\QueryException;
13
use Tempest\Database\Transactions\TransactionManager;
14
use Throwable;
15

16
final readonly class GenericDatabase implements Database
17
{
18
    public function __construct(
660✔
19
        private Connection $connection,
20
        private TransactionManager $transactionManager,
21
    ) {}
660✔
22

23
    public function execute(Query $query): void
658✔
24
    {
25
        $bindings = $this->resolveBindings($query);
658✔
26

27
        try {
28
            $this->connection
658✔
29
                ->prepare($query->getSql())
658✔
30
                ->execute($bindings);
658✔
31
        } catch (PDOException $pdoException) {
2✔
32
            throw new QueryException($query, $bindings, $pdoException);
2✔
33
        }
34
    }
35

36
    public function getLastInsertId(): Id
658✔
37
    {
38
        return new Id($this->connection->lastInsertId());
658✔
39
    }
40

41
    public function fetch(Query $query): array
658✔
42
    {
43
        $pdoQuery = $this->connection->prepare($query->getSql());
658✔
44

45
        $pdoQuery->execute($this->resolveBindings($query));
658✔
46

47
        return $pdoQuery->fetchAll(PDO::FETCH_NAMED);
658✔
48
    }
49

50
    public function fetchFirst(Query $query): ?array
1✔
51
    {
52
        return $this->fetch($query)[0] ?? null;
1✔
53
    }
54

55
    public function withinTransaction(callable $callback): bool
4✔
56
    {
57
        $this->transactionManager->begin();
4✔
58

59
        try {
60
            $callback();
4✔
61

62
            $this->transactionManager->commit();
2✔
63
        } catch (PDOException) {
2✔
UNCOV
64
            return false;
×
65
        } catch (Throwable) {
2✔
66
            $this->transactionManager->rollback();
2✔
67

68
            return false;
2✔
69
        }
70

71
        return true;
2✔
72
    }
73

74
    private function resolveBindings(Query $query): array
658✔
75
    {
76
        $bindings = [];
658✔
77

78
        foreach ($query->bindings as $key => $value) {
658✔
79
            if ($value instanceof Id) {
57✔
80
                $value = $value->id;
24✔
81
            }
82

83
            if ($value instanceof Query) {
57✔
84
                $value = $value->execute();
22✔
85
            }
86

87
            if ($value instanceof BackedEnum) {
57✔
UNCOV
88
                $value = $value->value;
×
89
            }
90

91
            if ($value instanceof DateTimeInterface) {
57✔
UNCOV
92
                $value = $value->format('Y-m-d H:i:s');
×
93
            }
94

95
            $bindings[$key] = $value;
57✔
96
        }
97

98
        return $bindings;
658✔
99
    }
100
}
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