<commit_before><?php

/**
 *
 * This class allows to consume the API, either from within a module that knows civicrm already:
 *
 * @code
 *   require_once('api/class.api.php');
 *   $api = new civicrm_api3();
 * @endcode
 *
 * or from any code on the same server as civicrm
 *
 * @code
 *   require_once('/your/civi/folder/api/class.api.php');
 *   // the path to civicrm.settings.php
 *   $api = new civicrm_api3 (array('conf_path'=> '/your/path/to/your/civicrm/or/joomla/site));
 * @endcode
 *
 * or to query a remote server via the rest api
 *
 * @code
 *   $api = new civicrm_api3 (array ('server' => 'http://example.org',
 *                                   'api_key'=>'theusersecretkey',
 *                                   'key'=>'thesitesecretkey'));
 * @endcode
 *
 * No matter how initialised and if civicrm is local or remote, you use the class the same way.
 *
 * @code
 *   $api->{entity}->{action}($params);
 * @endcode
 *
 * So, to get the individual contacts:
 *
 * @code
 *   if ($api->Contact->Get(array('contact_type'=>'Individual','return'=>'sort_name,current_employer')) {
 *     // each key of the result array is an attribute of the api
 *     echo "\n contacts found " . $api->count;
 *     foreach ($api->values as $c) {
 *       echo "\n".$c->sort_name. " working for ". $c->current_employer;
 *     }
 *     // in theory, doesn't append
 *   } else {
 *     echo $api->errorMsg();
 *   }
 * @endcode
 *
 * Or, to create an event:
 *
 * @code
 *   if ($api->Event->Create(array('title'=>'Test','event_type_id' => 1,'is_public' => 1,'start_date' => 19430429))) {
 *     echo "created event id:". $api->id;
 *   } else {
 *     echo $api->errorMsg();
 *   }
 * @endcode
 *
 * To make it easier, the Actions can either take for input an
 * associative array $params, or simply an id. The following two lines
 * are equivalent.
 *
 * @code
 *   $api->Activity->Get (42);
 *   $api->Activity->Get (array('id'=>42));
 * @endcode
 *
 *
 * You can also get the result like civicrm_api does, but as an object
 * instead of an array (eg $entity->attribute instead of
 * $entity['attribute']).
 *
 * @code
 *   $result = $api->result;
 *   // is the json encoded result
 *   echo $api;
 * @endcode
 */
class civicrm_api3 {

  /**
   * Class constructor.
   *
   * @param array $config API configuration.
   */
  public function __construct($config = NULL) {
    $this->local      = TRUE;
    $this->input      = array();
    $this->lastResult = array();
    if (isset($config) && isset($config['server'])) {
      // we are calling a remote server via REST
      $this->local = FALSE;
      $this->uri = $config['server'];
      if (isset($config['path'])) {
        $this->uri .= "/" . $config['path'];
      }
      else {
        $this->uri .= '/sites/all/modules/civicrm/extern/rest.php';
      }
      if (isset($config['key'])) {
        $this->key = $config['key'];
      }
      else {
        die("\nFATAL:param['key] missing\n");
      }
      if (isset($config['api_key'])) {
        $this->api_key = $config['api_key'];
      }
      else {
        die("\nFATAL:param['api_key] missing\n");
      }
      return;
    }
    if (isset($config) && isset($config['conf_path'])) {
      define('CIVICRM_SETTINGS_PATH', $config['conf_path'] . '/civicrm.settings.php');
      require_once CIVICRM_SETTINGS_PATH;
      require_once 'CRM/Core/ClassLoader.php';
      require_once 'api/api.php';
      require_once "api/v3/utils.php";
      CRM_Core_ClassLoader::singleton()->register();
      $this->cfg = CRM_Core_Config::singleton();
      $this->init();
    }
    else {
      $this->cfg = CRM_Core_Config::singleton();
    }
  }

  /**
   * Convert to string.
   *
   * @return string
   */
  public function __toString() {
    return json_encode($this->lastResult);
  }

  /**
   * Perform action.
   *
   * @param $action
   * @param $params
   *
   * @return bool
   */
  public function __call($action, $params) {
    // @TODO Check if it's a valid action.
    if (isset($params[0])) {
      return $this->call($this->currentEntity, $action, $params[0]);
    }
    else {
      return $this->call($this->currentEntity, $action, $this->input);
    }
  }

  /**
   * As of PHP 5.3.0.
   *
   * @param $name
   * @param $arguments
   */
  public static function __callStatic($name, $arguments) {
    // Should we implement it ?
    echo "Calling static method '$name' " . implode(', ', $arguments) . "\n";
  }
<commit_msg>Api remove unused fn<commit_after><?php

/**
 *
 * This class allows to consume the API, either from within a module that knows civicrm already:
 *
 * @code
 *   require_once('api/class.api.php');
 *   $api = new civicrm_api3();
 * @endcode
 *
 * or from any code on the same server as civicrm
 *
 * @code
 *   require_once('/your/civi/folder/api/class.api.php');
 *   // the path to civicrm.settings.php
 *   $api = new civicrm_api3 (array('conf_path'=> '/your/path/to/your/civicrm/or/joomla/site));
 * @endcode
 *
 * or to query a remote server via the rest api
 *
 * @code
 *   $api = new civicrm_api3 (array ('server' => 'http://example.org',
 *                                   'api_key'=>'theusersecretkey',
 *                                   'key'=>'thesitesecretkey'));
 * @endcode
 *
 * No matter how initialised and if civicrm is local or remote, you use the class the same way.
 *
 * @code
 *   $api->{entity}->{action}($params);
 * @endcode
 *
 * So, to get the individual contacts:
 *
 * @code
 *   if ($api->Contact->Get(array('contact_type'=>'Individual','return'=>'sort_name,current_employer')) {
 *     // each key of the result array is an attribute of the api
 *     echo "\n contacts found " . $api->count;
 *     foreach ($api->values as $c) {
 *       echo "\n".$c->sort_name. " working for ". $c->current_employer;
 *     }
 *     // in theory, doesn't append
 *   } else {
 *     echo $api->errorMsg();
 *   }
 * @endcode
 *
 * Or, to create an event:
 *
 * @code
 *   if ($api->Event->Create(array('title'=>'Test','event_type_id' => 1,'is_public' => 1,'start_date' => 19430429))) {
 *     echo "created event id:". $api->id;
 *   } else {
 *     echo $api->errorMsg();
 *   }
 * @endcode
 *
 * To make it easier, the Actions can either take for input an
 * associative array $params, or simply an id. The following two lines
 * are equivalent.
 *
 * @code
 *   $api->Activity->Get (42);
 *   $api->Activity->Get (array('id'=>42));
 * @endcode
 *
 *
 * You can also get the result like civicrm_api does, but as an object
 * instead of an array (eg $entity->attribute instead of
 * $entity['attribute']).
 *
 * @code
 *   $result = $api->result;
 *   // is the json encoded result
 *   echo $api;
 * @endcode
 */
class civicrm_api3 {

  /**
   * Class constructor.
   *
   * @param array $config API configuration.
   */
  public function __construct($config = NULL) {
    $this->local      = TRUE;
    $this->input      = array();
    $this->lastResult = array();
    if (isset($config) && isset($config['server'])) {
      // we are calling a remote server via REST
      $this->local = FALSE;
      $this->uri = $config['server'];
      if (isset($config['path'])) {
        $this->uri .= "/" . $config['path'];
      }
      else {
        $this->uri .= '/sites/all/modules/civicrm/extern/rest.php';
      }
      if (isset($config['key'])) {
        $this->key = $config['key'];
      }
      else {
        die("\nFATAL:param['key] missing\n");
      }
      if (isset($config['api_key'])) {
        $this->api_key = $config['api_key'];
      }
      else {
        die("\nFATAL:param['api_key] missing\n");
      }
      return;
    }
    if (isset($config) && isset($config['conf_path'])) {
      define('CIVICRM_SETTINGS_PATH', $config['conf_path'] . '/civicrm.settings.php');
      require_once CIVICRM_SETTINGS_PATH;
      require_once 'CRM/Core/ClassLoader.php';
      require_once 'api/api.php';
      require_once "api/v3/utils.php";
      CRM_Core_ClassLoader::singleton()->register();
      $this->cfg = CRM_Core_Config::singleton();
      $this->init();
    }
    else {
      $this->cfg = CRM_Core_Config::singleton();
    }
  }

  /**
   * Convert to string.
   *
   * @return string
   */
  public function __toString() {
    return json_encode($this->lastResult);
  }

  /**
   * Perform action.
   *
   * @param $action
   * @param $params
   *
   * @return bool
   */
  public function __call($action, $params) {
    // @TODO Check if it's a valid action.
    if (isset($params[0])) {
      return $this->call($this->currentEntity, $action, $params[0]);
    }
    else {
      return $this->call($this->currentEntity, $action, $this->input);
    }
  }

{'fraction_non_alphanumeric': 0.17389293559949126, 'fraction_numerical': 0.005202913631633715, 'mean_word_length': 2.523421588594705, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 101, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2184775', 'n_tokens_mistral': 2926, 'n_tokens_neox': 2871, 'n_words': 688}