Skip to content

Commit

Permalink
Improve code readability
Browse files Browse the repository at this point in the history
  • Loading branch information
eliseekn committed Aug 6, 2023
1 parent 81ad400 commit df9b357
Show file tree
Hide file tree
Showing 15 changed files with 39 additions and 44 deletions.
6 changes: 3 additions & 3 deletions app/Http/Controllers/Auth/EmailVerificationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ public function notify(Request $request, Response $response): void
}

Alert::default(__('email_verification_link_sent'))->success();
$response->url('login')->send(302);
$response->url('login')->send();
}

Alert::default(__('email_verification_link_not_sent'))->error();
$response->url('signup')->send(302);
$response->url('signup')->send();
}

public function verify(Request $request, Response $response, UpdateAction $updateAction): void
Expand Down Expand Up @@ -82,6 +82,6 @@ public function verify(Request $request, Response $response, UpdateAction $updat
Mail::send(new WelcomeMail($user->email, $user->name));

Alert::default(__('email_verified'))->success();
$response->url('login')->send(400);
$response->url('login')->send();
}
}
10 changes: 5 additions & 5 deletions app/Http/Controllers/Auth/ForgotPasswordController.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ public function notify(Request $request, Response $response): void
}

Alert::default(__('password_reset_link_sent'))->success();
$response->back()->send(302);
$response->back()->send();
}

Alert::default(__('password_reset_link_not_sent'))->error();
$response->back()->send(302);
$response->back()->send();
}

public function reset(Request $request, Response $response): void
Expand All @@ -71,7 +71,7 @@ public function reset(Request $request, Response $response): void
}

$token->delete();
$response->url("/password/new?email={$request->email}")->send(302);
$response->url("/password/new?email={$request->email}")->send();
}

public function update(Request $request, Response $response, LoginValidator $loginValidator, UpdateAction $updateAction): void
Expand All @@ -81,10 +81,10 @@ public function update(Request $request, Response $response, LoginValidator $log

if (!$user) {
Alert::default(__('password_not_reset'))->error();
$response->back()->send(302);
$response->back()->send();
}

Alert::default(__('password_reset'))->success();
$response->url('/login')->send(302);
$response->url('/login')->send();
}
}
6 changes: 3 additions & 3 deletions app/Http/Controllers/Auth/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function index(Request $request, Response $response): void
}

$uri = !Session::has('intended') ? config('app.home') : Session::pull('intended');
$response->url($uri)->send(302);
$response->url($uri)->send();
}

public function authenticate(Request $request, Response $response, LoginValidator $loginValidator): void
Expand All @@ -35,10 +35,10 @@ public function authenticate(Request $request, Response $response, LoginValidato
$uri = !Session::has('intended') ? config('app.home') : Session::pull('intended');

Alert::toast(__('welcome', ['name' => Auth::get('name')]))->success();
$response->url($uri)->send(302);
$response->url($uri)->send();
}

Alert::default(__('login_failed'))->error();
$response->url('/login')->withInputs($request->only('email', 'password'))->withErrors([__('login_failed')])->send(302);
$response->url('/login')->withInputs($request->only('email', 'password'))->withErrors([__('login_failed')])->send();
}
}
2 changes: 1 addition & 1 deletion app/Http/Controllers/Auth/LogoutController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ public function __invoke(Response $response): void
Auth::forget();
Alert::toast(__('logged_out'))->success();

$response->url(config('app.home'))->send(302);
$response->url(config('app.home'))->send();
}
}
6 changes: 3 additions & 3 deletions app/Http/Controllers/Auth/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function index(Request $request, Response $response): void
}

$uri = !Session::has('intended') ? config('app.home') : Session::pull('intended');
$response->url($uri)->send(302);
$response->url($uri)->send();
}

public function register(Request $request, Response $response, RegisterValidator $registerValidator, StoreAction $storeAction): void
Expand All @@ -36,12 +36,12 @@ public function register(Request $request, Response $response, RegisterValidator
$user = $storeAction->handle($validator->validated());

if (config('security.auth.email_verification')) {
$response->url('/email/notify?email=' . $user->email)->send(302);
$response->url('/email/notify?email=' . $user->email)->send();
}

Mail::send(new WelcomeMail($user->email, $user->name));
Alert::default(__('account_created'))->success();

$response->url('/login')->send(302);
$response->url('/login')->send();
}
}
2 changes: 1 addition & 1 deletion app/Http/Middlewares/AccountPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function handle(Request $request, Response $response): void
if (config('security.auth.email_verification')) {
if (is_null(Auth::get('email_verified'))) {
Alert::default(__('email_not_verifed'))->error();
$response->url('/login')->intended($request->fullUri())->send(302);
$response->url('/login')->intended($request->fullUri())->send();
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Middlewares/AuthPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function handle(Request $request, Response $response): void
->url('login')
->intended($request->fullUri())
->withErrors([__('not_logged')])
->send(302);
->send();
}
}
}
17 changes: 7 additions & 10 deletions core/Database/Connection/ConnectionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,19 @@

namespace Core\Database\Connection;

use PDO;
use PDOStatement;

interface ConnectionInterface
{
public function getPDO(): PDO;
public function getPDO();

public function executeStatement(string $query): false|int;
public function executeStatement(string $query);

public function executeQuery(string $query, array $args): false|PDOStatement;
public function executeQuery(string $query, array $args);

public function schemaExists(string $name): bool;
public function schemaExists(string $name);

public function tableExists(string $name): bool;
public function tableExists(string $name);

public function createSchema(string $name): void;
public function createSchema(string $name);

public function deleteSchema(string $name): void;
public function deleteSchema(string $name);
}
2 changes: 1 addition & 1 deletion core/Database/Migration.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Migration
/**
* @var \Core\Database\QueryBuilder
*/
protected static $qb;
protected static mixed $qb;

public static function createTable(string $name): self
{
Expand Down
6 changes: 3 additions & 3 deletions core/Database/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
*/
class QueryBuilder
{
protected static $query = '';
protected static $args = [];
protected static $table;
protected static string $query = '';
protected static array $args = [];
protected static mixed $table;

protected static function setTable(string $name): string
{
Expand Down
2 changes: 1 addition & 1 deletion core/Database/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Repository
{
protected QueryBuilder $qb;

public function __construct(private string $table) {}
public function __construct(private readonly string $table) {}

public function select(string ...$columns): self
{
Expand Down
1 change: 0 additions & 1 deletion core/Http/Client/Curl.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
namespace Core\Http\Client;

use Core\Exceptions\InvalidUrlFormatException;
use Core\Http\Client\ClientInterface;

/**
* Send asynchronous HTTP requests using curl
Expand Down
2 changes: 1 addition & 1 deletion core/Http/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public function json(array $data): self
return $this;
}

public function send(int $code = 200): void
public function send(int $code = 302): void
{
if (config('app.env') === 'test') {
header('Session:' . json_encode($_SESSION));
Expand Down
1 change: 0 additions & 1 deletion core/Http/Validator/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

use GUMP;
use Core\Http\Response;
use Core\Http\Validator\ValidatorInterface;

/**
* Request fields validator
Expand Down
18 changes: 9 additions & 9 deletions core/Support/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
/**
* Cookies management
*/
if (!function_exists('create_cookie')) {
function create_cookie(string $name, string $value, int $expire = 3600, bool $secure = false, string $domain = ''): bool
if (!function_exists('cookie_create')) {
function cookie_create(string $name, string $value, int $expire = 3600, bool $secure = false, string $domain = ''): bool
{
return Cookies::create($name, $value, $expire, $secure, $domain);
}
}

if (!function_exists('get_cookie')) {
function get_cookie(string $name): mixed
if (!function_exists('cookie_get')) {
function cookie_get(string $name): mixed
{
return Cookies::get($name);
}
Expand All @@ -38,8 +38,8 @@ function cookie_has(string $name): bool
}
}

if (!function_exists('delete_cookie')) {
function delete_cookie(string $name): bool
if (!function_exists('cookie_delete')) {
function cookie_delete(string $name): bool
{
return Cookies::delete($name);
}
Expand All @@ -48,8 +48,8 @@ function delete_cookie(string $name): bool
/**
* Sessions management
*/
if (!function_exists('create_session')) {
function create_session(string $name, $data): void
if (!function_exists('session_create')) {
function session_create(string $name, $data): void
{
Session::create($name, $data);
}
Expand Down Expand Up @@ -155,7 +155,7 @@ function generate_csrf_token(): string
$csrf_token = session_get('csrf_token');
} else {
$csrf_token = generate_token();
create_session('csrf_token', $csrf_token);
session_create('csrf_token', $csrf_token);
}

return $csrf_token;
Expand Down

0 comments on commit df9b357

Please sign in to comment.