<commit_before><?php

/**
 * @file
 *   Helper functions for hosting_restapi.
 */

/**
 * Validate if the REST-ish function exists
 */
function hosting_restapi_invoke_function($func, $method) {
  $result = [];
  $f = 'hosting_restapi_' . $func . '_' . $method;

  try {
    if (function_exists($f)) {
      $result = $f();
    }
    else {
      $result = [
        'status' => 'error',
        'message' => "Unknown method for $func: $method",
      ];
    }
  }
  catch (Exception $e) {
    $result = [
      'status' => 'error',
      'message' => $e->getMessage(),
    ];
  }

  return $result;
}

/**
 * Checks if authentication token is valid for a given site.
 *
 * @param String $site_name
 * @param String $token
 * @returns Boolean
 */
function hosting_restapi_is_valid_auth_token($url, $token) {
  if (! $url) {
    throw new Exception('Missing url argument.');
  }

  $exists = db_query('SELECT count(*) as cpt FROM hosting_restapi_order WHERE url = :url AND token = :token', array(':url' => $url, ':token' => $token))->fetchField();
  return ($exists ? TRUE : FALSE);
}

/**
 * Given an authentication token, returns the invoice_id.
 * Returns NULL if the token is not valid.
 *
 * @param String $site_name
 * @param String $token
 * @returns Boolean
 */<commit_msg>set an http 500 response code when there are errors<commit_after><?php

/**
 * @file
 *   Helper functions for hosting_restapi.
 */

/**
 * Validate if the REST-ish function exists
 */
function hosting_restapi_invoke_function($func, $method) {
  $result = [];
  $f = 'hosting_restapi_' . $func . '_' . $method;

  try {
    if (function_exists($f)) {
      $result = $f();
    }
    else {
      $result = [
        'status' => 'error',
        'message' => "Unknown method for $func: $method",
      ];
    }
  }
  catch (Exception $e) {
    $result = [
      'status' => 'error',
      'message' => $e->getMessage(),
    ];
  }

  if ($result['status'] == 'error') {
    http_response_code(500);
  }

  return $result;
}

/**
 * Checks if authentication token is valid for a given site.
 *
 * @param String $site_name
 * @param String $token
 * @returns Boolean
 */
function hosting_restapi_is_valid_auth_token($url, $token) {
  if (! $url) {
    throw new Exception('Missing url argument.');
  }

  $exists = db_query('SELECT count(*) as cpt FROM hosting_restapi_order WHERE url = :url AND token = :token', array(':url' => $url, ':token' => $token))->fetchField();
  return ($exists ? TRUE : FALSE);
}

/**
 * Given an authentication token, returns the invoice_id.
 * Returns NULL if the token is not valid.
 *
 * @param String $site_name
 * @param String $token
 * @returns Boolean
 */
{'fraction_non_alphanumeric': 0.16116941529235382, 'fraction_numerical': 0.0022488755622188904, 'mean_word_length': 3.0075075075075075, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 19, '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': '4593507', 'n_tokens_mistral': 878, 'n_tokens_neox': 869, 'n_words': 247}