Skip to content

Commit cc6a658

Browse files
committed
PB-24082: refactor code
1 parent c906888 commit cc6a658

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/Controller/EmailController.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function showLastEmail($username)
7070
->where(['email' => $username])
7171
->order(['created' => 'DESC']);
7272

73-
$emailType = $this->request->getQueryParams()["type"] ?? null;
73+
$emailType = $this->getEmailType();
7474
if (!is_null($emailType)) {
7575
$emailQuery->where(['template' => $emailType]);
7676
}
@@ -91,4 +91,22 @@ public function showLastEmail($username)
9191
->setTemplate($email->template)
9292
->setTemplatePath("email/$format");
9393
}
94+
95+
/**
96+
* Returns a validated `has-type` filter set in the query parameters of the request if any.
97+
* @return string|null
98+
*/
99+
private function getEmailType() {
100+
$filter = $this->request->getQuery('filter');
101+
if (is_null($filter)) {
102+
return null;
103+
}
104+
105+
$hasType = $filter['has-type'];
106+
if (empty($hasType) || !is_string($hasType)) {
107+
return null;
108+
}
109+
110+
return $hasType;
111+
}
94112
}

0 commit comments

Comments
 (0)