<commit_before><?php
/*
 * $Id$
 *
 * Diese Klasse ist Bestandteil des XP-Frameworks
 * (c) 2001 <NAME>, Schlund+Partner AG
 *
 * @see http://doku.elite.schlund.de/projekte/xp/skeleton/
 *
 */

  define('COMMENT_ID_CLASS',    '__CLASS__');

  /**
   * Gibt Informationen zu einer Klasse zurck
   *
   */
  class ClassInfo extends Object {
    var 
      $className,
      $classPath;
      
    var
      $_comments;
    
    function __construct($params= NULL) {
      Object::__construct($params);
      if (isset($params['class'])) $this->setClass($params['class']);
    }
    
    function setClassFile($filename) {
      return $this->setClass(strtr($filename, array(
        '/'             => '.',
        '.class.php'    => '',
        SKELETON_PATH   => ''
      )));
    }
    
    function setClass($class) {
      try(); {
        import($class);
      } if (catch('Exception', $e)) {
        return throw($e);
      }      
      $parts= explode('.', $class);
      $this->className= $parts[sizeof($parts)- 1];
      $this->classPath= implode('.', array_slice($parts, 0, -1));
      if (!class_exists(strtolower($this->className))) {
        return throw(new IOException('noclassdeffounderror'));
      }
    }
    
    function _new() {
      $reflect= strtolower($this->className);
      $this->object= &new $reflect;
    }
    
    function _destroy() {
      $this->object->__destruct();
    }
    
    function _parse() {
      $fd= fopen(SKELETON_PATH.'/'.strtr($this->classPath.'.'.$this->className, array(
        '.'     => '/'
      )).'.class.php', 'r');
      if (!$fd) {
        return throw(new IOException($this->classPath.'.'.$this->className));
      }
      
      $this->_comments= array();
      $cid= -1;
      while (!feof($fd)) {
        $line= chop(fgets($fd, 4096));
        
        // CVS-Versions-Info suchen
        // Beispiel: $Id$
        if (preg_match(
          '#\$Id: [a-zA-Z]+\.class\.php,v ([0-9\.]+) ([0-9/\.]+ [0-9/:]+) ([a-z]+) Exp#', 
          $line, 
          $regs
        )) {
          $this->_version= new StdClass();
          $this->_version->num= $regs[1];
          $this->_version->date= $regs[2];
          $this->_version->author= $regs[3];
        }

        // Kommentar-Anfang suchen
        // DOC_Kommentare fangen mit /** an
        if (preg_match('=^[\s\t]*/\*\*[\s\t]*$=', $line)) {
          $comment= '';
          $cid= sizeof($this->_comments);
          continue;
        }

        // Kommentar-Ende?
        // DOC_Kommentare hren mit */ auf
        if (preg_match('=^[\s\t]*\*/[\s\t]*$=', $line) && $cid>= 0) {

          $c= new StdClass();
          $c->access= 'public';
          $c->return= new StdClass();
          $c->return->type= 'void';
          $c->params= array();
          $c->see= array();
          $c->throws= array();
          
          // In der nchsten Zeile kommt die Funktion. Sonst ist es Klassendoku
          // "    function unLock() {"
          $line= chop(fgets($fd, 4096));
          $cid= COMMENT_ID_CLASS;
          if (preg_match(
            '=^[\s\t]+function[\s\t]+&?([a-zA-Z_]+)[\s\t]*\([^\)]*\)[\s\t\{]*$=',
            $line,
            $regs
          )) {
            $c->function= $regs[1];
            $cid= strtolower($c->function);
          }
          $lines= explode("\n", $comment);
          foreach ($lines as $i=> $line) {
            if ('@' == substr($line, 0, 1)) {
              list($indicator, $doc)= preg_split('/\s+/', substr($line, 1), 2);
              switch ($indicator) {
                case 'return':
                  list(
                    $c->return->type, 
                    $c->return->comment
                  )= explode(' ', $doc, 2);
                  break;
                case 'param':
                  $param= new StdClass();
                  list(
                    $param->type,
                    $param->var,
                    $param->comment
                  )= explode(' ', $doc, 3);
                  if (preg_match('/^default ([^\s]+)/', $param->comment, $regs)) {
                    $param->default= $regs[1];
                    $param->comment= str_replace($regs[0], '', $param->comment);
                  }
                  $c->params[]= $param;
                  break;
                case 'see':
                  $c->see[]= $doc;
                  break;
                case 'throws':
                  $except= new StdClass;
                  list($except->name, $except->comment)= preg_split('/,? /', $doc, 2);
                  $c->throws[]= $except;
                  break;
                default:
                  $c->$indicator= $doc;
                  break;
              }
              unset($lines[$i]);
            }
          }
          $c->comment= chop(implode("\n", $lines));

          $this->_comments[$cid]= $c;
          $cid= -1;
        }

        if ($cid>= 0) $comment.= preg_replace('=^[^\*]+\* ?=', '', $line)."\n";
      }
      fclose($fd);
    }<commit_msg>-ClassLoader benutzen und Exceptions<commit_after><?php
/*
 * $Id$
 *
 * Diese Klasse ist Bestandteil des XP-Frameworks
 * (c) 2001 <NAME>, Schlund+Partner AG
 *
 * @see http://doku.elite.schlund.de/projekte/xp/skeleton/
 *
 */

  define('COMMENT_ID_CLASS',    '__CLASS__');

  /**
   * Gibt Informationen zu einer Klasse zurck
   *
   */
  class ClassInfo extends Object {
    var 
      $className,
      $classPath;
      
    var
      $_comments;
    
    function __construct($params= NULL) {
      Object::__construct($params);
      if (isset($params['class'])) $this->setClass($params['class']);
    }
    
    function setClassFile($filename) {
      return $this->setClass(strtr($filename, array(
        '/'             => '.',
        '.class.php'    => '',
        SKELETON_PATH   => ''
      )));
    }
    
    function setClass($class) {
      try(); {
        $name= ClassLoader::loadClass($class);
      } if (catch('Exception', $e)) {
        return throw($e);
      }      
      $this->className= substr($class, strrpos($class, '.')+ 1);
      $this->classPath= substr($class, 0, strrpos($class, '.'));
    }
    
    function _new() {
      $reflect= strtolower($this->className);
      $this->object= &new $reflect;
    }
    
    function _destroy() {
      $this->object->__destruct();
    }
    
    function _parse() {
      $fd= fopen(SKELETON_PATH.'/'.strtr($this->classPath.'.'.$this->className, array(
        '.'     => '/'
      )).'.class.php', 'r');
      if (!$fd) {
        return throw(new IOException($this->classPath.'.'.$this->className));
      }
      
      $this->_comments= array();
      $cid= -1;
      while (!feof($fd)) {
        $line= chop(fgets($fd, 4096));
        
        // CVS-Versions-Info suchen
        // Beispiel: $Id$
        if (preg_match(
          '#\$Id: [a-zA-Z]+\.class\.php,v ([0-9\.]+) ([0-9/\.]+ [0-9/:]+) ([a-z]+) Exp#', 
          $line, 
          $regs
        )) {
          $this->_version= new StdClass();
          $this->_version->num= $regs[1];
          $this->_version->date= $regs[2];
          $this->_version->author= $regs[3];
        }

        // Kommentar-Anfang suchen
        // DOC_Kommentare fangen mit /** an
        if (preg_match('=^[\s\t]*/\*\*[\s\t]*$=', $line)) {
          $comment= '';
          $cid= sizeof($this->_comments);
          continue;
        }

        // Kommentar-Ende?
        // DOC_Kommentare hren mit */ auf
        if (preg_match('=^[\s\t]*\*/[\s\t]*$=', $line) && $cid>= 0) {

          $c= new StdClass();
          $c->access= 'public';
          $c->return= new StdClass();
          $c->return->type= 'void';
          $c->params= array();
          $c->see= array();
          $c->throws= array();
          
          // In der nchsten Zeile kommt die Funktion. Sonst ist es Klassendoku
          // "    function unLock() {"
          $line= chop(fgets($fd, 4096));
          $cid= COMMENT_ID_CLASS;
          if (preg_match(
            '=^[\s\t]+function[\s\t]+&?([a-zA-Z_]+)[\s\t]*\([^\)]*\)[\s\t\{]*$=',
            $line,
            $regs
          )) {
            $c->function= $regs[1];
            $cid= strtolower($c->function);
          }
          $lines= explode("\n", $comment);
          foreach ($lines as $i=> $line) {
            if ('@' == substr($line, 0, 1)) {
              list($indicator, $doc)= preg_split('/\s+/', substr($line, 1), 2);
              switch ($indicator) {
                case 'return':
                  @list(
                    $c->return->type, 
                    $c->return->comment
                  )= explode(' ', $doc, 2);
                  break;
                case 'param':
                  $param= new StdClass();
                  @list(
                    $param->type,
                    $param->var,
                    $param->comment
                  )= explode(' ', $doc, 3);
                  if (preg_match('/^default ([^\s]+)/', $param->comment, $regs)) {
                    $param->default= $regs[1];
                    $param->comment= str_replace($regs[0], '', $param->comment);
                  }
                  $c->params[]= $param;
                  break;
                case 'see':
                  $c->see[]= $doc;
                  break;
                case 'throws':
                  $except= new StdClass;
                  @list(
                    $except->name, 
                    $except->comment
                  )= preg_split('/,? /', $doc, 2);
                  $c->throws[]= $except;
                  break;
                default:
                  $c->$indicator= $doc;
                  break;
              }
              unset($lines[$i]);
            }
          }
          $c->comment= chop(implode("\n", $lines));

          $this->_comments[$cid]= $c;
          $cid= -1;
        }

        if ($cid>= 0) $comment.= preg_replace('=^[^\*]+\* ?=', '', $line)."\n";
      }
      fclose($fd);
    }
{'fraction_non_alphanumeric': 0.19583794108776514, 'fraction_numerical': 0.007539961797526892, 'mean_word_length': 1.3994211287988423, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 118, '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': '5695819', 'n_tokens_mistral': 3267, 'n_tokens_neox': 3118, 'n_words': 563}