Skip to content

Commit

Permalink
#43 Refactoring Codacy Issue
Browse files Browse the repository at this point in the history
  • Loading branch information
bfoujols committed Dec 29, 2023
1 parent 5de8951 commit 017e39c
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 10 deletions.
10 changes: 5 additions & 5 deletions app/Controller/DataBaseTestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ public function execute(Request $request): string|null
// Connexion à la base de données
$getConnectDb = DatabaseService::getConnect();
// Requête SQL
$etudiantStmt = $getConnectDb->prepare("SELECT * FROM `etudiant`");
// Exécution de la requête
$etudiantStmt->execute();
$etudiantStmt = $getConnectDb->query("SELECT * FROM `etudiant`");
// Récupération des données
$etudiants = $etudiantStmt->fetchAll();

return TwigCore::getEnvironment()->render('home/db.html.twig',
return TwigCore::getEnvironment()->render

Check notice on line 32 in app/Controller/DataBaseTestController.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

app/Controller/DataBaseTestController.php#L32

Space before opening parenthesis of function call prohibited
(
'home/db.html.twig',
[
'titre' => 'Exemple avec connextion à la base de données',
'titre' => 'Exemple avec connextion à la base de données',

Check notice on line 36 in app/Controller/DataBaseTestController.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

app/Controller/DataBaseTestController.php#L36

Array key not aligned correctly; expected 13 spaces but found 16
'etudiants' => $etudiants

Check notice on line 37 in app/Controller/DataBaseTestController.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

app/Controller/DataBaseTestController.php#L37

Array key not aligned correctly; expected 13 spaces but found 16
]
);
Expand Down
8 changes: 8 additions & 0 deletions app/Template/error/http-Default.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{% extends "base.html.twig" %}

{% block title %}Error{% endblock %}

{% block content %}
<h1>Error Default Route</h1>
{% endblock %}

Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
/*
* Ce fichier fait partie du Studoo
*
* @author Benoit Foujols
*
* Pour les informations complètes sur les droits d'auteur et la licence,
* veuillez consulter le fichier LICENSE qui a été distribué avec ce code source.
*/

namespace Studoo\EduFramework\Core\Controller\Error;

use Studoo\EduFramework\Core\Controller\ControllerInterface;
use Studoo\EduFramework\Core\Controller\Request;
use Studoo\EduFramework\Core\View\TwigCore;
use Twig\Error\LoaderError;
use Twig\Error\RuntimeError;
use Twig\Error\SyntaxError;

/**
* Class HttpErrorDefaultController
* Classe Controller pour les erreurs HTTP
*/
class HttpErrorDefaultController implements ControllerInterface
{
/**
* Si y a pas de route valide alors j'affiche la page 404
* @param Request $request Objet de la requête
* @return string
* @throws SyntaxError
* @throws RuntimeError
* @throws LoaderError
*/
public function execute(Request $request): string

Check warning on line 34 in src/EduFramework/Core/Controller/Error/HttpErrorDefaultController.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/EduFramework/Core/Controller/Error/HttpErrorDefaultController.php#L34

Avoid unused parameters such as '$request'.
{
return TwigCore::getEnvironment()->render(
'error/http-Default.html.twig',
[]
);
}
}
9 changes: 7 additions & 2 deletions src/EduFramework/Core/Controller/FastRouteCore.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use FastRoute\Dispatcher;
use Studoo\EduFramework\Core\Controller\Error\HttpError404Controller;
use Studoo\EduFramework\Core\Controller\Error\HttpError405Controller;
use Studoo\EduFramework\Core\Controller\Error\HttpErrorDefaultController;
use Symfony\Component\Yaml\Yaml;
use Twig\Error\LoaderError;
use Twig\Error\RuntimeError;
Expand All @@ -25,6 +26,11 @@
class FastRouteCore
{
use BuildControllerTrait;

/**
* Objet pour la gestion des routes
* @var \FastRoute\RouteCollector
*/
private \FastRoute\RouteCollector $routeCollector;

/**
Expand Down Expand Up @@ -138,8 +144,7 @@ public function getRoute(): string|null
$returnView = $this->buildController($request->getHander())->execute($request);
break;
default:
// TODO Refactoring des erreurs
$returnView = (new HttpError404Controller())->execute($request);
$returnView = (new HttpErrorDefaultController())->execute($request);
break;
}
return $returnView;
Expand Down
2 changes: 1 addition & 1 deletion src/EduFramework/Core/Controller/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function __construct(string $route, string $httpMethod)
*/
public function getHearder(): bool|array
{
if (!function_exists('getallheaders')) {
if (function_exists('getallheaders') === false) {
$headers = [];
foreach ($_SERVER as $name => $value) {
if (substr($name, 0, 5) === 'HTTP_') {
Expand Down
2 changes: 2 additions & 0 deletions src/EduFramework/Core/Exception/NotDataResponseException.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
class NotDataResponseException extends \Exception
{
/**
*
* @var string
*/
protected $message = "Pas de donnée dans la réponse";

/**
*
* @var integer
*/
protected $code = 403;
Expand Down
4 changes: 3 additions & 1 deletion src/EduFramework/Core/Service/DatabaseMariadb.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ public function getManager(): PDO
';dbname=' . ConfigCore::getEnv("DB_NAME"),
ConfigCore::getEnv("DB_USER"),
ConfigCore::getEnv("DB_PASSWORD"),
[PDO::ATTR_PERSISTENT => false]
[
PDO::ATTR_PERSISTENT => false

Check notice on line 30 in src/EduFramework/Core/Service/DatabaseMariadb.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/EduFramework/Core/Service/DatabaseMariadb.php#L30

Array key not aligned correctly; expected 13 spaces but found 16
]
);
}
}
5 changes: 4 additions & 1 deletion src/EduFramework/Core/Service/DatabaseMysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ public function getManager(): PDO
';dbname=' . ConfigCore::getEnv("DB_NAME"),
ConfigCore::getEnv("DB_USER"),
ConfigCore::getEnv("DB_PASSWORD"),
[PDO::ATTR_PERSISTENT => false, PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8']
[
PDO::ATTR_PERSISTENT => false,

Check notice on line 30 in src/EduFramework/Core/Service/DatabaseMysql.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/EduFramework/Core/Service/DatabaseMysql.php#L30

Array key not aligned correctly; expected 13 spaces but found 16
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'

Check notice on line 31 in src/EduFramework/Core/Service/DatabaseMysql.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/EduFramework/Core/Service/DatabaseMysql.php#L31

Array key not aligned correctly; expected 13 spaces but found 16
]
);
}
}

0 comments on commit 017e39c

Please sign in to comment.