Suggestion correction fiabilité

Bonjour,
Afin d’éviter des logs du type « PHP Notice: Undefined index: properties in /var/www/html/plugins/meteofrance/core/class/meteofrance.class.php on line 438 », il faudrait ajouter quelques tests afin de tester l’existance des index afin d’essayer d’y accéder. Pour l’exemple, la correction de la méthode getBulletinSemaine() ci dessous, mais il y a beaucoup d’autre méthodes à corriger…

  public function getBulletinSemaine() {
    $url = 'https://rpcache-aa.meteofrance.com/internet2018client/2.0/report?domain=france&report_type=forecast&report_subtype=BGP_mensuel';
    $return = self::callMeteoWS($url, true);
    if (is_array($return) && array_key_exists('groupe', $return) && is_array($return['groupe'] && is_array($return['groupe'][0])) {
      if(array_key_exists('date',  $return['groupe'][0])) $this->checkAndUpdateCmd('Bulletindatesem', $return['groupe'][0]['date']);
      if(array_key_exists('titre', $return['groupe'][0])) $this->checkAndUpdateCmd('Bulletintempssem', $return['groupe'][0]['titre']);
    }
  }
1 « J'aime »

Bonjour,

Simplifiable avec isset où il n’est pas nécessaire de tester toutes les dimensions du tableau $return

  public function getBulletinSemaine() {
    $url = 'https://rpcache-aa.meteofrance.com/internet2018client/2.0/report?domain=france&report_type=forecast&report_subtype=BGP_mensuel';
    $return = self::callMeteoWS($url, true);
    if(isset($return['groupe'][0]['date'])) $this->checkAndUpdateCmd('Bulletindatesem', $return['groupe'][0]['date']);
    if(isset($return['groupe'][0]['titre'])) $this->checkAndUpdateCmd('Bulletintempssem', $return['groupe'][0]['titre']);
  }

Merci à Nebz qui me l’a suggéré.

2 « J'aime »