<commit_before><?php

/**
 * Uses XHPAST to apply lint rules to PHP.
 */
final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {

  const LINT_PHP_SYNTAX_ERROR          = 1;
  const LINT_UNABLE_TO_PARSE           = 2;
  const LINT_VARIABLE_VARIABLE         = 3;
  const LINT_EXTRACT_USE               = 4;
  const LINT_UNDECLARED_VARIABLE       = 5;
  const LINT_PHP_SHORT_TAG             = 6;
  const LINT_PHP_ECHO_TAG              = 7;
  const LINT_PHP_CLOSE_TAG             = 8;
  const LINT_NAMING_CONVENTIONS        = 9;
  const LINT_IMPLICIT_CONSTRUCTOR      = 10;
  const LINT_DYNAMIC_DEFINE            = 12;
  const LINT_STATIC_THIS               = 13;
  const LINT_PREG_QUOTE_MISUSE         = 14;
  const LINT_PHP_OPEN_TAG              = 15;
  const LINT_TODO_COMMENT              = 16;
  const LINT_EXIT_EXPRESSION           = 17;
  const LINT_COMMENT_STYLE             = 18;
  const LINT_CLASS_FILENAME_MISMATCH   = 19;
  const LINT_TAUTOLOGICAL_EXPRESSION   = 20;
  const LINT_PLUS_OPERATOR_ON_STRINGS  = 21;
  const LINT_DUPLICATE_KEYS_IN_ARRAY   = 22;
  const LINT_REUSED_ITERATORS          = 23;
  const LINT_BRACE_FORMATTING          = 24;
  const LINT_PARENTHESES_SPACING       = 25;
  const LINT_CONTROL_STATEMENT_SPACING = 26;
  const LINT_BINARY_EXPRESSION_SPACING = 27;
  const LINT_ARRAY_INDEX_SPACING       = 28;
  const LINT_RAGGED_CLASSTREE_EDGE     = 29;
  const LINT_IMPLICIT_FALLTHROUGH      = 30;
  const LINT_PHP_53_FEATURES           = 31;
  const LINT_REUSED_AS_ITERATOR        = 32;
  const LINT_COMMENT_SPACING           = 34;
  const LINT_PHP_54_FEATURES           = 35;
  const LINT_SLOWNESS                  = 36;
  const LINT_CLOSING_CALL_PAREN        = 37;
  const LINT_CLOSING_DECL_PAREN        = 38;
  const LINT_REUSED_ITERATOR_REFERENCE = 39;
  const LINT_KEYWORD_CASING            = 40;

  private $naminghook;
  private $switchhook;

  public function getInfoName() {
    return 'XHPAST Lint';
  }

  public function getInfoDescription() {
    return pht(
      'Use XHPAST to enforce Phabricator coding conventions on PHP source '.
      'files. This linter is intended for use in Phabricator libraries and '.
      'extensions, and enforces some Phabricator-specific style rules. It '.
      'may not work well for general PHP source.');
  }

  public function getLintNameMap() {
    return array(
      self::LINT_PHP_SYNTAX_ERROR          => 'PHP Syntax Error!',
      self::LINT_UNABLE_TO_PARSE           => 'Unable to Parse',
      self::LINT_VARIABLE_VARIABLE         => 'Use of Variable Variable',
      self::LINT_EXTRACT_USE               => 'Use of extract()',
      self::LINT_UNDECLARED_VARIABLE       => 'Use of Undeclared Variable',
      self::LINT_PHP_SHORT_TAG             => 'Use of Short Tag "<?"',
      self::LINT_PHP_ECHO_TAG              => 'Use of Echo Tag "<?="',
      self::LINT_PHP_CLOSE_TAG             => 'Use of Close Tag "?>"',
      self::LINT_NAMING_CONVENTIONS        => 'Naming Conventions',
      self::LINT_IMPLICIT_CONSTRUCTOR      => 'Implicit Constructor',
      self::LINT_DYNAMIC_DEFINE            => 'Dynamic define()',
      self::LINT_STATIC_THIS               => 'Use of $this in Static Context',
      self::LINT_PREG_QUOTE_MISUSE         => 'Misuse of preg_quote()',
      self::LINT_PHP_OPEN_TAG              => 'Expected Open Tag',
      self::LINT_TODO_COMMENT              => 'TODO Comment',
      self::LINT_EXIT_EXPRESSION           => 'Exit Used as Expression',
      self::LINT_COMMENT_STYLE             => 'Comment Style',
      self::LINT_CLASS_FILENAME_MISMATCH   => 'Class-Filename Mismatch',
      self::LINT_TAUTOLOGICAL_EXPRESSION   => 'Tautological Expression',
      self::LINT_PLUS_OPERATOR_ON_STRINGS  => 'Not String Concatenation',
      self::LINT_DUPLICATE_KEYS_IN_ARRAY   => 'Duplicate Keys in Array',
      self::LINT_REUSED_ITERATORS          => 'Reuse of Iterator Variable',
      self::LINT_BRACE_FORMATTING          => 'Brace placement',
      self::LINT_PARENTHESES_SPACING       => 'Spaces Inside Parentheses',
      self::LINT_CONTROL_STATEMENT_SPACING => 'Space After Control Statement',
      self::LINT_BINARY_EXPRESSION_SPACING => 'Space Around Binary Operator',
      self::LINT_ARRAY_INDEX_SPACING       => 'Spacing Before Array Index',
      self::LINT_RAGGED_CLASSTREE_EDGE     => 'Class Not abstract Or final',
      self::LINT_IMPLICIT_FALLTHROUGH      => 'Implicit Fallthrough',
      self::LINT_PHP_53_FEATURES           => 'Use Of PHP 5.3 Features',
      self::LINT_PHP_54_FEATURES           => 'Use Of PHP 5.4 Features',
      self::LINT_REUSED_AS_ITERATOR        => 'Variable Reused As Iterator',
      self::LINT_COMMENT_SPACING           => 'Comment Spaces',
      self::LINT_SLOWNESS                  => 'Slow Construct',
      self::LINT_CLOSING_CALL_PAREN        => 'Call Formatting',
      self::LINT_CLOSING_DECL_PAREN        => 'Declaration Formatting',
      self::LINT_REUSED_ITERATOR_REFERENCE => 'Reuse of Iterator References',
      self::LINT_KEYWORD_CASING            => 'Keyword Conventions',
    );
  }

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

  public function getLinterConfigurationName() {
    return 'xhpast';
  }

  public function getLintSeverityMap() {
    $disabled = ArcanistLintSeverity::SEVERITY_DISABLED;
    $advice   = ArcanistLintSeverity::SEVERITY_ADVICE;
    $warning  = ArcanistLintSeverity::SEVERITY_WARNING;

    return array(
      self::LINT_TODO_COMMENT              => $disabled,
      self::LINT_UNABLE_TO_PARSE           => $warning,
      self::LINT_NAMING_CONVENTIONS        => $warning,
      self::LINT_PREG_QUOTE_MISUSE         => $advice,
      self::LINT_BRACE_FORMATTING          => $warning,
      self::LINT_PARENTHESES_SPACING       => $warning,
      self::LINT_CONTROL_STATEMENT_SPACING => $warning,
      self::LINT_BINARY_EXPRESSION_SPACING => $warning,
      self::LINT_ARRAY_INDEX_SPACING       => $warning,
      self::LINT_IMPLICIT_FALLTHROUGH      => $warning,
      self::LINT_SLOWNESS                  => $warning,
      self::LINT_COMMENT_SPACING           => $advice,
      self::LINT_CLOSING_CALL_PAREN        => $warning,
      self::LINT_CLOSING_DECL_PAREN        => $warning,
      self::LINT_REUSED_ITERATOR_REFERENCE => $warning,
      self::LINT_KEYWORD_CASING            => $warning,

      // This is disabled by default because it implies a very strict policy
      // which isn't necessary in the general case.
      self::LINT_RAGGED_CLASSTREE_EDGE     => $disabled,

      // This is disabled by default because projects don't necessarily target
      // a specific minimum version.
      self::LINT_PHP_53_FEATURES           => $disabled,
      self::LINT_PHP_54_FEATURES           => $disabled,
    );
  }

  public function getLinterConfigurationOptions() {
    return parent::getLinterConfigurationOptions() + array(
      'xhpast.naminghook' => array(
        'type' => 'optional ArcanistXHPASTLintNamingHook',
        'help' => pht(''),
      ),
      'xhpast.switchhook' => array(
        'type' => 'optional ArcanistXHPASTLintSwitchHook',
        'help' => pht(''),
      ),
    );
  }

  public function setLinterConfigurationValue($key, $value) {
    switch ($key) {
      case 'xhpast.naminghook':
        $this->naminghook = $value;
        return;
      case 'xhpast.switchhook':
        $this->switchhook = $value;
        return;
    }

    return parent::setLinterConfigurationValue($key, $value);
  }

  public function getCacheVersion() {
    $version = '4';<commit_msg>Minor tweaks for XHPAST config<commit_after><?php

/**
 * Uses XHPAST to apply lint rules to PHP.
 */
final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {

  const LINT_PHP_SYNTAX_ERROR          = 1;
  const LINT_UNABLE_TO_PARSE           = 2;
  const LINT_VARIABLE_VARIABLE         = 3;
  const LINT_EXTRACT_USE               = 4;
  const LINT_UNDECLARED_VARIABLE       = 5;
  const LINT_PHP_SHORT_TAG             = 6;
  const LINT_PHP_ECHO_TAG              = 7;
  const LINT_PHP_CLOSE_TAG             = 8;
  const LINT_NAMING_CONVENTIONS        = 9;
  const LINT_IMPLICIT_CONSTRUCTOR      = 10;
  const LINT_DYNAMIC_DEFINE            = 12;
  const LINT_STATIC_THIS               = 13;
  const LINT_PREG_QUOTE_MISUSE         = 14;
  const LINT_PHP_OPEN_TAG              = 15;
  const LINT_TODO_COMMENT              = 16;
  const LINT_EXIT_EXPRESSION           = 17;
  const LINT_COMMENT_STYLE             = 18;
  const LINT_CLASS_FILENAME_MISMATCH   = 19;
  const LINT_TAUTOLOGICAL_EXPRESSION   = 20;
  const LINT_PLUS_OPERATOR_ON_STRINGS  = 21;
  const LINT_DUPLICATE_KEYS_IN_ARRAY   = 22;
  const LINT_REUSED_ITERATORS          = 23;
  const LINT_BRACE_FORMATTING          = 24;
  const LINT_PARENTHESES_SPACING       = 25;
  const LINT_CONTROL_STATEMENT_SPACING = 26;
  const LINT_BINARY_EXPRESSION_SPACING = 27;
  const LINT_ARRAY_INDEX_SPACING       = 28;
  const LINT_RAGGED_CLASSTREE_EDGE     = 29;
  const LINT_IMPLICIT_FALLTHROUGH      = 30;
  const LINT_PHP_53_FEATURES           = 31;
  const LINT_REUSED_AS_ITERATOR        = 32;
  const LINT_COMMENT_SPACING           = 34;
  const LINT_PHP_54_FEATURES           = 35;
  const LINT_SLOWNESS                  = 36;
  const LINT_CLOSING_CALL_PAREN        = 37;
  const LINT_CLOSING_DECL_PAREN        = 38;
  const LINT_REUSED_ITERATOR_REFERENCE = 39;
  const LINT_KEYWORD_CASING            = 40;

  private $naminghook;
  private $switchhook;

  public function getInfoName() {
    return 'XHPAST Lint';
  }

  public function getInfoDescription() {
    return pht(
      'Use XHPAST to enforce Phabricator coding conventions on PHP source '.
      'files. This linter is intended for use in Phabricator libraries and '.
      'extensions, and enforces some Phabricator-specific style rules. It '.
      'may not work well for general PHP source.');
  }

  public function getLintNameMap() {
    return array(
      self::LINT_PHP_SYNTAX_ERROR          => 'PHP Syntax Error!',
      self::LINT_UNABLE_TO_PARSE           => 'Unable to Parse',
      self::LINT_VARIABLE_VARIABLE         => 'Use of Variable Variable',
      self::LINT_EXTRACT_USE               => 'Use of extract()',
      self::LINT_UNDECLARED_VARIABLE       => 'Use of Undeclared Variable',
      self::LINT_PHP_SHORT_TAG             => 'Use of Short Tag "<?"',
      self::LINT_PHP_ECHO_TAG              => 'Use of Echo Tag "<?="',
      self::LINT_PHP_CLOSE_TAG             => 'Use of Close Tag "?>"',
      self::LINT_NAMING_CONVENTIONS        => 'Naming Conventions',
      self::LINT_IMPLICIT_CONSTRUCTOR      => 'Implicit Constructor',
      self::LINT_DYNAMIC_DEFINE            => 'Dynamic define()',
      self::LINT_STATIC_THIS               => 'Use of $this in Static Context',
      self::LINT_PREG_QUOTE_MISUSE         => 'Misuse of preg_quote()',
      self::LINT_PHP_OPEN_TAG              => 'Expected Open Tag',
      self::LINT_TODO_COMMENT              => 'TODO Comment',
      self::LINT_EXIT_EXPRESSION           => 'Exit Used as Expression',
      self::LINT_COMMENT_STYLE             => 'Comment Style',
      self::LINT_CLASS_FILENAME_MISMATCH   => 'Class-Filename Mismatch',
      self::LINT_TAUTOLOGICAL_EXPRESSION   => 'Tautological Expression',
      self::LINT_PLUS_OPERATOR_ON_STRINGS  => 'Not String Concatenation',
      self::LINT_DUPLICATE_KEYS_IN_ARRAY   => 'Duplicate Keys in Array',
      self::LINT_REUSED_ITERATORS          => 'Reuse of Iterator Variable',
      self::LINT_BRACE_FORMATTING          => 'Brace placement',
      self::LINT_PARENTHESES_SPACING       => 'Spaces Inside Parentheses',
      self::LINT_CONTROL_STATEMENT_SPACING => 'Space After Control Statement',
      self::LINT_BINARY_EXPRESSION_SPACING => 'Space Around Binary Operator',
      self::LINT_ARRAY_INDEX_SPACING       => 'Spacing Before Array Index',
      self::LINT_RAGGED_CLASSTREE_EDGE     => 'Class Not abstract Or final',
      self::LINT_IMPLICIT_FALLTHROUGH      => 'Implicit Fallthrough',
      self::LINT_PHP_53_FEATURES           => 'Use Of PHP 5.3 Features',
      self::LINT_PHP_54_FEATURES           => 'Use Of PHP 5.4 Features',
      self::LINT_REUSED_AS_ITERATOR        => 'Variable Reused As Iterator',
      self::LINT_COMMENT_SPACING           => 'Comment Spaces',
      self::LINT_SLOWNESS                  => 'Slow Construct',
      self::LINT_CLOSING_CALL_PAREN        => 'Call Formatting',
      self::LINT_CLOSING_DECL_PAREN        => 'Declaration Formatting',
      self::LINT_REUSED_ITERATOR_REFERENCE => 'Reuse of Iterator References',
      self::LINT_KEYWORD_CASING            => 'Keyword Conventions',
    );
  }

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

  public function getLinterConfigurationName() {
    return 'xhpast';
  }

  public function getLintSeverityMap() {
    $disabled = ArcanistLintSeverity::SEVERITY_DISABLED;
    $advice   = ArcanistLintSeverity::SEVERITY_ADVICE;
    $warning  = ArcanistLintSeverity::SEVERITY_WARNING;

    return array(
      self::LINT_TODO_COMMENT              => $disabled,
      self::LINT_UNABLE_TO_PARSE           => $warning,
      self::LINT_NAMING_CONVENTIONS        => $warning,
      self::LINT_PREG_QUOTE_MISUSE         => $advice,
      self::LINT_BRACE_FORMATTING          => $warning,
      self::LINT_PARENTHESES_SPACING       => $warning,
      self::LINT_CONTROL_STATEMENT_SPACING => $warning,
      self::LINT_BINARY_EXPRESSION_SPACING => $warning,
      self::LINT_ARRAY_INDEX_SPACING       => $warning,
      self::LINT_IMPLICIT_FALLTHROUGH      => $warning,
      self::LINT_SLOWNESS                  => $warning,
      self::LINT_COMMENT_SPACING           => $advice,
      self::LINT_CLOSING_CALL_PAREN        => $warning,
      self::LINT_CLOSING_DECL_PAREN        => $warning,
      self::LINT_REUSED_ITERATOR_REFERENCE => $warning,
      self::LINT_KEYWORD_CASING            => $warning,

      // This is disabled by default because it implies a very strict policy
      // which isn't necessary in the general case.
      self::LINT_RAGGED_CLASSTREE_EDGE     => $disabled,

      // This is disabled by default because projects don't necessarily target
      // a specific minimum version.
      self::LINT_PHP_53_FEATURES           => $disabled,
      self::LINT_PHP_54_FEATURES           => $disabled,
    );
  }

  public function getLinterConfigurationOptions() {
    return parent::getLinterConfigurationOptions() + array(
      'xhpast.naminghook' => array(
        'type' => 'optional string',
        'help' => pht(
          'Name of a concrete subclass of ArcanistXHPASTLintNamingHook which '.
          'enforces more granular naming convention rules for symbols.'),
      ),
      'xhpast.switchhook' => array(
        'type' => 'optional string',
        'help' => pht(
          'Name of a concrete subclass of ArcanistXHPASTLintSwitchHook which '.
          'tunes the analysis of switch() statements for this linter.'),
      ),
    );
  }

  public function setLinterConfigurationValue($key, $value) {
    switch ($key) {
      case 'xhpast.naminghook':
        $this->naminghook = $value;
        return;
      case 'xhpast.switchhook':
        $this->switchhook = $value;
        return;
    }

    return parent::setLinterConfigurationValue($key, $value);
  }

  public function getCacheVersion() {
    $version = '4';
{'fraction_non_alphanumeric': 0.0907906734401459, 'fraction_numerical': 0.010941774130519734, 'mean_word_length': 2.5977038425492034, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 135, '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': '4810901', 'n_tokens_mistral': 5340, 'n_tokens_neox': 5069, 'n_words': 998}