Skip to content

Commit

Permalink
HW7
Browse files Browse the repository at this point in the history
  • Loading branch information
RofFlexor committed Sep 18, 2023
1 parent fcb4e52 commit ed9b68c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
14 changes: 9 additions & 5 deletions app/Actions/CheckEmailAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,17 @@ class CheckEmailAction
/**
* @throws Exception
*/
public function run(string $email): false|int
public function run(string $email): array
{
$isValidFormat = (new CheckEmailTask())->run($email);
if($isValidFormat) {
return (new CheckEmailDomainWithDoHTask())->run($email);
$emails = explode(',', $email);
$validatedEmails = [];
foreach($emails as $emailItem) {

Check failure on line 18 in app/Actions/CheckEmailAction.php

View workflow job for this annotation

GitHub Actions / phpcs

Expected 1 space(s) after FOREACH keyword; 0 found
$isValidFormat = (new CheckEmailTask())->run($emailItem);
if($isValidFormat && (new CheckEmailDomainWithDoHTask())->run($emailItem)) {

Check failure on line 20 in app/Actions/CheckEmailAction.php

View workflow job for this annotation

GitHub Actions / phpcs

Expected 1 space(s) after IF keyword; 0 found
$validatedEmails[] = $emailItem;
}
}
return false;
return $validatedEmails;
}

}

Check failure on line 27 in app/Actions/CheckEmailAction.php

View workflow job for this annotation

GitHub Actions / phpcs

Expected 1 newline at end of file; 0 found

Check failure on line 27 in app/Actions/CheckEmailAction.php

View workflow job for this annotation

GitHub Actions / phpcs

The closing brace for the class must go on the next line after the body
13 changes: 8 additions & 5 deletions app/Controllers/CheckEmailController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@

class CheckEmailController
{
/**
* @throws \Exception
*/
public function handle(): JsonResponse
{
if(isset($_POST['string'])) {
$isValidateBrackets = (new CheckEmailAction())->run($_POST['string']);
if($isValidateBrackets) {
return new JsonResponse(['message' => 'Строка валидна!']);
if(isset($_POST['email'])) {
$validateEmails = (new CheckEmailAction())->run($_POST['string']);
if(count($validateEmails) > 0) {
return new JsonResponse($validateEmails);
}
return new JsonResponse(['message' => 'Строка Невалидна!'], 400);
return new JsonResponse(['message' => 'Нет валидных Email'], 400);
}
return new JsonResponse(['message' => 'Bad request'], 400);
}
Expand Down

0 comments on commit ed9b68c

Please sign in to comment.