<commit_before><?php namespace Wigwam;

use \ReflectionClass;
use \ReflectionMethod;

class Reflect {

  private $name;
  private $api;
  private $taghlrs;
  private $parsehlrs;

  public function __construct($name) {
    $xthis            = $this;
    $this->name       = $name;
    $this->taghlrs    = array();
    $this->parsehlrs  = array();
  }

  public function getName() {
    $app = new ReflectionClass($this->name);
    return $app->getName();
  }

  public function addTagHandler($tag, $handler) {
    $this->taghlrs[$tag] = $handler;
  }

  public function addParseHandler($handler) {
    array_push($this->parsehlrs, $handler);
  }

  public function run() {
    return $this->getApi();
  }

  public function getApi() {
    $app    = new ReflectionClass($this->name);
    $xthis  = $this;

    return $this->api ? $this->api : $this->api = array(
      'name'      => $app->getName(),
      'methods'   => array_values(array_map(function($method) use ($xthis) {
        return $xthis->runParseHandlers(array(
          'name'      => $method->getName(),
          'tags'      => $xthis->parseDoc((string) $method->getDocComment()),
          'params'    => array_map(function($param) {
            return array(
              'name'      => $param->name,
              'optional'  => $param->isOptional()
            );
          }, $method->getParameters())
        ));
      }, $app->getMethods(ReflectionMethod::IS_STATIC)))
    );
  }

  public function runParseHandlers($method) {
    return array_reduce($this->parsehlrs, function($xs, $x) {
      return $xs = $x($xs);
    }, $method);
  }

  public function parseDoc($doc) {
    $xthis = $this;
    return array_reduce(array_keys($this->taghlrs), function($acc, $e) use ($doc, $xthis) {
      $acc[$e] = array_values(array_filter(array_map(function($line) use ($xthis, $e) {
        $toks  = preg_split('/ +/', preg_replace('/^[\s\*]+(@[^\s]+.*)\s*$/', '\1', $line));
        return array_shift($toks) == "@$e"
          ? array_map(function($tok) use ($xthis) {
              return $xthis->parseDocTag($tok);
            }, $toks)
          : null;
      }, preg_split('/\n/', $doc))));
      return $acc;
    }, array());
  }

  public function parseDocTag($tok) {<commit_msg>add default value to method parameter descriptor in API<commit_after><?php namespace Wigwam;

use \ReflectionClass;
use \ReflectionMethod;

class Reflect {

  private $name;
  private $api;
  private $taghlrs;
  private $parsehlrs;

  public function __construct($name) {
    $xthis            = $this;
    $this->name       = $name;
    $this->taghlrs    = array();
    $this->parsehlrs  = array();
  }

  public function getName() {
    $app = new ReflectionClass($this->name);
    return $app->getName();
  }

  public function addTagHandler($tag, $handler) {
    $this->taghlrs[$tag] = $handler;
  }

  public function addParseHandler($handler) {
    array_push($this->parsehlrs, $handler);
  }

  public function run() {
    return $this->getApi();
  }

  public function getApi() {
    $app    = new ReflectionClass($this->name);
    $xthis  = $this;

    return $this->api ? $this->api : $this->api = array(
      'name'      => $app->getName(),
      'methods'   => array_values(array_map(function($method) use ($xthis) {
        return $xthis->runParseHandlers(array(
          'name'      => $method->getName(),
          'tags'      => $xthis->parseDoc((string) $method->getDocComment()),
          'params'    => array_map(function($param) {
            $tmp = array(
              'name'      => $param->name,
              'optional'  => $param->isOptional()
            );
            if ($param->isDefaultValueAvailable())
              $tmp['default'] = $param->getDefaultValue();
            return $tmp;
          }, $method->getParameters())
        ));
      }, $app->getMethods(ReflectionMethod::IS_STATIC)))
    );
  }

  public function runParseHandlers($method) {
    return array_reduce($this->parsehlrs, function($xs, $x) {
      return $xs = $x($xs);
    }, $method);
  }

  public function parseDoc($doc) {
    $xthis = $this;
    return array_reduce(array_keys($this->taghlrs), function($acc, $e) use ($doc, $xthis) {
      $acc[$e] = array_values(array_filter(array_map(function($line) use ($xthis, $e) {
        $toks  = preg_split('/ +/', preg_replace('/^[\s\*]+(@[^\s]+.*)\s*$/', '\1', $line));
        return array_shift($toks) == "@$e"
          ? array_map(function($tok) use ($xthis) {
              return $xthis->parseDocTag($tok);
            }, $toks)
          : null;
      }, preg_split('/\n/', $doc))));
      return $acc;
    }, array());
  }

  public function parseDocTag($tok) {
{'fraction_non_alphanumeric': 0.1823039110921137, 'fraction_numerical': 0.00042744176106005556, 'mean_word_length': 2.5697940503432495, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 67, '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': '2516664', 'n_tokens_mistral': 1532, 'n_tokens_neox': 1508, 'n_words': 292}