Skip to content

Commit d881fcf

Browse files
chore: refactor getUserInfo to AbstractAuditLog
1 parent 29fca86 commit d881fcf

File tree

4 files changed

+17
-51
lines changed

4 files changed

+17
-51
lines changed

app/Audit/AbstractAuditLogFormatter.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,22 @@ final public function setContext(AuditContext $ctx): void
2424
$this->ctx = $ctx;
2525
}
2626

27+
protected function getUserInfo(): string
28+
{
29+
if (!$this->ctx) {
30+
return 'Unknown (unknown)';
31+
}
32+
33+
$user_name = 'Unknown';
34+
if ($this->ctx->userFirstName || $this->ctx->userLastName) {
35+
$user_name = trim(sprintf("%s %s", $this->ctx->userFirstName ?? '', $this->ctx->userLastName ?? '')) ?: 'Unknown';
36+
} elseif ($this->ctx->userEmail) {
37+
$user_name = $this->ctx->userEmail;
38+
}
39+
40+
$user_id = $this->ctx->userId ?? 'unknown';
41+
return sprintf("%s (%s)", $user_name, $user_id);
42+
}
43+
2744
abstract public function format($subject, array $change_set): ?string;
2845
}

app/Audit/ConcreteFormatters/PresentationTrackChairRatingTypeAuditLogFormatter.php

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,6 @@ public function __construct(string $event_type)
2929
$this->event_type = $event_type;
3030
}
3131

32-
private function getUserInfo(): string
33-
{
34-
if (!$this->ctx) {
35-
return 'Unknown (unknown)';
36-
}
37-
38-
$user_name = 'Unknown';
39-
if ($this->ctx->userFirstName || $this->ctx->userLastName) {
40-
$user_name = trim(sprintf("%s %s", $this->ctx->userFirstName ?? '', $this->ctx->userLastName ?? '')) ?: 'Unknown';
41-
} elseif ($this->ctx->userEmail) {
42-
$user_name = $this->ctx->userEmail;
43-
}
44-
45-
$user_id = $this->ctx->userId ?? 'unknown';
46-
return sprintf("%s (%s)", $user_name, $user_id);
47-
}
48-
4932
public function format($subject, array $change_set): ?string
5033
{
5134
if (!$subject instanceof PresentationTrackChairRatingType) {

app/Audit/ConcreteFormatters/PresentationTrackChairScoreTypeAuditLogFormatter.php

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,6 @@ public function __construct(string $event_type)
2929
$this->event_type = $event_type;
3030
}
3131

32-
private function getUserInfo(): string
33-
{
34-
if (!$this->ctx) {
35-
return 'Unknown (unknown)';
36-
}
37-
38-
$user_name = 'Unknown';
39-
if ($this->ctx->userFirstName || $this->ctx->userLastName) {
40-
$user_name = trim(sprintf("%s %s", $this->ctx->userFirstName ?? '', $this->ctx->userLastName ?? '')) ?: 'Unknown';
41-
} elseif ($this->ctx->userEmail) {
42-
$user_name = $this->ctx->userEmail;
43-
}
44-
45-
$user_id = $this->ctx->userId ?? 'unknown';
46-
return sprintf("%s (%s)", $user_name, $user_id);
47-
}
48-
4932
public function format($subject, array $change_set): ?string
5033
{
5134
if (!$subject instanceof PresentationTrackChairScoreType) {

app/Audit/ConcreteFormatters/SummitTrackChairAuditLogFormatter.php

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,6 @@ public function __construct(string $event_type)
2929
$this->event_type = $event_type;
3030
}
3131

32-
private function getUserInfo(): string
33-
{
34-
if (!$this->ctx) {
35-
return 'Unknown (unknown)';
36-
}
37-
38-
$user_name = 'Unknown';
39-
if ($this->ctx->userFirstName || $this->ctx->userLastName) {
40-
$user_name = trim(sprintf("%s %s", $this->ctx->userFirstName ?? '', $this->ctx->userLastName ?? '')) ?: 'Unknown';
41-
} elseif ($this->ctx->userEmail) {
42-
$user_name = $this->ctx->userEmail;
43-
}
44-
45-
$user_id = $this->ctx->userId ?? 'unknown';
46-
return sprintf("%s (%s)", $user_name, $user_id);
47-
}
48-
4932
public function format($subject, array $change_set): ?string
5033
{
5134
if (!$subject instanceof SummitTrackChair) {

0 commit comments

Comments
 (0)