<commit_before><?php

/**
 * @group linter
 */
final class ArcanistPhutilXHPASTLinter extends ArcanistBaseXHPASTLinter {

  const LINT_ARRAY_COMBINE           = 2;
  const LINT_DEPRECATED_FUNCTION     = 3;
  const LINT_UNSAFE_DYNAMIC_STRING   = 4;

  private $xhpastLinter;
  private $deprecatedFunctions = array();
  private $dynamicStringFunctions = array();
  private $dynamicStringClasses = array();

  public function setXHPASTLinter(ArcanistXHPASTLinter $linter) {
    $this->xhpastLinter = $linter;
    return $this;
  }

  public function setDeprecatedFunctions($map) {
    $this->deprecatedFunctions = $map;
    return $this;
  }

  public function setDynamicStringFunctions($map) {
    $this->dynamicStringFunctions = $map;
    return $this;
  }

  public function setDynamicStringClasses($map) {
    $this->dynamicStringClasses = $map;
    return $this;
  }

  public function setEngine(ArcanistLintEngine $engine) {
    if (!$this->xhpastLinter) {
      throw new Exception(
        'Call setXHPASTLinter() before using ArcanistPhutilXHPASTLinter.');
    }
    $this->xhpastLinter->setEngine($engine);
    return parent::setEngine($engine);
  }

  public function getLintNameMap() {
    return array(
      self::LINT_ARRAY_COMBINE           => 'array_combine() Unreliable',
      self::LINT_DEPRECATED_FUNCTION     => 'Use of Deprecated Function',
      self::LINT_UNSAFE_DYNAMIC_STRING   => 'Unsafe Usage of Dynamic String',
    );
  }

  public function getLintSeverityMap() {
    $warning = ArcanistLintSeverity::SEVERITY_WARNING;
    return array(
      self::LINT_ARRAY_COMBINE           => $warning,
      self::LINT_DEPRECATED_FUNCTION     => $warning,
      self::LINT_UNSAFE_DYNAMIC_STRING   => $warning,
    );
  }

  public function getLinterName() {
    return 'PHLXHP';
  }

  public function getCacheVersion() {
    $version = '2';
    $path = xhpast_get_binary_path();
    if (Filesystem::pathExists($path)) {
      $version .= '-'.md5_file($path);
    }
    return $version;
  }

  protected function buildFutures(array $paths) {
    return $this->xhpastLinter->buildFutures($paths);
  }

  protected function resolveFuture($path, Future $future) {
    $tree = $this->xhpastLinter->getXHPASTTreeForPath($path);
    if (!$tree) {
      return;
    }

    $root = $tree->getRootNode();
<commit_msg>Call willLintPath() hook from PhutilLinter<commit_after><?php

/**
 * @group linter
 */
final class ArcanistPhutilXHPASTLinter extends ArcanistBaseXHPASTLinter {

  const LINT_ARRAY_COMBINE           = 2;
  const LINT_DEPRECATED_FUNCTION     = 3;
  const LINT_UNSAFE_DYNAMIC_STRING   = 4;

  private $xhpastLinter;
  private $deprecatedFunctions = array();
  private $dynamicStringFunctions = array();
  private $dynamicStringClasses = array();

  public function setXHPASTLinter(ArcanistXHPASTLinter $linter) {
    $this->xhpastLinter = $linter;
    return $this;
  }

  public function setDeprecatedFunctions($map) {
    $this->deprecatedFunctions = $map;
    return $this;
  }

  public function setDynamicStringFunctions($map) {
    $this->dynamicStringFunctions = $map;
    return $this;
  }

  public function setDynamicStringClasses($map) {
    $this->dynamicStringClasses = $map;
    return $this;
  }

  public function setEngine(ArcanistLintEngine $engine) {
    if (!$this->xhpastLinter) {
      throw new Exception(
        'Call setXHPASTLinter() before using ArcanistPhutilXHPASTLinter.');
    }
    $this->xhpastLinter->setEngine($engine);
    return parent::setEngine($engine);
  }

  public function getLintNameMap() {
    return array(
      self::LINT_ARRAY_COMBINE           => 'array_combine() Unreliable',
      self::LINT_DEPRECATED_FUNCTION     => 'Use of Deprecated Function',
      self::LINT_UNSAFE_DYNAMIC_STRING   => 'Unsafe Usage of Dynamic String',
    );
  }

  public function getLintSeverityMap() {
    $warning = ArcanistLintSeverity::SEVERITY_WARNING;
    return array(
      self::LINT_ARRAY_COMBINE           => $warning,
      self::LINT_DEPRECATED_FUNCTION     => $warning,
      self::LINT_UNSAFE_DYNAMIC_STRING   => $warning,
    );
  }

  public function getLinterName() {
    return 'PHLXHP';
  }

  public function getCacheVersion() {
    $version = '2';
    $path = xhpast_get_binary_path();
    if (Filesystem::pathExists($path)) {
      $version .= '-'.md5_file($path);
    }
    return $version;
  }

  protected function buildFutures(array $paths) {
    return $this->xhpastLinter->buildFutures($paths);
  }

  public function willLintPath($path) {
    $this->xhpastLinter->willLintPath($path);
    return parent::willLintPath($path);
  }

  protected function resolveFuture($path, Future $future) {
    $tree = $this->xhpastLinter->getXHPASTTreeForPath($path);
    if (!$tree) {
      return;
    }

    $root = $tree->getRootNode();

{'fraction_non_alphanumeric': 0.1180873180873181, 'fraction_numerical': 0.002079002079002079, 'mean_word_length': 3.5906488549618323, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 41, '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': '3425955', 'n_tokens_mistral': 1636, 'n_tokens_neox': 1596, 'n_words': 294}