Skip to content

Commit d733ddf

Browse files
committed
refactor: replace if-empty blocks with array_filter in createCheckRun
1 parent f5fe277 commit d733ddf

1 file changed

Lines changed: 17 additions & 25 deletions

File tree

src/VCS/Adapter/Git/GitHub.php

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -896,35 +896,27 @@ public function createCheckRun(
896896
): array {
897897
$url = "/repos/$owner/$repositoryName/check-runs";
898898

899-
$body = [
900-
'name' => $name,
901-
'head_sha' => $headSha,
902-
'status' => $status,
903-
];
899+
$body = array_merge(
900+
[
901+
'name' => $name,
902+
'head_sha' => $headSha,
903+
'status' => $status,
904+
],
905+
array_filter([
906+
'details_url' => $detailsUrl,
907+
'external_id' => $externalId,
908+
'started_at' => $startedAt,
909+
'conclusion' => $conclusion,
910+
'completed_at' => $completedAt,
911+
], fn ($value) => !empty($value))
912+
);
904913

905-
if (!empty($detailsUrl)) {
906-
$body['details_url'] = $detailsUrl;
907-
}
908-
if (!empty($externalId)) {
909-
$body['external_id'] = $externalId;
910-
}
911-
if (!empty($startedAt)) {
912-
$body['started_at'] = $startedAt;
913-
}
914-
if (!empty($conclusion)) {
915-
$body['conclusion'] = $conclusion;
916-
}
917-
if (!empty($completedAt)) {
918-
$body['completed_at'] = $completedAt;
919-
}
920914
if (!empty($title) || !empty($summary)) {
921-
$body['output'] = [
915+
$body['output'] = array_filter([
922916
'title' => $title,
923917
'summary' => $summary,
924-
];
925-
if (!empty($text)) {
926-
$body['output']['text'] = $text;
927-
}
918+
'text' => $text,
919+
], fn ($value) => !empty($value));
928920
}
929921

930922
$response = $this->call(self::METHOD_POST, $url, ['Authorization' => "Bearer $this->accessToken"], $body);

0 commit comments

Comments
 (0)