<commit_before><?php

namespace SearchApi\Support;


use Exception;

/**
 * Class Json_Decoder - decodes the json from a Geocoder
 *
 * @throws Exception - error if bad json object or json string
 */
class JsonDecoder {

  /**
   * Function: reverse_geocoder_json_decoder
   *
   * @param Json obj $json_results
   * @throws Exception -  error if bad json object or json string
   */
  public function reverse_geocoder_json_decoder( $json_results ) {
    // code that decodes the json object into anrray
    // make sure utf8 format
    $json_results = utf8_encode( $json_results );
    // decode json into associate array
    $returnArrays = true;
    $geocoder_results = json_decode( $json_results, $returnArrays );

    // checking if received Json was valid
    if ( $geocoder_results === null ) {
      throw new Exception( 'Invalid Json Object' );
    }

    // check for valid key
    if ( array_key_exists( 'status', $geocoder_results ) &&
        $geocoder_results['status'] !== 'OK' ) {
      // UPDATE: update with new "Invalid Key" status
      if ( $geocoder_results['status'] === 'REQUEST_DENIED' ) {
        throw new Exception( 'Invalid Key' );
      }
      throw new Exception( 'Invalid Json String' );
    }

    // return decoded json
    return $geocoder_results;
  }
}<commit_msg>add status info to invalid json exception<commit_after><?php

namespace SearchApi\Support;


use Exception;

/**
 * Class Json_Decoder - decodes the json from a Geocoder
 *
 * @throws Exception - error if bad json object or json string
 */
class JsonDecoder {

  /**
   * Function: reverse_geocoder_json_decoder
   *
   * @param Json obj $json_results
   * @throws Exception -  error if bad json object or json string
   */
  public function reverse_geocoder_json_decoder( $json_results ) {
    // code that decodes the json object into anrray
    // make sure utf8 format
    $json_results = utf8_encode( $json_results );
    // decode json into associate array
    $returnArrays = true;
    $geocoder_results = json_decode( $json_results, $returnArrays );

    // checking if received Json was valid
    if ( $geocoder_results === null ) {
      throw new Exception( 'Invalid Json Object' );
    }

    // check for valid key
    if ( array_key_exists( 'status', $geocoder_results ) &&
        $geocoder_results['status'] !== 'OK' ) {
      // UPDATE: update with new "Invalid Key" status
      if ( $geocoder_results['status'] === 'REQUEST_DENIED' ) {
        throw new Exception( 'Invalid Key' );
      }
      throw new Exception( "Invalid Json String: Status: {$geocoder_results['status']}" );
    }

    // return decoded json
    return $geocoder_results;
  }
}
{'fraction_non_alphanumeric': 0.10445526020217147, 'fraction_numerical': 0.001497566454511419, 'mean_word_length': 2.994020926756353, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '3503581', 'n_tokens_mistral': 801, 'n_tokens_neox': 781, 'n_words': 252}