<commit_before><?php
/**
 * Array utility functions.
 *
 * @copyright Copyright (c) 2012 bne1.
 * @author <NAME> [au] <<EMAIL>>
 * @license http://www.opensource.org/licenses/mit-license.php
 *
 * @package Sutra
 * @link http://www.sutralib.com/
 *
 * @version 1.2
 */
class sArray {
  /**
   * Checks if an array has all required keys.
   *
   * @param array $array Array to check.
   * @param array $required_keys Keys that must be in the array.
   * @param boolean $only_required If the array should only have the required keys.
   * @return string|boolean Returns boolean TRUE if the array is valid, or the
   *   missing key.
   *
   * @SuppressWarnings("unused")
   */
  public static function hasRequiredKeys(array $array, array $required_keys, $only_required = FALSE) {
    foreach ($required_keys as $key) {
      if (!array_key_exists($key, $array)) {
        return $key;
      }
    }

    if ($only_required) {
      foreach ($array as $key => $value) {
        if (!in_array($key, $required_keys)) {
          return FALSE;
        }
      }
    }

    return TRUE;
  }
}
<commit_msg>Specific supression of warning; return the first required key if array is empty<commit_after><?php
/**
 * Array utility functions.
 *
 * @copyright Copyright (c) 2012 bne1.
 * @author <NAME> [au] <<EMAIL>>
 * @license http://www.opensource.org/licenses/mit-license.php
 *
 * @package Sutra
 * @link http://www.sutralib.com/
 *
 * @version 1.2
 */
class sArray {
  /**
   * Checks if an array has all required keys.
   *
   * @param array $array Array to check.
   * @param array $required_keys Keys that must be in the array.
   * @param boolean $only_required If the array should only have the required keys.
   * @return string|boolean Returns boolean TRUE if the array is valid, or the
   *   missing key.
   *
   * @SuppressWarnings(PHPMD.UnusedLocalVariable)
   */
  public static function hasRequiredKeys(array $array, array $required_keys, $only_required = FALSE) {
    if (empty($array)) {
      return array_shift($required_keys);
    }

    foreach ($required_keys as $key) {
      if (!array_key_exists($key, $array)) {
        return $key;
      }
    }

    if ($only_required) {
      foreach ($array as $key => $value) {
        if (!in_array($key, $required_keys)) {
          return FALSE;
        }
      }
    }

    return TRUE;
  }
}

{'fraction_non_alphanumeric': 0.12622184445388865, 'fraction_numerical': 0.005949851253718657, 'mean_word_length': 2.7187993680884674, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '6494194', 'n_tokens_mistral': 754, 'n_tokens_neox': 740, 'n_words': 228}