Typage et documentation
continuous-integration/drone/push Build encountered an error Details

ServeurDeTest
Noé GARNIER 2 years ago
parent 034f66c642
commit a91ae178a8

@ -4,6 +4,9 @@ class Autoload
{ {
private static $_instance = null; private static $_instance = null;
/**
* If the class is not already loaded, then load it.
*/
public static function charger() public static function charger()
{ {
if(null !== self::$_instance) { if(null !== self::$_instance) {
@ -18,6 +21,9 @@ class Autoload
} }
} }
/**
* If the instance is not null, unregister the autoload function and set the instance to null.
*/
public static function shutDown() public static function shutDown()
{ {
if(null !== self::$_instance) { if(null !== self::$_instance) {
@ -30,6 +36,11 @@ class Autoload
} }
} }
/**
* If the file exists, include it
*
* @param class The name of the class to load.
*/
private static function _autoload($class) private static function _autoload($class)
{ {
global $rep; global $rep;

@ -3,12 +3,29 @@ class Connection extends SQLite3
{ {
private $stmt; private $stmt;
private $result; private $result;
/**
* The function __construct() is a constructor function that takes a parameter and calls the
* open() function with the parameter
*
* @param dsn The Data Source Name, or DSN, contains the information required to connect to the
* database.
*/
function __construct($dsn) function __construct($dsn)
{ {
$this->open($dsn); $this->open($dsn);
$this->enableExceptions(true); $this->enableExceptions(true);
} }
/**
* It takes a query and an array of parameters, binds the parameters to the query, and executes the
* query
*
* @param string query The query to execute.
* @param array parameters
*
* @return bool The result of the query.
*/
public function executeQuery(string $query, array $parameters = []): bool public function executeQuery(string $query, array $parameters = []): bool
{ {
$this->stmt = parent::prepare($query); $this->stmt = parent::prepare($query);
@ -25,6 +42,12 @@ class Connection extends SQLite3
} }
} }
/**
* It takes the result of a query and returns an array of arrays
*
* @return array An array of arrays.
*/
public function getResults(): array public function getResults(): array
{ {
$resultArray = $this->result->fetchArray(SQLITE3_ASSOC); $resultArray = $this->result->fetchArray(SQLITE3_ASSOC);

@ -1,19 +1,28 @@
<?php <?php
Class Nettoyage{ Class Nettoyage{
public function clean($input) /**
* It takes a string, trims it, strips it of HTML tags, and returns the string
*
* @param string input The string to be cleaned.
*
* @return string The output of the function.
*/
public function clean(string $input) : string
{ {
// Supprime les espaces en début et fin de chaîne
$output = trim($input); $output = trim($input);
// Supprime les balises HTML
$output = strip_tags($output); $output = strip_tags($output);
// Supprime les caractères spéciaux
// $output = htmlspecialchars($output); // $output = htmlspecialchars($output);
return $output; return $output;
} }
public function cleanEmail($input){ /**
* It takes a string, cleans it, then sanitizes it as an email.
*
* @param string input The input to be cleaned.
*
* @return string The output is being returned.
*/
public function cleanEmail(string $input) : string{
$output = $this->clean($input); $output = $this->clean($input);
$output = filter_var($output, FILTER_SANITIZE_EMAIL); $output = filter_var($output, FILTER_SANITIZE_EMAIL);
return $output; return $output;

@ -2,6 +2,11 @@
class Validation class Validation
{ {
/**
* If the variable is set, return true, otherwise return false.
*
* @param var The variable you want to check if it's set.
*/
public function ValidateSet($var) :bool{ public function ValidateSet($var) :bool{
if (isset($var)) { if (isset($var)) {
return true; return true;
@ -9,6 +14,11 @@ class Validation
return false; return false;
} }
/**
* If the variable is empty, return false. Otherwise, return true.
*
* @param var The variable to be validated.
*/
public function ValidateNotEmpty($var) :bool{ public function ValidateNotEmpty($var) :bool{
if (empty($var)) { if (empty($var)) {
return false; return false;
@ -16,6 +26,13 @@ class Validation
return true; return true;
} }
/**
* If the URL is not a valid URL, return false. Otherwise, return true.
*
* @param string url The URL to be validated.
*
* @return bool A boolean value.
*/
public function ValidateURL(string $url) :bool{ public function ValidateURL(string $url) :bool{
if (!preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i",$url)) { if (!preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i",$url)) {
return false; return false;
@ -23,12 +40,27 @@ class Validation
return true; return true;
} }
/**
* It checks if the email is valid.
*
* @param string email The email address to validate.
*
* @return bool A boolean value.
*/
public function ValidateEmail(string $email) :bool{ public function ValidateEmail(string $email) :bool{
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
return false; return false;
} }
return true; return true;
} }
/**
* It returns true if the username is valid, and false if it isn't.
*
* @param string username The username to validate.
*
* @return bool A boolean value.
*/
public function ValidateUsername(string $username) : bool{ public function ValidateUsername(string $username) : bool{
// if(!filter_var($username,FILTER_VALIDATE_REGEXP,array("options" => array( "regexp" => "^[^&=_'\-+;<>.]{1,18}$" )))) // if(!filter_var($username,FILTER_VALIDATE_REGEXP,array("options" => array( "regexp" => "^[^&=_'\-+;<>.]{1,18}$" ))))
@ -37,6 +69,14 @@ class Validation
// } // }
return true; return true;
} }
/**
* If the password is longer than 100 characters, return false. Otherwise, return true.
*
* @param string password The password to validate.
*
* @return bool A boolean value.
*/
public function ValidatePassword(string $password) : bool{ public function ValidatePassword(string $password) : bool{
if(strlen($password)>100) if(strlen($password)>100)
{ {
@ -44,6 +84,23 @@ class Validation
} }
return true; return true;
} }
/**
* It checks if the length of the strings are less than 250 characters and if the resolution time
* and points are positive
*
* @param string name The name of the enigma
* @param string statement The statement of the enigma
* @param string help Help text for the enigma
* @param string reminder a reminder of the enigma
* @param string example
* @param string solution The solution to the enigma
* @param string test the test to be run on the solution
* @param string resolutionTime the time it takes to solve the enigma
* @param int points
*
* @return bool a boolean value.
*/
public function ValidateEnigme(string $name,string $statement,string $help,string $reminder,string $example,string $solution,string $test, string $resolutionTime, int $points) : bool{ public function ValidateEnigme(string $name,string $statement,string $help,string $reminder,string $example,string $solution,string $test, string $resolutionTime, int $points) : bool{
if(strlen($name)>50 || strlen($statement) > 250 || strlen($help) > 250 || strlen($reminder) > 250 || strlen($example) > 250 || strlen($solution) > 250 || strlen($test) > 250 || $resolutionTime < 0 || $points < 0) if(strlen($name)>50 || strlen($statement) > 250 || strlen($help) > 250 || strlen($reminder) > 250 || strlen($example) > 250 || strlen($solution) > 250 || strlen($test) > 250 || $resolutionTime < 0 || $points < 0)
return false; return false;

@ -145,6 +145,10 @@ class AdminController extends UserController
} }
} }
/**
* It gets the enigme from the database and displays it
* in the enigme page.
*/
public function goToEnigme() public function goToEnigme()
{ {
try { try {
@ -162,6 +166,11 @@ class AdminController extends UserController
} }
} }
/**
* It gets the enigmas from the database and sorts them by their order
* and displays them in the admin page.
*
*/
public function goToAdmin() public function goToAdmin()
{ {
try { try {
@ -178,6 +187,7 @@ class AdminController extends UserController
require($rep . $vues['erreur']); require($rep . $vues['erreur']);
} }
} }
public function goToAddEnigmeSolo() public function goToAddEnigmeSolo()
{ {
try { try {
@ -188,6 +198,7 @@ class AdminController extends UserController
require($rep . $vues['erreur']); require($rep . $vues['erreur']);
} }
} }
public function goToAddEnigmeMulti(){ public function goToAddEnigmeMulti(){
try { try {
global $rep, $vues; global $rep, $vues;
@ -291,6 +302,10 @@ class AdminController extends UserController
require($rep . $vues['erreur']); require($rep . $vues['erreur']);
} }
} }
/**
* When the user clicks on the button, the function enigmeEnded() is called, which will display the
* next enigma.
*/
public function enigmeEnded(){ public function enigmeEnded(){
try{ try{
global $rep, $vues; global $rep, $vues;
@ -303,6 +318,7 @@ class AdminController extends UserController
require($rep . $vues['erreur']); require($rep . $vues['erreur']);
} }
} }
public function editEnigme() public function editEnigme()
{ {
try{ try{
@ -336,6 +352,7 @@ class AdminController extends UserController
require($rep . $vues['erreur']); require($rep . $vues['erreur']);
} }
} }
public function deleteEnigme(){ public function deleteEnigme(){
try{ try{
global $rep, $vues; global $rep, $vues;
@ -437,6 +454,7 @@ class AdminController extends UserController
require($rep . $vues['erreur']); require($rep . $vues['erreur']);
} }
} }
public function report(){ public function report(){
try{ try{
global $rep, $vues; global $rep, $vues;

@ -107,7 +107,8 @@ class EnigmeGateway
* *
* @return array of objects. * @return array of objects.
*/ */
public function findSoloEnigma(){ public function findSoloEnigma() : array
{
$query = "SELECT * FROM Enigme $query = "SELECT * FROM Enigme
WHERE points IS NULL OR points = 0"; WHERE points IS NULL OR points = 0";
$this->con->executeQuery($query); $this->con->executeQuery($query);
@ -115,7 +116,7 @@ class EnigmeGateway
return $tabEnigme; return $tabEnigme;
} }
public function findEnigmaFromPartie(string $idPartie){ public function findEnigmaFromPartie(string $idPartie) : array{
$query = "SELECT * FROM Enigme e, Contenir c $query = "SELECT * FROM Enigme e, Contenir c
WHERE c.partie=:idPartie"; WHERE c.partie=:idPartie";
$this->con->executeQuery($query, array( $this->con->executeQuery($query, array(

@ -47,7 +47,7 @@ class PartieGateway
return $partie; return $partie;
} }
public function findPartieInQueue() public function findPartieInQueue() : int
{ {
$query = "SELECT partie $query = "SELECT partie
FROM Participer FROM Participer
@ -269,7 +269,7 @@ class PartieGateway
$row = $results[0]; $row = $results[0];
return $row['count(*)']; return $row['count(*)'];
} }
public function getEtat($idPartie){ public function getEtat($idPartie) : int{
$query = "SELECT etat FROM Participer WHERE partie = :idPartie"; $query = "SELECT etat FROM Participer WHERE partie = :idPartie";
$this->con->executeQuery($query, array( $this->con->executeQuery($query, array(
"idPartie" => array($idPartie, SQLITE3_INTEGER) "idPartie" => array($idPartie, SQLITE3_INTEGER)
@ -287,7 +287,7 @@ class PartieGateway
return 0; return 0;
} }
public function getLesMailJoueurs($idPartie){ public function getLesMailJoueurs($idPartie) : array{
$query = "SELECT utilisateur FROM Participer WHERE partie = :idPartie"; $query = "SELECT utilisateur FROM Participer WHERE partie = :idPartie";
$this->con->executeQuery($query, array( $this->con->executeQuery($query, array(
"idPartie" => array($idPartie, SQLITE3_INTEGER) "idPartie" => array($idPartie, SQLITE3_INTEGER)
@ -300,7 +300,7 @@ class PartieGateway
} }
return $lesJoueurs; return $lesJoueurs;
} }
public function getLesIdEnigmes($idPartie){ public function getLesIdEnigmes($idPartie) : array{
$query = "SELECT enigme FROM Contenir WHERE partie = :idPartie"; $query = "SELECT enigme FROM Contenir WHERE partie = :idPartie";
$this->con->executeQuery($query, array( $this->con->executeQuery($query, array(
"idPartie" => array($idPartie, SQLITE3_INTEGER) "idPartie" => array($idPartie, SQLITE3_INTEGER)
@ -349,6 +349,11 @@ class PartieGateway
$date = new DateTime ($results[0]['dateDebut']); $date = new DateTime ($results[0]['dateDebut']);
return $date; return $date;
} }
/**
* It updates the state of a game to 2 (ended) in the database
*
* @param int idPartie the id of the game
*/
public function endGame(int $idPartie){ public function endGame(int $idPartie){
$query = "UPDATE Participer SET etat = 2 WHERE partie = :idPartie"; $query = "UPDATE Participer SET etat = 2 WHERE partie = :idPartie";
$this->con->executeQuery($query, array( $this->con->executeQuery($query, array(
@ -356,6 +361,11 @@ class PartieGateway
) )
); );
} }
/**
* It updates the state of a game from 0 to 1.
*
* @param int idPartie the id of the game
*/
public function launchGame(int $idPartie){ public function launchGame(int $idPartie){
$query = "UPDATE Participer SET etat=1 WHERE etat=0 AND partie=:partie"; $query = "UPDATE Participer SET etat=1 WHERE etat=0 AND partie=:partie";
$this->con->executeQuery($query,array( $this->con->executeQuery($query,array(
@ -373,6 +383,11 @@ class PartieGateway
} }
return true; return true;
} }
/**
* It updates the dateDebut column of the Partie table with the current date and time.
*
* @param int idPartie
*/
public function majDateDebut(int $idPartie){ public function majDateDebut(int $idPartie){
$query = "UPDATE Partie SET dateDebut = :dateDebut WHERE id = :idPartie"; $query = "UPDATE Partie SET dateDebut = :dateDebut WHERE id = :idPartie";
$this->con->executeQuery($query, array( $this->con->executeQuery($query, array(
@ -381,6 +396,7 @@ class PartieGateway
) )
); );
} }
public function quitQueue(string $mailUtilisateur,int $idPartie){ public function quitQueue(string $mailUtilisateur,int $idPartie){
$query = "DELETE FROM Participer $query = "DELETE FROM Participer
WHERE utilisateur = :mailUtilisateur WHERE utilisateur = :mailUtilisateur

@ -127,7 +127,7 @@ class ResoudreGateway
"ended" => array($ended, SQLITE3_INTEGER))); "ended" => array($ended, SQLITE3_INTEGER)));
} }
} }
public function checkEnigmeIsEnded(string $mailUtilisateur, int $enigmeId){ public function checkEnigmeIsEnded(string $mailUtilisateur, int $enigmeId) : bool{
$query="SELECT * FROM Resoudre $query="SELECT * FROM Resoudre
WHERE utilisateur=:utilisateur WHERE utilisateur=:utilisateur
AND enigme=:enigme"; AND enigme=:enigme";
@ -144,7 +144,7 @@ class ResoudreGateway
return $results[0]['ended']; return $results[0]['ended'];
} }
} }
public function checkEnigmeIsEndedInPartie(string $mailUtilisateur, int $enigmeId, int $idPartie){ public function checkEnigmeIsEndedInPartie(string $mailUtilisateur, int $enigmeId, int $idPartie) : bool{
$query="SELECT * FROM Resoudre $query="SELECT * FROM Resoudre
WHERE utilisateur=:utilisateur WHERE utilisateur=:utilisateur
AND enigme=:enigme AND enigme=:enigme

@ -385,7 +385,6 @@ class UserController
} }
} }
// A appeler après avoir vérifié que la partie est finie
public function endGame(){ public function endGame(){
try { try {
global $rep, $vues, $error; global $rep, $vues, $error;

@ -139,7 +139,7 @@ class UtilisateurGateway
return true; return true;
} }
public function queueFilled(){ public function queueFilled() : bool{
$query = "SELECT count(*) FROM Participer WHERE etat=0"; $query = "SELECT count(*) FROM Participer WHERE etat=0";
$this->con->executeQuery($query); $this->con->executeQuery($query);
if ($this->con->getResults()[0]['count(*)'] >= 2) if ($this->con->getResults()[0]['count(*)'] >= 2)

@ -1,6 +1,6 @@
<?php <?php
class EnigmeFactory{ class EnigmeFactory{
public static function create($results) public static function create($results) : array
{ {
$tabEnigme=array(); $tabEnigme=array();
foreach($results as $row) foreach($results as $row)

@ -2,7 +2,7 @@
class UtilisateurFactory class UtilisateurFactory
{ {
public static function createUtilisateur(array $results){ public static function createUtilisateur(array $results) : Utilisateur{
if ($results == null){ if ($results == null){
return new Utilisateur("null", "null", "null", false); return new Utilisateur("null", "null", "null", false);
} }
@ -15,7 +15,7 @@ class UtilisateurFactory
} }
return new Utilisateur($email, $pseudo, $mdp, $estAdmin); return new Utilisateur($email, $pseudo, $mdp, $estAdmin);
} }
public static function createTabUtilisateur(array $results){ public static function createTabUtilisateur(array $results) : array{
$tabUtilisateur=array(); $tabUtilisateur=array();
foreach($results as $row) foreach($results as $row)
{ {

@ -1,16 +1,8 @@
<?php <?php
require_once('./Config/Config.php'); require_once('./Config/Config.php');
require_once('./Config/Autoload.php'); require_once('./Config/Autoload.php');
Autoload::charger();
global $vues, $rep;
echo 'index.php';
require($rep.$vues['main']);
$control = new FrontController();
//session_regenerate_id(true); Autoload::charger();
// session_unset();
// session_destroy();
// $_SESSION = null;
//https://a-pellegrini.developpez.com/temp/tutoriels/php/security/session/#III.2 $control = new FrontController();
?> ?>
Loading…
Cancel
Save