Skip to content

Commit

Permalink
improve code quality.
Browse files Browse the repository at this point in the history
  • Loading branch information
Amin-Cheribet committed Jun 9, 2024
1 parent af22376 commit 057186e
Show file tree
Hide file tree
Showing 23 changed files with 41 additions and 35 deletions.
4 changes: 2 additions & 2 deletions Authenticator/Attempt.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ private function checkUserValide()

private function getUserData()
{
$model = "\Model\\".$this->table['value'];
$model = "\Model\\" . $this->table['value'];
if ($this->optionalValue['value']) {
return $model::select()->where($this->identifier['key'], '=', $this->identifier['value'])->where($this->optionalValue['key'], '=', $this->optionalValue['value'])->get();
}
Expand Down Expand Up @@ -81,7 +81,7 @@ private function setup()
* remove white spaces from inputs & add slashes
*
* @return void
*/
*/
private function secure()
{
foreach ($this->data as $key => $value) {
Expand Down
4 changes: 2 additions & 2 deletions Box/FileGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function __construct(string $command, string $argument, string $flag = nu

public function create()
{
if (!file_put_contents($this->fileInfo->getFileDir().DIRECTORY_SEPARATOR.$this->fileInfo->getFileName().'.php', $this->template)) {
if (!file_put_contents($this->fileInfo->getFileDir() . DIRECTORY_SEPARATOR . $this->fileInfo->getFileName() . '.php', $this->template)) {
echo "can't create file";
exit();
}
Expand All @@ -45,7 +45,7 @@ public function create()

private function getTemplate()
{
$templateGenerator = 'Box\TemplateGenerators\\'.$this->commandShortcuts[strtolower($this->command)];
$templateGenerator = 'Box\TemplateGenerators\\' . $this->commandShortcuts[strtolower($this->command)];
return $this->generateTemplate(new $templateGenerator($this->fileInfo->getFileDir(), $this->fileInfo->getFileName(), $this->flag));
}

Expand Down
2 changes: 1 addition & 1 deletion Box/FileLocationResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ private function resolveDir(string $mainDir, string $dir)
return $mainDir;
}

return $mainDir.'/'.$this->fileInfo['dirname'];
return $mainDir . '/' . $this->fileInfo['dirname'];
}

public function getFileName()
Expand Down
2 changes: 1 addition & 1 deletion Box/TemplateGenerators/TemplateGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ private function adapter()
{
$dir = explode('/', $this->directory);
$dir = array_slice($dir, 2, count($dir));
$this->directory = empty($dir) ? implode('\\', $dir) : '\\'.implode('\\', $dir);
$this->directory = empty($dir) ? implode('\\', $dir) : '\\' . implode('\\', $dir);
}
}
5 changes: 3 additions & 2 deletions Cookie/Cookie.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Cookie;

class Cookie
Expand All @@ -13,13 +14,13 @@ public function __construct()
public function delete(string $key): void
{
unset($_COOKIE[$key]);
setcookie($key, '', time()-1);
setcookie($key, '', time() - 1);
}

public function deleteAll(): void
{
foreach ($_COOKIE as $key => $value) {
setcookie($key, $value, time()-1);
setcookie($key, $value, time() - 1);
}
}

Expand Down
2 changes: 1 addition & 1 deletion Kernel/Compiler/MiddlewareCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function __construct(array $middlewares)
*/
public function execute(): void
{
$middlewareProvider = require rootDir().getAliase('MiddlewaresProviders');
$middlewareProvider = require rootDir() . getAliase('MiddlewaresProviders');

foreach ($this->middlewares as $middleware) {
if (!array_key_exists($middleware, $middlewareProvider)) {
Expand Down
6 changes: 3 additions & 3 deletions Kernel/Compiler/RouteCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ public function __construct(RouteInterface $route)
{
$this->route = $route;
$this->arguments = [
container()->Request,
container()->Response,
container()->Request,
container()->Response,
];
}

Expand Down Expand Up @@ -87,7 +87,7 @@ private function explodeController(RouteInterface $route): array
{
$parameters = explode('@', $route->getAction());
return [
'controller' => '\Controller\\'.$parameters[0],
'controller' => '\Controller\\' . $parameters[0],
'method' => $parameters[1],
];
}
Expand Down
2 changes: 1 addition & 1 deletion Kernel/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function prepare(): void
// load all service providers.
container()->build('Services\ServicesLoader');
// load routes
container()->Router->call(rootDir().'App/Routes.php');
container()->Router->call(rootDir() . 'App/Routes.php');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion Model/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function __construct()
}
}

public static function getPDO(): \PDO
public static function getPDO(): PDO
{
$self = new static();
return $self->pdo;
Expand Down
2 changes: 1 addition & 1 deletion Request/RequestMethodResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ private function resolveMethodFromInputs(): string
private function getMethodFromRequest(): string
{
if (!in_array($this->request->body->_method, $this->allowedMethods)) {
throw new \Exception($this->request->body->_method." Type of method is not supported", 1);
throw new \Exception($this->request->body->_method . " Type of method is not supported", 1);
}

return $this->request->body->_method;
Expand Down
1 change: 1 addition & 0 deletions Request/RequestMethodResolverInterface.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Request;

interface RequestMethodResolverInterface
Expand Down
2 changes: 1 addition & 1 deletion Router/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Route implements RouteInterface
public function __construct(string $method, string $prefix, string $routeUrl, $action)
{
$this->method = $method;
$this->routeUrl = $prefix.$routeUrl;
$this->routeUrl = $prefix . $routeUrl;
$this->action = $action;
$this->middlewares = new MiddlewaresCollection([]);
$this->lateMiddlewares = new MiddlewaresCollection([]);
Expand Down
2 changes: 1 addition & 1 deletion Router/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function call(string $routesFile): Router
return $this;
}

throw new \Exception('This Page ('.url(currentUrl()).') Does Not Exist', 404);
throw new \Exception('This Page (' . url(currentUrl()) . ') Does Not Exist', 404);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion Router/UrlMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function matchURL(): bool

private function matchUrlWithRoute(): bool
{
for ($i=0; $i < count($this->url); $i++) {
for ($i = 0; $i < count($this->url); $i++) {
if (($this->url[$i] !== $this->route[$i]) && !$this->isVariable($this->url[$i], $this->route[$i])) {
return false;
}
Expand Down
16 changes: 8 additions & 8 deletions Services/Helpers/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ function view(string $view, array $data = [])
// return full valide url (inside application)
function url(string $url)
{
$host = 'http'.(($_SERVER['SERVER_PORT'] == 443) ? 's://' : '://').$_SERVER['HTTP_HOST'].'/';
$host = 'http' . (($_SERVER['SERVER_PORT'] == 443) ? 's://' : '://') . $_SERVER['HTTP_HOST'] . '/';

return $host.$url;
return $host . $url;
}
// redirect to a specific url (inside application);
function route(string $url)
{
$host = 'http'.(($_SERVER['SERVER_PORT'] == 443) ? 's://' : '://').$_SERVER['HTTP_HOST'].'/';
header('Location: '.$host.$url);
$host = 'http' . (($_SERVER['SERVER_PORT'] == 443) ? 's://' : '://') . $_SERVER['HTTP_HOST'] . '/';
header('Location: ' . $host . $url);
}
// reidrect to an external url
function redirect(string $url)
{
header('Location: '.$url);
header('Location: ' . $url);
}

function setSession(string $key, string $value)
Expand Down Expand Up @@ -71,7 +71,7 @@ function destroyAllCookies()

function setLanguage(string $language): void
{
setNewCookie('_language', $language, time()+3600*24*364);
setNewCookie('_language', $language, time() + 3600 * 24 * 364);
}

function getLanguage(): string
Expand All @@ -92,7 +92,7 @@ function csrf_field()
$token = uniqid(random_int(0, 1000));
}
setSession('_token', $token);
echo "<input type='hidden' name='_token' value='".$token."'>";
echo "<input type='hidden' name='_token' value='" . $token . "'>";
}

function csrf_token()
Expand Down Expand Up @@ -124,7 +124,7 @@ function getAliase(string $aliase)

function rootDir()
{
return $_SERVER['DOCUMENT_ROOT'].'/../';
return $_SERVER['DOCUMENT_ROOT'] . '/../';
}

function previousUrl()
Expand Down
4 changes: 2 additions & 2 deletions Services/LanguagesResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public static function resolve(string $path): array

private static function savePath(string $path): void
{
$fullDir = rootDir().'resources/languages/'.$path.'.php';
$fullDir = rootDir() . 'resources/languages/' . $path . '.php';

if (!file_exists($fullDir)) {
throw new \Exception("Language file you are looking for don't exist: $path", 89);
}
Expand Down
2 changes: 1 addition & 1 deletion Services/ServicesLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function __construct()

private function loadApp()
{
require rootDir().getAliase('App');
require rootDir() . getAliase('App');
}

private function loadServices()
Expand Down
1 change: 1 addition & 0 deletions Session/Session.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Session;

class Session
Expand Down
1 change: 1 addition & 0 deletions Validator/Pipable.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Validator;

interface Pipable
Expand Down
1 change: 1 addition & 0 deletions Validator/Pipeline.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Validator;

use Validator\Validators\Validatable as Validatable;
Expand Down
3 changes: 2 additions & 1 deletion Validator/Validators/Factory.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Validator\Validators;

use Validator\Validators\Validatable as Validatable;
Expand All @@ -23,7 +24,7 @@ public static function create(string $validator, ...$arguments): Validatable

public function return(string $validator, ...$arguments): Validatable
{
$validator = "Validator\Validators\\".$this->resolveValidator($validator);
$validator = "Validator\Validators\\" . $this->resolveValidator($validator);
return new $validator(...$arguments);
}

Expand Down
6 changes: 3 additions & 3 deletions Validator/Validators/Length.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ public function __construct(string $input, int $min, int $max, string $errorMsg)
$this->max = $max;
$this->errorMsg = $errorMsg;
}

public function check(): bool
{
if (!$this->maxLength($this->max) or !$this->minLength($this->min)) {
return false;
}

return true;
}

private function maxLength(int $max): bool
{
return (strlen($this->input) > $max) ? false : true;
Expand Down
4 changes: 2 additions & 2 deletions Validator/Validators/Validatable.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
abstract class Validatable
{
protected $errorMsg;

abstract public function check(): bool;

public function getErrorMessage(): ?string
{
return $this->errorMsg;
Expand Down

0 comments on commit 057186e

Please sign in to comment.