<commit_before><?php
/* This class is part of the XP framework
 *
 * $Id$ 
 */

  uses('util.AssertException');

  /**
   * Assertion
   *
   * <quote>
   * Assertions should be used as a debugging feature only. You may use them 
   * for sanity-checks that test for conditions that should always be TRUE 
   * and that indicate some programming errors if not or to check for the 
   * presence of certain features like extension functions or certain system 
   * limits and features.
   * Assertions should not be used for normal runtime operations like input 
   * parameter checks. As a rule of thumb your code should always be able 
   * to work correctly if assertion checking is not activated.
   * </quote>
   * 
   * Example:
   * <code>
   *   function divide($y, $x) {
   *     Assert::that('${1} != 0', $x) or die(Assert::printException());
   *     return $y / $x;
   *   }
   * </code>
   *
   * @model    static
   * @purpose  Make assertian
   */
  class Assert extends Object {
    var
      $exception= NULL;
      
    /**
     * Callback method for when an assertion failed
     *
     * @access  private
     * @param   string file
     * @param   int line
     * @param   string code
     */
    function onAssertionFailed($file, $line, $code) {
      $this->exception= &new AssertException(sprintf(
        'Assertion {%s} failed at line %d of %s',
        preg_replace('/\$_\[([0-9]+)\]/', '\${$1}', $code),
        $line,
        $file
      ));
    }
  
    /**
     * Get an instance
     *
     * @access  private
     * @return  &util.Assert
     */
    function &getInstance() {
      static $__instance;
      
      if (!isset($__instance)) {
        $__instance= new Assert();
        assert_options(ASSERT_CALLBACK, array(&$__instance, 'onAssertionFailed'));
        assert_options(ASSERT_WARNING, 0);
      }
      return $__instance;
    }
  
    /**
     * Make an assertion
     *
     * @access  public
     * @param   string code
     * @param   mixed* args
     * @return  bool FALSE if assertion failed, TRUE otherwise
     */
    function that() {
      static $instance;
      if (!isset($instance)) $instance= &Assert::getInstance();
      
      $instance->exception= NULL;
      $_= &func_get_args();
      return assert(preg_replace('/\$\{([0-9]+)\}/', '\$_[$1]', $_[0]));
    }
    
    /**
     * Retrieve the exception thrown by the assertion
     *
     * @access  public
     * @return  &util.AssertException
     */
    function &getException() {
      static $instance;
      if (!isset($instance)) $instance= &Assert::getInstance();
      
      return $instance->exception;
    }
    
    /**
     * Print the exception thrown by the assertion
     *
     * @access  public
     */
    function printException() {
      static $instance;
      if (!isset($instance)) $instance= &Assert::getInstance();
      
      if (NULL !== $instance->exception) {
        $instance->exception->printStackTrace();
      }
    }
    
    /**
     * Activate assertions
     *
     * @access  public
     */
    function activate() {
      assert_options(ASSERT_ACTIVE, 1);
    }
    
    /**
     * Deactivate assertions
     *
     * @access  public
     */
    function deactivate() {
      assert_options(ASSERT_ACTIVE, 0);
    }
  }
?>
<commit_msg>- Use $instance instead of $__instance # In general, do not use any variables with double-underscore # "__" is reserved for magic stuff you should *never* touch<commit_after><?php
/* This class is part of the XP framework
 *
 * $Id$ 
 */

  uses('util.AssertException');

  /**
   * Assertion
   *
   * <quote>
   * Assertions should be used as a debugging feature only. You may use them 
   * for sanity-checks that test for conditions that should always be TRUE 
   * and that indicate some programming errors if not or to check for the 
   * presence of certain features like extension functions or certain system 
   * limits and features.
   * Assertions should not be used for normal runtime operations like input 
   * parameter checks. As a rule of thumb your code should always be able 
   * to work correctly if assertion checking is not activated.
   * </quote>
   * 
   * Example:
   * <code>
   *   function divide($y, $x) {
   *     Assert::that('${1} != 0', $x) or die(Assert::printException());
   *     return $y / $x;
   *   }
   * </code>
   *
   * @model    static
   * @purpose  Make assertian
   */
  class Assert extends Object {
    var
      $exception= NULL;
      
    /**
     * Callback method for when an assertion failed
     *
     * @access  private
     * @param   string file
     * @param   int line
     * @param   string code
     */
    function onAssertionFailed($file, $line, $code) {
      $this->exception= &new AssertException(sprintf(
        'Assertion {%s} failed at line %d of %s',
        preg_replace('/\$_\[([0-9]+)\]/', '\${$1}', $code),
        $line,
        $file
      ));
    }
  
    /**
     * Get an instance
     *
     * @access  private
     * @return  &util.Assert
     */
    function &getInstance() {
      static $instance;
      
      if (!isset($instance)) {
        $instance= new Assert();
        assert_options(ASSERT_CALLBACK, array(&$instance, 'onAssertionFailed'));
        assert_options(ASSERT_WARNING, 0);
      }
      return $instance;
    }
  
    /**
     * Make an assertion
     *
     * @access  public
     * @param   string code
     * @param   mixed* args
     * @return  bool FALSE if assertion failed, TRUE otherwise
     */
    function that() {
      static $instance;
      if (!isset($instance)) $instance= &Assert::getInstance();
      
      $instance->exception= NULL;
      $_= &func_get_args();
      return assert(preg_replace('/\$\{([0-9]+)\}/', '\$_[$1]', $_[0]));
    }
    
    /**
     * Retrieve the exception thrown by the assertion
     *
     * @access  public
     * @return  &util.AssertException
     */
    function &getException() {
      static $instance;
      if (!isset($instance)) $instance= &Assert::getInstance();
      
      return $instance->exception;
    }
    
    /**
     * Print the exception thrown by the assertion
     *
     * @access  public
     */
    function printException() {
      static $instance;
      if (!isset($instance)) $instance= &Assert::getInstance();
      
      if (NULL !== $instance->exception) {
        $instance->exception->printStackTrace();
      }
    }
    
    /**
     * Activate assertions
     *
     * @access  public
     */
    function activate() {
      assert_options(ASSERT_ACTIVE, 1);
    }
    
    /**
     * Deactivate assertions
     *
     * @access  public
     */
    function deactivate() {
      assert_options(ASSERT_ACTIVE, 0);
    }
  }
?>

{'fraction_non_alphanumeric': 0.12862453531598514, 'fraction_numerical': 0.0035687732342007433, 'mean_word_length': 2.0924137931034483, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '7137191', 'n_tokens_mistral': 1993, 'n_tokens_neox': 1947, 'n_words': 575}