original_string: public static function validate($data) {
          // Get all user profile fields definition.
          self::fill_properties_cache();
  
          foreach ($data as $property => $value) {
              try {
                  if (isset(self::$propertiescache[$property])) {
                      validate_param($value, self::$propertiescache[$property]['type'], self::$propertiescache[$property]['null']);
                  }
                  // Check that the value is part of a list of allowed values.
                  if (!empty(self::$propertiescache[$property]['choices']) &&
                          !isset(self::$propertiescache[$property]['choices'][$value])) {
                      throw new invalid_parameter_exception($value);
                  }
              } catch (invalid_parameter_exception $e) {
                  $errors[$property] = $e->getMessage();
              }
          }
  
          return empty($errors) ? true : $errors;
      }
code: public static function validate($data) {
          // Get all user profile fields definition.
          self::fill_properties_cache();
  
          foreach ($data as $property => $value) {
              try {
                  if (isset(self::$propertiescache[$property])) {
                      validate_param($value, self::$propertiescache[$property]['type'], self::$propertiescache[$property]['null']);
                  }
                  // Check that the value is part of a list of allowed values.
                  if (!empty(self::$propertiescache[$property]['choices']) &&
                          !isset(self::$propertiescache[$property]['choices'][$value])) {
                      throw new invalid_parameter_exception($value);
                  }
              } catch (invalid_parameter_exception $e) {
                  $errors[$property] = $e->getMessage();
              }
          }
  
          return empty($errors) ? true : $errors;
      }
code_tokens: public static function validate ( $ data ) { // Get all user profile fields definition. self :: fill_properties_cache ( ) ; foreach ( $ data as $ property => $ value ) { try { if ( isset ( self :: $ propertiescache [ $ property ] ) ) { validate_param ( $ value , self :: $ propertiescache [ $ property ] [ 'type' ] , self :: $ propertiescache [ $ property ] [ 'null' ] ) ; } // Check that the value is part of a list of allowed values. if ( ! empty ( self :: $ propertiescache [ $ property ] [ 'choices' ] ) && ! isset ( self :: $ propertiescache [ $ property ] [ 'choices' ] [ $ value ] ) ) { throw new invalid_parameter_exception ( $ value ) ; } } catch ( invalid_parameter_exception $ e ) { $ errors [ $ property ] = $ e -> getMessage ( ) ; } } return empty ( $ errors ) ? true : $ errors ; }
docstring: Validate user data.
  
  This method just validates each user field and return an array of errors. It doesn't clean the data,
  the methods clean() and clean_field() should be used for this purpose.
  
  @param stdClass|array $data user data object or array to be validated.
  @return array|true $errors array of errors found on the user object, true if the validation passed.
docstring_tokens: Validate user data .