<commit_before><?php
/**
 *
 * This file is part of Open Library System.
 * Copyright © 2009, <NAME> a/s,
 * Tempovej 7-11, DK-2750 Ballerup, Denmark. CVR: 15149043
 *
 * Open Library System is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Open Library System is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with Open Library System.  If not, see <http://www.gnu.org/licenses/>.
*/


/**
 * \brief singleton class to handle object creation
 *
 * Usage: \n
 * Object::set_value(object, tag-to-set, value); \n
 * Object::set_namespace(object, tag-to-set, value); \n
 * Object::set_array_value(object, array-to-set, value); \n
 * Object::set_element(object, tag-to-set, element, value); \n
 *
 * Example:
 *   instead of:
 *     $test = new stdClass();
 *     $test->tag = new stdClass()
 *     $test->tag->_value = 19;
 *   use:
 *     Object::set_value($test, 'tag', 19);
 *
 *   instead of:
 *     $test = new stdClass();
 *     $test->tag = new stdClass()
 *     $test->tag->_namespace = 'string';
 *   use:
 *     Object::set_namespace($test, 'tag', 'string');
 *
 *   instead of:
 *     $test = new stdClass();
 *     $test->tag = new stdClass()
 *     $test->tag->$sub_tag = 19;
 *   use:
 *     Object::set_element($test, 'tag', 'sub_tag', 19);
 *
 *   instead of:
 *     $test = new stdClass();
 *     $test->arr[] = 19;
 *   use:
 *     Object::set_aray($test, 'arr', 19);
 *
 *   instead of:
 *     $test = new stdClass();
 *     $help = new stdClass();
 *     $help->_value = 19;
 *     $test->arr[] = $help;
 *   use:
 *     Object::set_aray_value($test, 'arr', 19);
 *
 * @author <NAME> - DBC
**/

class Object {

  private function __construct() {}
  private function __destruct() {}
  private function __clone() {}

  /** \brief Sets _value on object
   * @param obj (object) - the object to set
   * @param name (string)
   * @param value (mixed)
   **/
  static public function set_value(&$obj, $name, $value) {
    self::set_element($obj, $name, '_value', $value);
  }

  /** \brief Sets _namespace on object
   * @param obj (object) - the object to set
   * @param name (string)
   * @param value (mixed)
   **/
  static public function set_namespace(&$obj, $name, $value) {
    self::set_element($obj, $name, '_namespace', $value);
  }

  /** \brief Sets an object
   * @param obj (object) - the object to set
   * @param name (string)
   * @param value (mixed)
   **/
  static public function set_array(&$obj, $name, $value) {
    self::check_object_set($obj);
    $obj->{$name}[] = $value;
  }

  /** \brief Sets an object
   * @param obj (object) - the object to set
   * @param name (string)
   * @param value (mixed)
   **/
  static public function set_array_value(&$obj, $name, $value) {
    $help = new stdClass();
    $help->_value = $value;
    self::set_array($obj, $name, $help);
  }

  /** \brief Sets an object
   * @param obj (object) - the object to set
   * @param name (string)
   * @param value (mixed)
   **/
  static public function set(&$obj, $name, $value) {
    self::check_object_set($obj);
    $obj->$name = $value;
  }

  /** \brief Sets element on object
   * @param obj (object) - the object to set
   * @param name (string)
   * @param element (string)
   * @param value (mixed)
   **/
  static public function set_element(&$obj, $name, $element, $value) {
    self::check_object_and_name_set($obj, $name);
    $obj->$name->$element = $value;
  }

  /** \brief makes surre the object is defined
   * @param obj (object) - the object to set
   * @param name (string)
   **/
  static private function check_object_and_name_set(&$obj, $name) {
    self::check_object_set($obj);
    self::check_object_set($obj->$name);
  }

  /** \brief makes surre the object is defined
   * @param obj (object) - the object to set
   **/
  static private function check_object_set(&$obj) {
    if (!isset($obj)) $obj = new stdClass();
  }

}
<commit_msg>set_value new param to check for empty values - defaults to include empty values<commit_after><?php
/**
 *
 * This file is part of Open Library System.
 * Copyright © 2009, Dansk Bibliotekscenter a/s,
 * Tempovej 7-11, DK-2750 Ballerup, Denmark. CVR: 15149043
 *
 * Open Library System is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Open Library System is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with Open Library System.  If not, see <http://www.gnu.org/licenses/>.
*/


/**
 * \brief singleton class to handle object creation
 *
 * Usage: \n
 * Object::set_value(object, tag-to-set, value); \n
 * Object::set_namespace(object, tag-to-set, value); \n
 * Object::set_array_value(object, array-to-set, value); \n
 * Object::set_element(object, tag-to-set, element, value); \n
 *
 * Example:
 *   instead of:
 *     $test = new stdClass();
 *     $test->tag = new stdClass()
 *     $test->tag->_value = 19;
 *   use:
 *     Object::set_value($test, 'tag', 19);
 *
 *   instead of:
 *     $test = new stdClass();
 *     $test->tag = new stdClass()
 *     $test->tag->_namespace = 'string';
 *   use:
 *     Object::set_namespace($test, 'tag', 'string');
 *
 *   instead of:
 *     $test = new stdClass();
 *     $test->tag = new stdClass()
 *     $test->tag->$sub_tag = 19;
 *   use:
 *     Object::set_element($test, 'tag', 'sub_tag', 19);
 *
 *   instead of:
 *     $test = new stdClass();
 *     $test->arr[] = 19;
 *   use:
 *     Object::set_aray($test, 'arr', 19);
 *
 *   instead of:
 *     $test = new stdClass();
 *     $help = new stdClass();
 *     $help->_value = 19;
 *     $test->arr[] = $help;
 *   use:
 *     Object::set_aray_value($test, 'arr', 19);
 *
 * @author <NAME> - DBC
**/

class Object {

  private function __construct() {}
  private function __destruct() {}
  private function __clone() {}

  /** \brief Sets _value on object
   * @param obj (object) - the object to set
   * @param name (string)
   * @param value (mixed)
   **/
  static public function set_value(&$obj, $name, $value, $set_empty = TRUE) {
    if ($set_empty || !empty($value)) self::set_element($obj, $name, '_value', $value);
  }

  /** \brief Sets _namespace on object
   * @param obj (object) - the object to set
   * @param name (string)
   * @param value (mixed)
   **/
  static public function set_namespace(&$obj, $name, $value) {
    self::set_element($obj, $name, '_namespace', $value);
  }

  /** \brief Sets an object
   * @param obj (object) - the object to set
   * @param name (string)
   * @param value (mixed)
   **/
  static public function set_array(&$obj, $name, $value) {
    self::check_object_set($obj);
    $obj->{$name}[] = $value;
  }

  /** \brief Sets an object
   * @param obj (object) - the object to set
   * @param name (string)
   * @param value (mixed)
   **/
  static public function set_array_value(&$obj, $name, $value) {
    $help = new stdClass();
    $help->_value = $value;
    self::set_array($obj, $name, $help);
  }

  /** \brief Sets an object
   * @param obj (object) - the object to set
   * @param name (string)
   * @param value (mixed)
   **/
  static public function set(&$obj, $name, $value) {
    self::check_object_set($obj);
    $obj->$name = $value;
  }

  /** \brief Sets element on object
   * @param obj (object) - the object to set
   * @param name (string)
   * @param element (string)
   * @param value (mixed)
   **/
  static public function set_element(&$obj, $name, $element, $value) {
    self::check_object_and_name_set($obj, $name);
    $obj->$name->$element = $value;
  }

  /** \brief makes surre the object is defined
   * @param obj (object) - the object to set
   * @param name (string)
   **/
  static private function check_object_and_name_set(&$obj, $name) {
    self::check_object_set($obj);
    self::check_object_set($obj->$name);
  }

  /** \brief makes surre the object is defined
   * @param obj (object) - the object to set
   **/
  static private function check_object_set(&$obj) {
    if (!isset($obj)) $obj = new stdClass();
  }

}

{'fraction_non_alphanumeric': 0.15548780487804878, 'fraction_numerical': 0.008130081300813009, 'mean_word_length': 3.083448593822038, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 44, 'https://': 0, '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': '1498030', 'n_tokens_mistral': 2992, 'n_tokens_neox': 2893, 'n_words': 928}