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

tempestphp / tempest-framework / 14140550176

28 Mar 2025 10:29PM UTC coverage: 80.716% (+1.4%) from 79.334%
14140550176

push

github

web-flow
feat(support): support `$default` on array `first` and `last` methods (#1096)

11 of 12 new or added lines in 2 files covered. (91.67%)

135 existing lines in 16 files now uncovered.

10941 of 13555 relevant lines covered (80.72%)

100.32 hits per line

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

90.0
/src/Tempest/Database/src/Query.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Tempest\Database;
6

7
use Tempest\Database\Config\DatabaseConfig;
8

9
use function Tempest\get;
10

11
final class Query
12
{
13
    public function __construct(
705✔
14
        public string|QueryStatement $sql,
15
        public array $bindings = [],
16
    ) {}
705✔
17

18
    public function execute(mixed ...$bindings): Id
705✔
19
    {
20
        $this->bindings = [...$this->bindings, ...$bindings];
705✔
21

22
        $database = $this->getDatabase();
705✔
23

24
        $query = $this->withBindings($bindings);
705✔
25

26
        $database->execute($query);
705✔
27

28
        // TODO: add support for "after" queries to attach hasMany relations
29

30
        return isset($query->bindings['id'])
705✔
31
            ? new Id($query->bindings['id'])
2✔
32
            : $database->getLastInsertId();
705✔
33
    }
34

35
    public function fetch(mixed ...$bindings): array
705✔
36
    {
37
        return $this->getDatabase()->fetch($this->withBindings($bindings));
705✔
38
    }
39

40
    public function fetchFirst(mixed ...$bindings): ?array
1✔
41
    {
42
        return $this->getDatabase()->fetchFirst($this->withBindings($bindings));
1✔
43
    }
44

45
    public function getSql(): string
705✔
46
    {
47
        $sql = $this->sql;
705✔
48

49
        if ($sql instanceof QueryStatement) {
705✔
50
            return $sql->compile($this->getDatabaseConfig()->dialect);
87✔
51
        }
52

53
        return $sql;
705✔
54
    }
55

UNCOV
56
    public function append(string $append): self
×
57
    {
UNCOV
58
        $this->sql .= PHP_EOL . $append;
×
59

UNCOV
60
        return $this;
×
61
    }
62

63
    public function withBindings(array $bindings): self
705✔
64
    {
65
        $clone = clone $this;
705✔
66

67
        $clone->bindings = [...$clone->bindings, ...$bindings];
705✔
68

69
        return $clone;
705✔
70
    }
71

72
    private function getDatabase(): Database
705✔
73
    {
74
        return get(Database::class);
705✔
75
    }
76

77
    private function getDatabaseConfig(): DatabaseConfig
87✔
78
    {
79
        return get(DatabaseConfig::class);
87✔
80
    }
81
}
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

© 2025 Coveralls, Inc