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

tempestphp / tempest-framework / 14662303859

25 Apr 2025 10:16AM UTC coverage: 80.225% (+0.006%) from 80.219%
14662303859

Pull #1174

github

web-flow
Merge 32bf6b4f8 into be8067395
Pull Request #1174: feat(database): add `Count` query builder and statement

49 of 60 new or added lines in 3 files covered. (81.67%)

11834 of 14751 relevant lines covered (80.23%)

106.45 hits per line

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

81.82
/src/Tempest/Database/src/QueryStatements/CountStatement.php
1
<?php
2

3
namespace Tempest\Database\QueryStatements;
4

5
use Tempest\Database\Builder\TableDefinition;
6
use Tempest\Database\Config\DatabaseDialect;
7
use Tempest\Database\QueryStatement;
8
use Tempest\Support\Arr\ImmutableArray;
9

10
use function Tempest\Support\arr;
11

12
final class CountStatement implements QueryStatement
13
{
14
    public readonly string $countArgument;
15

16
    public ?string $alias = null;
17

18
    public function __construct(
8✔
19
        public readonly TableDefinition $table,
20
        public ?string $column = null,
21
        public ImmutableArray $where = new ImmutableArray(),
22
    ) {
23
        $this->countArgument = $this->column === null
8✔
24
            ? '*'
6✔
25
            : "`{$this->column}`";
2✔
26
    }
27

28
    public function compile(DatabaseDialect $dialect): string
8✔
29
    {
30
        $query = arr([
8✔
31
            sprintf(
8✔
32
                'SELECT COUNT(%s)%s',
8✔
33
                $this->countArgument,
8✔
34
                $this->alias ? " AS `{$this->alias}`" : '',
8✔
35
            ),
8✔
36
            sprintf('FROM `%s`', $this->table->name),
8✔
37
        ]);
8✔
38

39
        if ($this->where->isNotEmpty()) {
8✔
40
            $query[] = 'WHERE ' . $this->where
3✔
41
                ->map(fn (WhereStatement $where) => $where->compile($dialect))
3✔
42
                ->implode(PHP_EOL);
3✔
43
        }
44

45
        return $query->implode(PHP_EOL);
8✔
46
    }
47

NEW
48
    public function getKey(): string
×
49
    {
NEW
50
        if ($this->alias !== null) {
×
NEW
51
            return $this->alias;
×
52
        }
53

NEW
54
        return "COUNT({$this->countArgument})";
×
55
    }
56
}
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