Skip to content

Commit

Permalink
Fix code to PSR-12
Browse files Browse the repository at this point in the history
  • Loading branch information
levitanoff committed Apr 8, 2024
1 parent 1c8cd42 commit c92dc57
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
1 change: 1 addition & 0 deletions code/public/index.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

use Dmatrenin\Hw6\App;
Expand Down
10 changes: 5 additions & 5 deletions code/src/App.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Dmatrenin\Hw6;
Expand All @@ -8,7 +9,7 @@

class App
{
public function run()
public function run(): void
{
try {
http_response_code(200);
Expand All @@ -18,12 +19,11 @@ public function run()
'[email protected]',
'[email protected]', //Валидный E-mail. Домен не существует
]);
echo 'Ok';
}
catch (Exception $exception) {

echo 'All emails are valid';
} catch (Exception $exception) {
http_response_code($exception->getCode());
echo $exception->getMessage();
}

}
}

Check failure on line 29 in code/src/App.php

View workflow job for this annotation

GitHub Actions / phpcs

Expected 1 newline at end of file; 0 found
7 changes: 4 additions & 3 deletions code/src/Validator.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<?php

declare(strict_types=1);

namespace Dmatrenin\Hw6;


class Validator
{
/**
* @throws \Exception
*/
public static function validateEmails($emails = []) : void
public static function validateEmails($emails = []): void
{
if (empty($emails)) {
throw new \Exception('Emails is empty', 400);
Expand All @@ -24,6 +24,7 @@ public static function validateEmails($emails = []) : void
throw new \Exception($email . ' is not valid E-mail' . PHP_EOL);
}

/** @var TYPE_NAME $email_regex */
$email_regex = '/^(?!(?:(?:\x22?\x5C[\x00-\x7E]\x22?)|(?:\x22?[^\x5C\x22]\x22?)){255,})(?!(?:(?:\x22?\x5C[\x00-\x7E]\x22?)|(?:\x22?[^\x5C\x22]\x22?)){65,}@)(?:(?:[\x21\x23-\x27\x2A\x2B\x2D\x2F-\x39\x3D\x3F\x5E-\x7E]+)|(?:\x22(?:[\x01-\x08\x0B\x0C\x0E-\x1F\x21\x23-\x5B\x5D-\x7F]|(?:\x5C[\x00-\x7F]))*\x22))(?:\.(?:(?:[\x21\x23-\x27\x2A\x2B\x2D\x2F-\x39\x3D\x3F\x5E-\x7E]+)|(?:\x22(?:[\x01-\x08\x0B\x0C\x0E-\x1F\x21\x23-\x5B\x5D-\x7F]|(?:\x5C[\x00-\x7F]))*\x22)))*@(?:(?:(?!.*[^.]{64,})(?:(?:(?:xn--)?[a-z0-9]+(?:-[a-z0-9]+)*\.){1,126}){1,}(?:(?:[a-z][a-z0-9]*)|(?:(?:xn--)[a-z0-9]+))(?:-[a-z0-9]+)*)|(?:\[(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){7})|(?:(?!(?:.*[a-f0-9][:\]]){7,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?)))|(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){5}:)|(?:(?!(?:.*[a-f0-9]:){5,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3}:)?)))?(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))(?:\.(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))){3}))\]))$/iD';

if (!preg_match($email_regex, $email)) {
Expand All @@ -39,4 +40,4 @@ public static function validateEmails($emails = []) : void
}
}
}
}
}

0 comments on commit c92dc57

Please sign in to comment.