Your project should only use iterable types in foreach loops 8
- Read doc
- Reliability
- Major
More information: https://insight.symfony.com/what-we-analyse/php.invalid_foreach_iterable
- }
- if (!empty($intent['type'])) {
- $response .= "**Detected Intent:** " . $intent['type'] . "\n\n";
- }
- foreach ($results['products'] as $i => $p) {
- $response .= "**" . ($i + 1) . ". " . ($p['products_name'] ?? '') . "**\n";
- $response .= "💰 Price: " . ($p['products_price'] ?? 'N/A') . "€\n";
- $response .= "📦 Stock: " . ($p['products_quantity'] ?? 'N/A') . " units\n";
- $ean = $p['products_ean'] ?? '';
- // Display applied filters and detected intent
- if (!empty($intent['filters'])) {
- $response .= "**Applied Filters:** ";
- $filters = [];
- foreach ($intent['filters'] as $key => $value) {
- $filters[] = "$key: $value";
- }
- $response .= implode(", ", $filters) . "\n";
- }
- if (!empty($intent['type'])) {
- ');
- $Qcategories->bindInt(':language_id', (int)$this->lang->getId());
- $Qcategories->execute();
- $categories_array = $Qcategories->fetchAll();
- foreach ($categories_array as $cat) {
- $catLower = strtolower($cat['categories_name'] ?? '');
- if (strpos($translated, $catLower) !== false) {
- $intent['entities']['category'] = $catLower;
- $matchWeight += 0.8;
- $totalWeight += 1;
- $stopwords = [
- 'the', 'and', 'for', 'with', 'your', 'our', 'you', 'are', 'not', 'can', 'how', 'what', 'why', 'which', 'have', 'has', 'had', 'from', 'this', 'that', 'these', 'those', 'a', 'an', 'to', 'of', 'in', 'on', 'by', 'at', 'it', 'is', 'as', 'or', 'be', 'do', 'does', 'did', 'me', 'my', 'we', 'us', 'they', 'them', 'their', 'there', 'here', 'about', 'please', 'show', 'find', 'search', 'look', 'list', 'between', 'under', 'over', 'more', 'than', 'less', 'cheaper', 'above', 'below'
- ];
- $tokens = preg_split('/[^a-z0-9]+/i', $translated, -1, PREG_SPLIT_NO_EMPTY);
- foreach ($tokens as $tok) {
- $tokLower = strtolower($tok);
- if (strlen($tokLower) > 2 && !in_array($tokLower, $stopwords, true)) {
- $keywords[] = $tokLower;
- }
- }
- public function install()
- {
- $cut_length = \strlen('CLICSHOPPING_APP_CATEGORIES_' . $this->code . '_');
- foreach ($this->getParameters() as $key) {
- $p = mb_strtolower(substr($key, $cut_length));
- $class = 'ClicShopping\Apps\Catalog\Categories\Module\ClicShoppingAdmin\Config\\' . $this->code . '\Params\\' . $p;
- $cfg = new $class($this->code);
- $cut = 'CLICSHOPPING_APP_CATEGORIES_' . $this->code . '_';
- $cut_length = \strlen($cut);
- foreach ($this->getParameters() as $key) {
- $p = mb_strtolower(substr($key, $cut_length));
- $class = 'ClicShopping\Apps\Catalog\Categories\Module\ClicShoppingAdmin\Config\\' . $this->code . '\Params\\' . $p;
- $cfg = new $class($this->code);
- <td class="text-end"><?php echo $CLICSHOPPING_Api->getDef('text_action'); ?></td>
- </tr>
- </thead>
- <tbody>
- <?php
- foreach ($result as $value) {
- ?>
- <tr>
- <td><?php echo $value['ip']; ?></td>
- <td><?php echo $value['comment']; ?></td>
- <td class="text-end">
- <td class="text-end"><?php echo $CLICSHOPPING_Api->getDef('text_action'); ?></td>
- </tr>
- </thead>
- <tbody>
- <?php
- foreach ($result as $value) {
- ?>
- <tr>
- <td><?php echo $value['session_id']; ?></td>
- <td><?php echo $value['ip']; ?></td>
- <td><?php echo $value['date_added']; ?></td>
Your project should not contain unused code 5
- Read doc
- Productivity
- Minor
More information: https://insight.symfony.com/what-we-analyse/php.unused_local_variable_or_private_member
- * Returns a float score between 0.0 and 1.0 based on the number of citations.
- *
- * @param string $result The AI-generated response to validate.
- * @return float Attribution score (0.0 to 1.0).
- */
- private static function validateAttribution(string $result): float
- {
- $citations = substr_count($result, 'source:') + substr_count($result, '(voir') + preg_match_all('/\[.*?\]/', $result);
- if ($citations === 0) return 0.0;
- * Implements validation heuristics, hallucination detection, and response quality assessment.
- */
- class LlmGuardrails
- {
- private const CONFIDENCE_THRESHOLD = 0.75;
- private const HALLUCINATION_THRESHOLD = 0.8; // a implementer
- private const MAX_RESPONSE_LENGTH = 8192;
- private const MIN_CONFIDENCE_SCORE = 0.6; // a implementer
- protected static ?SecurityLogger $securityLogger = null;
- // Patterns de détection d'hallucinations e-commerce
- class LlmGuardrails
- {
- private const CONFIDENCE_THRESHOLD = 0.75;
- private const HALLUCINATION_THRESHOLD = 0.8; // a implementer
- private const MAX_RESPONSE_LENGTH = 8192;
- private const MIN_CONFIDENCE_SCORE = 0.6; // a implementer
- protected static ?SecurityLogger $securityLogger = null;
- // Patterns de détection d'hallucinations e-commerce
- //possible to create a specific suspicious pattern
- private const SUSPICIOUS_PATTERNS = [];
- * Logs an error message if debugging is enabled.
- * This function is used to log errors related to database operations.
- *
- * @param string $message The error message to log
- */
- private static function logError($message)
- {
- if (\defined('CLICSHOPPING_APP_CHATGPT_RA_DEBUG_RAG_MANAGER') && CLICSHOPPING_APP_CHATGPT_RA_OPENAI_EMBEDDING == 'True') {
- error_log($message);
- }
- }
- */
- private function createEmbeddingGenerator(): EmbeddingGeneratorInterface
- {
- return new class(Gpt::class) implements EmbeddingGeneratorInterface
- {
- private $gptClass;
- /**
- * Constructor for the embedding generator
- *
- * @param string $gptClass Class name of the Gpt instance
gyakutsuki