From 6b64c57eadd5d74d53217343962457d71b9099ff Mon Sep 17 00:00:00 2001
From: ArturoDelMadrazo <33378667+Ischyrosmilus@users.noreply.github.com>
Date: Mon, 13 Feb 2023 22:38:53 +0100
Subject: [PATCH] Ajout faker

---
 Faker.php           | 35 +++++++++++++++++++++++++++++++++++
 OpenAIGenerator.php | 14 ++++++++++----
 index.php           |  2 +-
 3 files changed, 46 insertions(+), 5 deletions(-)
 create mode 100644 Faker.php

diff --git a/Faker.php b/Faker.php
new file mode 100644
index 0000000..0576c3c
--- /dev/null
+++ b/Faker.php
@@ -0,0 +1,35 @@
+<?php
+
+class Faker
+{
+    private array $code = ['Filter a array and exclude element if key is "chapeau"', 'Check if word is a palindromic word', 'return a number of occurence for word into a text'];
+    private array $test = ["If you're using JavaScript, you can use the filter method to exclude elements with a key of 'chapeau'. Here's an example:",
+     "A palindromic word is a word that reads the same backward as forward. To check if a word is a palindromic word, you can compare its reverse to the original word. Here's an example in JavaScript:", 
+    "To return the number of occurrences of a word in a text, you can use the split method to convert the text into an array of words, and then use the filter method to count the number of elements in the array that match the target word. Here's an example in JavaScript:"];
+
+    public int $number;
+
+   
+    public function __construct()
+    {
+        $this->number = rand(0, sizeof($this->code)-1);
+    }
+
+
+
+    public function getCode(): string
+    {
+        return $this->code[$this->number];
+    }
+
+    public function getTest(): string
+    {
+        return $this->test[$this->number];
+    }
+
+
+    public function regenerateCode(): void
+    {
+        $this->number = rand(1, sizeof($this->code));
+    }
+}
\ No newline at end of file
diff --git a/OpenAIGenerator.php b/OpenAIGenerator.php
index fcc1a43..c30b272 100644
--- a/OpenAIGenerator.php
+++ b/OpenAIGenerator.php
@@ -1,4 +1,5 @@
 <?php
+require_once('Faker.php');
 class OPenAIGenerator
 {
     private string $question;
@@ -12,6 +13,11 @@ class OPenAIGenerator
     {
         $this->usefaker = $useFaker;
         $this->question = $question;
+        if($useFaker)
+        {
+            $fakerClasse = new Faker();
+            $this->setFaker($fakerClasse);
+        }
         if($generateCode)
         {
             $this->code = $this->genCode();
@@ -19,10 +25,10 @@ class OPenAIGenerator
         $this->test = $this->genTest();
     }
 
-    public function setFaker($faker) // SPECIFY CLASS OF FAKER FOR RETURN TYPE
+    public function setFaker($fakerClasse) // SPECIFY CLASS OF FAKER FOR RETURN TYPE
     {
         // TO DOO SET FAKER CLASSE
-        $this->faker = $faker;
+        $this->faker = $fakerClasse;
     }
 
     public function genCode(): string
@@ -42,7 +48,7 @@ class OPenAIGenerator
         {
             // TO DOO 
             // USE CLASS FAKER FOR RETURN STRING
-            return "";
+            return $this->faker->getCode();
         }
       
     }
@@ -63,7 +69,7 @@ class OPenAIGenerator
         {
             // TO DOO 
             // USE CLASS FAKER FOR RETURN STRING
-            return  "";
+            return  $this->faker->getTest();
         }
         
     }
diff --git a/index.php b/index.php
index 1f895f6..ee6690a 100644
--- a/index.php
+++ b/index.php
@@ -21,7 +21,7 @@ HTMLEOF;
 
 if(!empty($_POST['question']))
 {
-    $gen = new OpenAIGenerator($_POST['question']);
+    $gen = new OpenAIGenerator($_POST['question'], true ,true);
     echo $gen;
 }
 else
-- 
GitLab