From 8c663379dcb9859a060e07681cc9082c025cf203 Mon Sep 17 00:00:00 2001 From: polo Date: Thu, 22 May 2025 16:59:25 +0200 Subject: classe Captcha --- src/controller/Captcha.php | 52 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/controller/Captcha.php (limited to 'src/controller/Captcha.php') diff --git a/src/controller/Captcha.php b/src/controller/Captcha.php new file mode 100644 index 0000000..3253b95 --- /dev/null +++ b/src/controller/Captcha.php @@ -0,0 +1,52 @@ +a = rand(2, 9); + $this->b = rand(2, 9); + $this->solution = $this->a * $this->b; + } + + public function getA(): string + { + return $this->toLettersFrench($this->a); + } + public function getB(): string + { + return $this->toLettersFrench($this->b); + } + public function getSolution(): int + { + return $this->solution; + } + + 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 + }; + } + static public function controlInput(string $input = '0'): int + { + // un POST est une chaîne qu'on doit convertir en nombre si: + // 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