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

ericfortmeyer / activity-log / 20394701678

20 Dec 2025 12:56PM UTC coverage: 53.429% (-2.1%) from 55.481%
20394701678

push

github

web-flow
feat: create tenant if not exists (#59)

Signed-off-by: Eric Fortmeyer <e.fortmeyer01@gmail.com>

6 of 34 new or added lines in 2 files covered. (17.65%)

335 of 627 relevant lines covered (53.43%)

1.57 hits per line

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

0.0
/src/Services/TenantService.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace EricFortmeyer\ActivityLog\Services;
6

7
use EricFortmeyer\ActivityLog\Tenant;
8
use PDO;
9

10
/**
11
 * Handle tenant storage operations
12
 *
13
 * We are not using a StorageContext
14
 * here because the library does not
15
 * currently support single column
16
 * tables.
17
 */
18
readonly class TenantService
19
{
20
    public function __construct(
21
        private PDO $connection,
22
    )
23
    {
NEW
24
    }
×
25

26
    public function exists(string $tenantId): bool
27
    {
NEW
28
        $exists = false;
×
29

NEW
30
        $stmt = $this->connection->prepare(
×
NEW
31
            <<<SQL
×
32
            SELECT EXISTS (
33
                SELECT 1 FROM `tenant` WHERE `id`=:id LIMIT 1
34
            )
NEW
35
            SQL,
×
NEW
36
        );
×
37

NEW
38
        if ($stmt === false) {
×
NEW
39
            return false;
×
40
        }
41

NEW
42
        $stmt->bindColumn(1, $exists, PDO::PARAM_BOOL);
×
NEW
43
        $stmt->execute(["id" => $tenantId]);
×
NEW
44
        $stmt->fetch();
×
45

NEW
46
        return $exists;
×
47
    }
48

49
    /**
50
     * @return Tenant[]
51
     */
52
    public function getAll(): array
53
    {
NEW
54
        $stmt = $this->connection->query(
×
NEW
55
            <<<SQL
×
56
            TABLE `tenant`;
NEW
57
            SQL,
×
NEW
58
            PDO::FETCH_CLASS
×
NEW
59
        );
×
60

NEW
61
        if ($stmt === false) {
×
NEW
62
            return [];
×
63
        }
64

NEW
65
        return $stmt->fetchAll();
×
66
    }
67

68
    public function save(Tenant $tenant): void
69
    {
NEW
70
        $stmt = $this->connection->prepare(
×
NEW
71
            <<<SQL
×
72
            INSERT INTO `tenant`
73
            VALUES(:id)
NEW
74
            SQL,
×
NEW
75
        );
×
76

NEW
77
        if ($stmt === false) {
×
NEW
78
            return;
×
79
        }
80

NEW
81
        $stmt->execute(["id" => $tenant->getPrimaryKey()]);
×
82
    }
83
}
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