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

tempestphp / tempest-framework / 14024978163

23 Mar 2025 05:55PM UTC coverage: 79.391% (-0.05%) from 79.441%
14024978163

push

github

web-flow
feat(view): cache Blade and Twig templates in internal storage (#1061)

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

912 existing lines in 110 files now uncovered.

10478 of 13198 relevant lines covered (79.39%)

91.09 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(
659✔
19
        private Connection $connection,
20
        private TransactionManager $transactionManager,
21
    ) {
22
    }
659✔
23

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

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

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

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

46
        $pdoQuery->execute($this->resolveBindings($query));
657✔
47

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

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

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

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

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

69
            return false;
2✔
70
        }
71

72
        return true;
2✔
73
    }
74

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

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

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

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

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

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

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