From d352704c7029ec4a2c8d5157de7a91561c782fd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=AFeul=20Rouquette?= <maieul@maieul.net> Date: Fri, 15 Sep 2023 21:50:28 +0200 Subject: [PATCH] =?UTF-8?q?style:=20initier=20les=20variables=20importante?= =?UTF-8?q?s=20en=20d=C3=A9but=20de=20fonction=20(d=C3=A9tection=20par=20P?= =?UTF-8?q?HPstan)=20+=20mieux=20g=C3=A9rer=20un=20cas=20de=20`static`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- action/dupliquer_formulaire.php | 1 + action/editer_formulaire.php | 1 + echanger/formulaire/forms.php | 2 ++ echanger/formulaire/wcs.php | 2 ++ echanger/formulaire/yaml.php | 1 + formidable_fonctions.php | 1 + formulaires/exporter_formulaire_analyse.php | 1 + formulaires/formidable.php | 4 ++++ http/collectionjson/formulaires_reponses.php | 1 + inc/formidable.php | 11 ++++++++--- 10 files changed, 22 insertions(+), 3 deletions(-) diff --git a/action/dupliquer_formulaire.php b/action/dupliquer_formulaire.php index f5a7efc0..81e30951 100644 --- a/action/dupliquer_formulaire.php +++ b/action/dupliquer_formulaire.php @@ -18,6 +18,7 @@ function action_dupliquer_formulaire_dist($arg = null) { $arg = $securiser_action(); } $id_formulaire = intval($arg); + $erreur = ''; // Si le formulaire existe bien if ( diff --git a/action/editer_formulaire.php b/action/editer_formulaire.php index 21a1908a..0f345a65 100644 --- a/action/editer_formulaire.php +++ b/action/editer_formulaire.php @@ -15,6 +15,7 @@ function action_editer_formulaire_dist($arg = null) { $securiser_action = charger_fonction('securiser_action', 'inc'); $arg = $securiser_action(); } + $err = ''; // si id_formulaire n'est pas un nombre, c'est une creation if (!$id_formulaire = intval($arg)) { diff --git a/echanger/formulaire/forms.php b/echanger/formulaire/forms.php index 9592dcdc..988009d5 100644 --- a/echanger/formulaire/forms.php +++ b/echanger/formulaire/forms.php @@ -11,6 +11,8 @@ function echanger_formulaire_forms_importer_dist($fichier) { include_spip('inc/xml'); $arbre = spip_xml_load($fichier, false); + $id_formulaire = 0; + if (isset($arbre['forms'])) { foreach ($arbre['forms'] as $forms) { foreach ($forms['form'] as $form) { diff --git a/echanger/formulaire/wcs.php b/echanger/formulaire/wcs.php index d2f1ab8b..fb64881c 100644 --- a/echanger/formulaire/wcs.php +++ b/echanger/formulaire/wcs.php @@ -11,6 +11,8 @@ function echanger_formulaire_wcs_importer_dist($fichier) { include_spip('inc/saisies'); include_spip('inc/formidable'); $arbre = spip_xml_load($fichier, false); + $id_formulaire = 0; + $erreur = ''; if (isset($arbre['formdef'])) { foreach ($arbre['formdef'] as $form) { diff --git a/echanger/formulaire/yaml.php b/echanger/formulaire/yaml.php index fd86d06b..bae945e8 100644 --- a/echanger/formulaire/yaml.php +++ b/echanger/formulaire/yaml.php @@ -42,6 +42,7 @@ function echanger_formulaire_yaml_importer_dist($fichier) { $erreur = ''; // Si on a bien recupere une chaine on tente de la decoder + $yaml = '';//Pour PHPstan if (lire_fichier($fichier, $yaml) && $yaml) { include_spip('inc/yaml'); $formulaire = yaml_decode($yaml); diff --git a/formidable_fonctions.php b/formidable_fonctions.php index 78c04f31..c6b77ffb 100644 --- a/formidable_fonctions.php +++ b/formidable_fonctions.php @@ -154,6 +154,7 @@ function calculer_voir_reponse($id_formulaires_reponse, $id_formulaire, $nom, $s function affiche_resume_reponse($id_formulaires_reponse, $id_formulaire = null, $modele_resume = null) { static $modeles_resume = []; static $saisies_form = []; + $saisies = []; include_spip('formidable_fonctions'); diff --git a/formulaires/exporter_formulaire_analyse.php b/formulaires/exporter_formulaire_analyse.php index b1e977f7..16434df1 100644 --- a/formulaires/exporter_formulaire_analyse.php +++ b/formulaires/exporter_formulaire_analyse.php @@ -74,6 +74,7 @@ function action_exporter_analyse_reponses($id_formulaire, $delim = ',') { $valeurs[$r['nom']][] = formidable_deserialize($r['valeur']); } + $reponse_complete[] = []; foreach ($saisies as $nom => $saisie) { $valeur = sql_getfetsel( 'valeur', diff --git a/formulaires/formidable.php b/formulaires/formidable.php index 12c34d55..dbac5546 100644 --- a/formulaires/formidable.php +++ b/formulaires/formidable.php @@ -67,6 +67,7 @@ function formidable_id_formulaire($id) { **/ function formulaires_formidable_saisies_dist($id, $valeurs = [], $options_appel = [], $deprecated_url_redirect = false, $deprecated_forcer_modif = false) { $saisies = []; + $formulaire = []; include_spip('formidable_fonctions'); if ( ($id_formulaire = formidable_id_formulaire($id)) @@ -113,8 +114,10 @@ function formulaires_formidable_saisies_dist($id, $valeurs = [], $options_appel **/ function formulaires_formidable_charger_dist($id, $valeurs = [], $options_appel = [], $deprecated_url_redirect = false, $deprecated_forcer_modif = false) { $contexte = []; + $formulaire = []; include_spip('formidable_fonctions'); + $options_appel = formulaires_formidable_normaliser_options_appel($options_appel, $deprecated_url_redirect, $deprecated_forcer_modif); $id_formulaires_reponse = $options_appel['id_formulaires_reponse']; @@ -316,6 +319,7 @@ function formulaires_formidable_verifier_traitements($id, $valeurs = [], $option $erreurs = []; $id_formulaires_reponse = $options_appel['id_formulaires_reponse'] ?? false; include_spip('formidable_fonctions'); + $formulaire = []; if ( ($id_formulaire = formidable_id_formulaire($id)) diff --git a/http/collectionjson/formulaires_reponses.php b/http/collectionjson/formulaires_reponses.php index 63c7d88c..dd2a3d16 100644 --- a/http/collectionjson/formulaires_reponses.php +++ b/http/collectionjson/formulaires_reponses.php @@ -18,6 +18,7 @@ function http_collectionjson_formulaires_reponses_post_collection_dist($requete, include_spip('inc/session'); include_spip('inc/autoriser'); $fonction_erreur = charger_fonction('erreur', 'http/collectionjson/'); + $id_formulaire = 0; // On teste si on a bien du contenu au bon format if ( diff --git a/inc/formidable.php b/inc/formidable.php index f587af75..e44c16fb 100644 --- a/inc/formidable.php +++ b/inc/formidable.php @@ -162,6 +162,7 @@ function formidable_verifier_reponse_formulaire($id_formulaire, $choix_identific $nom_cookie = formidable_generer_nom_cookie($id_formulaire); $cookie = isset($_COOKIE[$nom_cookie]) ? $_COOKIE[$nom_cookie] : false; $variable_php_identification = formidable_variable_php_identification($variable_php_identification, $id_formulaire); + $where = ''; // ni cookie ni id, ni variable_php, on ne peut rien faire if (!$cookie && !$id_auteur && !$variable_php_identification) { @@ -504,6 +505,8 @@ function formidable_raccourcis_arobases_2_valeurs_champs(string $chaine, array $ $id_formulaire = $options['id_formulaire'] ?? 0; $contexte = $options['contexte'] ?? ''; + $valeurs = []; + $valeurs_libellees = []; if ($source === 'request') { list($valeurs, $valeurs_libellees) = formidable_tableau_valeurs_saisies($saisies, $sans_reponse); @@ -594,12 +597,13 @@ function formidable_raccourcis_arobases_2_valeurs_champs(string $chaine, array $ * On met les résultats en statiques pour gagner un peu de temps */ function formidable_tableau_valeurs_saisies($saisies, $sans_reponse = true) { - if (isset($valeurs)) { + static $valeurs = []; + static $valeurs_libellees = []; + static $done = false; + if ($done) { return [$valeurs,$valeurs_libellees]; } // On parcourt les champs pour générer le tableau des valeurs - static $valeurs = []; - static $valeurs_libellees = []; if ($sans_reponse === true) { $sans_reponse = _T('saisies:sans_reponse'); } @@ -636,6 +640,7 @@ function formidable_tableau_valeurs_saisies($saisies, $sans_reponse = true) { )); } } + $done = true; return [$valeurs, $valeurs_libellees]; } -- GitLab