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

ericfortmeyer / activity-log / 20420404465

22 Dec 2025 03:01AM UTC coverage: 51.874% (-1.6%) from 53.429%
20420404465

push

github

web-flow
fix: add tenant id to all post requests (#60)

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

17 of 49 new or added lines in 10 files covered. (34.69%)

2 existing lines in 2 files now uncovered.

346 of 667 relevant lines covered (51.87%)

1.62 hits per line

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

62.79
/src/Http/RequestProcessors/GetTimeEntries.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace EricFortmeyer\ActivityLog\Http\RequestProcessors;
6

7
use Phpolar\Phpolar\Auth\{
8
    Authorize
9
};
10
use Phpolar\{
11
    Model\Model,
12
    PurePhp\TemplateEngine,
13
    PurePhp\HtmlSafeContext,
14
    Storage\NotFound
15
};
16
use EricFortmeyer\ActivityLog\{RemarksForMonth, MonthFilters, CreditHours, Tenant, TimeEntry};
17
use EricFortmeyer\ActivityLog\Services\{RemarksForMonthService, CreditHoursService, TenantService, TimeEntryService};
18
use EricFortmeyer\ActivityLog\UserInterface\Contexts\{TimeEntriesContext, BadRequestContext};
19
use EricFortmeyer\ActivityLog\Utils\Hasher;
20

21
/**
22
 * Class GetTimeEntries
23
 *
24
 * @package EricFortmeyer\ActivityLog
25
 */
26
final class GetTimeEntries extends AbstractTenantBasedRequestProcessor
27
{
28
    public function __construct(
29
        private readonly TenantService $tenantService,
30
        private readonly TimeEntryService $timeEntryService,
31
        private readonly RemarksForMonthService $remarksForMonthService,
32
        private readonly CreditHoursService $creditHoursService,
33
        private readonly TemplateEngine $templateEngine,
34
        readonly Hasher $hasher,
35
    ) {
36
        parent::__construct($hasher);
2✔
37
    }
38

39
    /**
40
     * Process the request to get all time entries.
41
     *
42
     * @return string The rendered template
43
     */
44
    #[Authorize]
45
    public function process(
46
        #[Model] TimeEntry $timeEntry = new TimeEntry(),
47
        #[Model] MonthFilters $monthFilters = new MonthFilters(),
48
    ): string {
49
        if ($monthFilters->isValid() === false) {
2✔
50
            return (string) $this->templateEngine->apply(
×
51
                "400",
×
52
                new HtmlSafeContext(
×
53
                    new BadRequestContext(message: "Something is wrong with the request.")
×
54
                )
×
55
            );
×
56
        }
57

58
        $this->initTenantIfNotExists();
2✔
59

60
        $timeEntry->tenantId ??= $this->getTenantId();
2✔
61
        $month = $monthFilters->getMonth();
2✔
62
        $year = $monthFilters->getYear();
2✔
63
        TimeEntry::setUninitializedValues(timeEntry: $timeEntry, month: $month, year: $year);
2✔
64
        $timeEntries = $this->timeEntryService->getAllByMonth(
2✔
65
            month: $month,
2✔
66
            year: $year,
2✔
67
            tenantId: $this->getTenantId(),
2✔
68
        );
2✔
69
        $remarks = $this->remarksForMonthService->get(RemarksForMonth::getIdFromMonth(
2✔
70
            month: $month,
2✔
71
            year: $year,
2✔
72
            tenantId: $this->getTenantId(),
2✔
73
        ));
2✔
74
        $creditHours = $this->creditHoursService->get(CreditHours::getIdFromMonth(
2✔
75
            month: $month,
2✔
76
            year: $year,
2✔
77
            tenantId: $this->getTenantId(),
2✔
78
        ));
2✔
79
        return (string) $this->templateEngine->apply(
2✔
80
            "index",
2✔
81
            new HtmlSafeContext(
2✔
82
                $this->getContext(
2✔
83
                    timeEntries: $timeEntries,
2✔
84
                    timeEntry: $timeEntry,
2✔
85
                    monthFilters: $monthFilters,
2✔
86
                    remarks: $remarks,
2✔
87
                    creditHours: $creditHours,
2✔
88
                )
2✔
89
            ),
2✔
90
        );
2✔
91
    }
92

93
    /**
94
     * @param TimeEntry[] $timeEntries
95
     */
96
    private function getContext(
97
        array $timeEntries,
98
        TimeEntry $timeEntry,
99
        MonthFilters $monthFilters,
100
        RemarksForMonth| NotFound $remarks,
101
        CreditHours|NotFound $creditHours,
102
    ): TimeEntriesContext {
103
        return match (true) {
2✔
104
            $remarks instanceof NotFound && $creditHours instanceof NotFound =>
2✔
105
            new TimeEntriesContext(
2✔
106
                timeEntries: $timeEntries,
2✔
107
                tenantId: $this->getTenantId(),
2✔
108
                currentEntry: $timeEntry,
2✔
109
                filters: $monthFilters,
2✔
110
                user: $this->user
2✔
111
            ),
2✔
112
            $creditHours instanceof CreditHours && $remarks instanceof RemarksForMonth =>
2✔
113
            new TimeEntriesContext(
×
114
                timeEntries: $timeEntries,
×
NEW
115
                tenantId: $this->getTenantId(),
×
116
                currentEntry: $timeEntry,
×
117
                filters: $monthFilters,
×
118
                remarks: $remarks,
×
119
                creditHours: $creditHours,
×
120
                user: $this->user
×
121
            ),
×
122
            $creditHours instanceof CreditHours && $remarks instanceof NotFound =>
2✔
123
            new TimeEntriesContext(
×
124
                timeEntries: $timeEntries,
×
NEW
125
                tenantId: $this->getTenantId(),
×
126
                currentEntry: $timeEntry,
×
127
                filters: $monthFilters,
×
128
                creditHours: $creditHours,
×
129
                user: $this->user,
×
130
            ),
×
131
            $remarks instanceof RemarksForMonth && $creditHours instanceof NotFound =>
2✔
132
            new TimeEntriesContext(
×
133
                timeEntries: $timeEntries,
×
NEW
134
                tenantId: $this->getTenantId(),
×
135
                currentEntry: $timeEntry,
×
136
                filters: $monthFilters,
×
137
                remarks: $remarks,
×
138
                user: $this->user
×
139
            ),
×
140
            default =>
2✔
141
            new TimeEntriesContext(user: $this->user, tenantId: $this->getTenantId())
2✔
142
        };
2✔
143
    }
144

145

146
    private function initTenantIfNotExists(): void
147
    {
148
        $tenantId = $this->getTenantId();
2✔
149

150
        if ($this->tenantService->exists($tenantId) === true) {
2✔
151
            return;
×
152
        }
153

154
        $this->tenantService->save(
2✔
155
            new Tenant(["id" => $tenantId])
2✔
156
        );
2✔
157
    }
158
}
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