| Conditions | 13 |
| Paths | 7 |
| Total Lines | 52 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 40 | function cvtautosave_formulaire_charger($flux) { |
||
| 41 | if (is_array($flux['data']) |
||
| 42 | and isset($flux['data']['_autosave_id']) |
||
| 43 | and $cle_autosave = $flux['data']['_autosave_id'] |
||
| 44 | ) { |
||
| 45 | |||
| 46 | $form = $flux['args']['form']; |
||
| 47 | $je_suis_poste = $flux['args']['je_suis_poste']; |
||
| 48 | |||
| 49 | $cle_autosave = serialize($cle_autosave); |
||
| 50 | $cle_autosave = $form . "_" . md5($cle_autosave); |
||
| 51 | |||
| 52 | // si on a un backup en session et qu'on est au premier chargement, non poste |
||
| 53 | // on restitue les donnees |
||
| 54 | if (isset($GLOBALS['visiteur_session']['session_autosave_' . $cle_autosave]) |
||
| 55 | and !$je_suis_poste |
||
| 56 | ) { |
||
| 57 | parse_str($GLOBALS['visiteur_session']['session_autosave_' . $cle_autosave], $vars); |
||
| 58 | foreach ($vars as $key => $val) { |
||
|
|
|||
| 59 | if (isset($flux['data'][$key])) { |
||
| 60 | $flux['data'][$key] = (is_string($val) ? autosave_clean_value($val) : array_map('autosave_clean_value', |
||
| 61 | $val)); |
||
| 62 | } |
||
| 63 | } |
||
| 64 | } |
||
| 65 | |||
| 66 | // si on est dans le charger() qui suit le traiter(), l'autosave a normalement ete vide |
||
| 67 | // mais si il y a plusieurs sessions il peut y avoir concurrence et un retour de l'autosave |
||
| 68 | if ($je_suis_poste and _request('autosave') === $cle_autosave and function_exists('terminer_actualiser_sessions')) { |
||
| 69 | terminer_actualiser_sessions(); |
||
| 70 | // et verifions si jamais l'autosave a fait un come back, dans ce cas on le revide |
||
| 71 | if (isset($GLOBALS['visiteur_session']['session_autosave_' . $cle_autosave])) { |
||
| 72 | session_set('session_autosave_' . $cle_autosave, null); |
||
| 73 | // en court sleep pour etre certain que la concurrence est finie |
||
| 74 | sleep(1); |
||
| 75 | terminer_actualiser_sessions(); |
||
| 76 | } |
||
| 77 | } |
||
| 78 | |||
| 79 | |||
| 80 | /** |
||
| 81 | * Envoyer le input hidden et le bout de js qui l'utilisera |
||
| 82 | */ |
||
| 83 | $flux['data']['_hidden'] .= "<input type='hidden' name='autosave' class='autosaveactive' value='$cle_autosave' />" |
||
| 84 | . '<script type="text/javascript">/*<![CDATA[*/if (window.jQuery) jQuery(function(){ |
||
| 85 | $("input.autosaveactive").closest("form:not(.autosaveon)").autosave({url:"' . $GLOBALS['meta']['adresse_site'] . '/"}).addClass("autosaveon"); |
||
| 86 | });/*]]>*/</script>'; |
||
| 87 | |||
| 88 | } |
||
| 89 | |||
| 90 | return $flux; |
||
| 91 | } |
||
| 92 | |||
| 134 |
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.