From 3b369122645b07b290f7fcc7bccb4787745cd5ea Mon Sep 17 00:00:00 2001 From: polo Date: Tue, 24 Mar 2026 22:39:29 +0100 Subject: =?UTF-8?q?mode=20maintenance,=20optimisation=20moins=20de=20contr?= =?UTF-8?q?=C3=B4les=20en=20mode=20run,=20dossier=20service=20et=20d=C3=A9?= =?UTF-8?q?placement=20fichiers,=20sessions=20et=20entit=C3=A9=20User=20pr?= =?UTF-8?q?=C3=A9par=C3=A9es=20=C3=A0=20l'impl=C3=A9mentation=20hypoth?= =?UTF-8?q?=C3=A9tique=20des=20r=C3=B4les,=20entit=C3=A9=20AppMetadata,=20?= =?UTF-8?q?meilleure=20s=C3=A9curit=C3=A9=20de=20fillStartingDatabase?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/service/Captcha.php | 55 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 src/service/Captcha.php (limited to 'src/service/Captcha.php') diff --git a/src/service/Captcha.php b/src/service/Captcha.php new file mode 100644 index 0000000..d57f912 --- /dev/null +++ b/src/service/Captcha.php @@ -0,0 +1,55 @@ + on pourrait appliquer le pattern "singleton" (justification = le captcha devient une sorte de ressource partagée) + +declare(strict_types=1); + +class Captcha +{ + private int $a; + private int $b; + + public function __construct(){ + $this->a = rand(2, 9); + $this->b = rand(2, 9); + } + + public function getA(): string + { + return $this->toLettersFrench($this->a); + } + public function getB(): string + { + return $this->toLettersFrench($this->b); + } + public function getSolution(): int + { + return ($this->a * $this->b); + } + + private function toLettersFrench(int $number): string + { + return match($number){ + 2 => 'deux', + 3 => 'trois', + 4 => 'quatre', + 5 => 'cinq', + 6 => 'six', + 7 => 'sept', + 8 => 'huit', + 9 => 'neuf', + default => '', // erreur + }; + } + + // (à déplacer dans FormValidation?) + static public function controlInput(string $input = '0'): int + { + // un POST est une chaîne qu'on doit convertir en nombre dans deux conditions: + // test de format: $input est un nombre + // test d'intégrité: supprimer les décimales avec (int) ne change pas la valeur du nombre + return is_numeric($input) && $input == (int)$input ? (int)$input : 0; + } +} \ No newline at end of file -- cgit v1.2.3