<commit_before><?php
/**
* lookup media via the iTunes API
*
* The Apples search API is documented here https://www.apple.com/itunes/affiliates/resources/documentation/itunes-store-web-service-search-api.html
*
* @author <NAME> <<EMAIL>>
*/
class iTunesAPI
{
  
  private function __construct() {
    # code...
  }
  
  /**
   * search for a song and return a result object or raw json if specified via options
   *
   * @param string $find 
   * @param string $options 
   * @return object or JSON string if specified in options
   */
  static function search($find,$options=null) { // search music in english
    $defaultOptions = array(
      'max'     => 5,         // max results to return
      'country' => 'GB',      // country code of store to search
      'entity'  => 'song',    // what to search for 
      'media'   => 'music',
      'json'    => false
    );
    if (!is_array($options)) {
      $options = array();
    }
    $optionsToUse = array_merge($defaultOptions,$options);
    $raw = self::getData(
      'https://itunes.apple.com/search?media='.$optionsToUse['media'].
      '&entity='.$optionsToUse['entity'].
      '&country='.$optionsToUse['country'].
      '&limit='.$optionsToUse['max'].
      '&term='.urlencode($find)
    );
    return $optionsToUse['json'] ? $raw : json_decode($raw);
  }
  
  static function minimalSearch($find,$options=null) { // search and return first matching result else false
    $results = self::search($find,$options);
    if ($results && $results->resultCount > 0) {
      return $results->results[0];
    }
    return false;
  }

  // returns content from the specified URL
  static private function getData($url) {
    $ch = curl_init($url);
    curl_setopt_array(
      $ch,
      array(
        CURLOPT_HEADER => false,
        CURLOPT_POST => false,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_SSL_VERIFYPEER => false,
        CURLOPT_USERAGENT => 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)'
      )
    );
    $output = curl_exec($ch);
    $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    $redirectUrl = ($http_code == 302) ? curl_getinfo($ch,CURLINFO_EFFECTIVE_URL) : null;
    $error_no = curl_errno($ch);
    if ($error_no != 0) {
      throw new \Exception(__METHOD__.':Data fetch failed curl error:'.$error_no);
    }
    if ($http_code != 200) {
      throw new \Exception(__METHOD__.':Data fetch failed http code:'.$http_code.(($redirectUrl) ? ', redirect: '.$redirectUrl : ''));
    }
    curl_close($ch);
    return $output;
  }
}
<commit_msg>Scrutinizer Auto-Fixes<commit_after><?php
/**
* lookup media via the iTunes API
*
* The Apples search API is documented here https://www.apple.com/itunes/affiliates/resources/documentation/itunes-store-web-service-search-api.html
*
* @author <NAME> <<EMAIL>>
*/
class iTunesAPI
{
  
  private function __construct() {
    # code...
  }
  
  /**
   * search for a song and return a result object or raw json if specified via options
   *
   * @param string $find 
   * @param string $options 
   * @return object or JSON string if specified in options
   */
  static function search($find, $options = null) { // search music in english
    $defaultOptions = array(
      'max'     => 5, // max results to return
      'country' => 'GB', // country code of store to search
      'entity'  => 'song', // what to search for 
      'media'   => 'music',
      'json'    => false
    );
    if (!is_array($options)) {
      $options = array();
    }
    $optionsToUse = array_merge($defaultOptions, $options);
    $raw = self::getData(
      'https://itunes.apple.com/search?media='.$optionsToUse['media'].
      '&entity='.$optionsToUse['entity'].
      '&country='.$optionsToUse['country'].
      '&limit='.$optionsToUse['max'].
      '&term='.urlencode($find)
    );
    return $optionsToUse['json'] ? $raw : json_decode($raw);
  }
  
  static function minimalSearch($find, $options = null) { // search and return first matching result else false
    $results = self::search($find, $options);
    if ($results && $results->resultCount > 0) {
      return $results->results[0];
    }
    return false;
  }

  // returns content from the specified URL

  /**
   * @param string $url
   */
  static private function getData($url) {
    $ch = curl_init($url);
    curl_setopt_array(
      $ch,
      array(
        CURLOPT_HEADER => false,
        CURLOPT_POST => false,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_SSL_VERIFYPEER => false,
        CURLOPT_USERAGENT => 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)'
      )
    );
    $output = curl_exec($ch);
    $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    $redirectUrl = ($http_code == 302) ? curl_getinfo($ch, CURLINFO_EFFECTIVE_URL) : null;
    $error_no = curl_errno($ch);
    if ($error_no != 0) {
      throw new \Exception(__METHOD__.':Data fetch failed curl error:'.$error_no);
    }
    if ($http_code != 200) {
      throw new \Exception(__METHOD__.':Data fetch failed http code:'.$http_code.(($redirectUrl) ? ', redirect: '.$redirectUrl : ''));
    }
    curl_close($ch);
    return $output;
  }
}

{'fraction_non_alphanumeric': 0.15188145837395203, 'fraction_numerical': 0.006239032949892766, 'mean_word_length': 2.877551020408163, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 35, 'https://': 4, 'lorem ipsum': 0, 'www.': 2, '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': '2702071', 'n_tokens_mistral': 1681, 'n_tokens_neox': 1631, 'n_words': 399}