<commit_before><?php

use CRM_Basis_ExtensionUtil as E;

/**
 * Google.Afstand API specification (optional)
 * This is used for documentation and validation.
 *
 * @param array $spec description of fields supported by this API call
 * @return void
 * @see http://wiki.civicrm.org/confluence/display/CRMDOC/API+Architecture+Standards
 */
function _civicrm_api3_google_Afstand_spec(&$spec)
{
    $spec['adres'] = array(
        'api.required' => 1,
        'name' => 'adres',
        'title' => 'Adres',
        'type' => CRM_Utils_Type::T_STRING
    );

    $spec['postcode'] = array('api.required' => 1,
        'name' => 'postcode',
        'title' => 'Postcode',
        'type' => CRM_Utils_Type::T_STRING
    );

    $spec['gemeente'] = array('api.required' => 1,
        'name' => 'gemeente',
        'title' => 'Gemeente',
        'type' => CRM_Utils_Type::T_STRING);

    $spec['adres_arts'] = array('api.required' => 1,
        'name' => 'adres_arts',
        'title' => 'Adres Arts',
        'type' => CRM_Utils_Type::T_STRING);

    $spec['postcode_arts'] = array(
        'api.required' => 1,
        'name' => 'postcode_arts',
        'title' => 'Postcode Arts',
        'type' => CRM_Utils_Type::T_STRING);

    $spec['gemeente_arts'] = array('api.required' => 1,
        'name' => 'gemeente_arts',
        'title' => 'Gemeente Arts',
        'type' => CRM_Utils_Type::T_STRING);
}

/**
 * Google.Afstand API
 *
 * @param array $params
 * @return array API result descriptor
 * @see civicrm_api3_create_success
 * @see civicrm_api3_create_error
 * @throws API_Exception
 */
function civicrm_api3_google_Afstand($params)
{
    try {
        $from = $params['adres'] . ',' . $params['postcode'] . ' ' . $params['gemeente'];
        $to = $params['adres_arts'] . ',' . $params['postcode_arts'] . ' ' . $params['gemeente_arts'];
        $from = urlencode($from);
        $to = urlencode($to);
        $data = file_get_contents("http://maps.googleapis.com/maps/api/distancematrix/json?origins=$from&destinations=$to&language=en-EN&sensor=false");
        $data = json_decode($data);
        $time = 0;
        $distance = 0;

        if(isset($data->status)&&$data->status =='OVER_QUERY_LIMIT'){
            return civicrm_api3_create_error("Google is over zijn dagenlijkse aanvraag tax", $params);
        }
        if (isset($data->rows[0])) {
            if ($data->rows[0]->elements[0]->status == 'NOT_FOUND') {
                return civicrm_api3_create_error("Google kent dit adres niet", $params);
            } else {
                foreach ($data->rows[0]->elements as $road) {
                    if (isset($road->duration)) {
                        $time += $road->duration->value;
                        $distance += $road->distance->value;
                    }
                }
            }
        }
        $returnValues = array(
            'km' => round($distance / 1000, 1),
            'reistijd' => round($time / 60, 1)
        );
        return civicrm_api3_create_success($returnValues, $params, 'Google', 'Afstand');
    } catch (Exception $ex) {
        throw new API_Exception("Exception $ex in Api call Google: Afstand");
    }
}<commit_msg>CiviLint<commit_after><?php

use CRM_Basis_ExtensionUtil as E;

/**
 * Google.Afstand API specification (optional)
 * This is used for documentation and validation.
 *
 * @param array $spec description of fields supported by this API call
 *
 * @return void
 * @see http://wiki.civicrm.org/confluence/display/CRMDOC/API+Architecture+Standards
 */
function _civicrm_api3_google_Afstand_spec(&$spec) {
  $spec['adres'] = [
    'api.required' => 1,
    'name' => 'adres',
    'title' => 'Adres',
    'type' => CRM_Utils_Type::T_STRING,
  ];

  $spec['postcode'] = [
    'api.required' => 1,
    'name' => 'postcode',
    'title' => 'Postcode',
    'type' => CRM_Utils_Type::T_STRING,
  ];

  $spec['gemeente'] = [
    'api.required' => 1,
    'name' => 'gemeente',
    'title' => 'Gemeente',
    'type' => CRM_Utils_Type::T_STRING,
  ];

  $spec['adres_arts'] = [
    'api.required' => 1,
    'name' => 'adres_arts',
    'title' => 'Adres Arts',
    'type' => CRM_Utils_Type::T_STRING,
  ];

  $spec['postcode_arts'] = [
    'api.required' => 1,
    'name' => 'postcode_arts',
    'title' => 'Postcode Arts',
    'type' => CRM_Utils_Type::T_STRING,
  ];

  $spec['gemeente_arts'] = [
    'api.required' => 1,
    'name' => 'gemeente_arts',
    'title' => 'Gemeente Arts',
    'type' => CRM_Utils_Type::T_STRING,
  ];
}

/**
 * Google.Afstand API
 *
 * @param array $params
 *
 * @return array API result descriptor
 * @see civicrm_api3_create_success
 * @see civicrm_api3_create_error
 * @throws API_Exception
 */
function civicrm_api3_google_Afstand($params) {
  try {
    $from = $params['adres'] . ',' . $params['postcode'] . ' ' . $params['gemeente'];
    $to = $params['adres_arts'] . ',' . $params['postcode_arts'] . ' ' . $params['gemeente_arts'];
    $from = urlencode($from);
    $to = urlencode($to);
    $data = file_get_contents("http://maps.googleapis.com/maps/api/distancematrix/json?origins=$from&destinations=$to&language=en-EN&sensor=false");
    $data = json_decode($data);
    $time = 0;
    $distance = 0;

    if (isset($data->status) && $data->status == 'OVER_QUERY_LIMIT') {
      return civicrm_api3_create_error("Google is over zijn dagenlijkse aanvraag tax", $params);
    }
    if (isset($data->rows[0])) {
      if ($data->rows[0]->elements[0]->status == 'NOT_FOUND') {
        return civicrm_api3_create_error("Google kent dit adres niet", $params);
      }
      else {
        foreach ($data->rows[0]->elements as $road) {
          if (isset($road->duration)) {
            $time += $road->duration->value;
            $distance += $road->distance->value;
          }
        }
      }
    }
    $returnValues = [
      'km' => round($distance / 1000, 1),
      'reistijd' => round($time / 60, 1),
    ];
    return civicrm_api3_create_success($returnValues, $params, 'Google', 'Afstand');
  }
  catch (Exception $ex) {
    throw new API_Exception("Exception $ex in Api call Google: Afstand");
  }
}
{'fraction_non_alphanumeric': 0.1763261296660118, 'fraction_numerical': 0.008840864440078585, 'mean_word_length': 2.8324968632371395, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 81, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5184085', 'n_tokens_mistral': 2134, 'n_tokens_neox': 2063, 'n_words': 383}