<commit_before><?php
/**
 * Implementation of the `gulp\smartling\Application` class.
 */
namespace gulp\smartling;

/**
 * An HTTP server that strip comments and whitespace from the files specified in client requests.
 */
class Application {

  /**
   * Handles the PHP execution errors such as warnings and notices.
   * @param int $severity The level of the error raised.
   * @param string $message The error message.
   * @param string $file The filename that the error was raised in.
   * @param int $line The line number the error was raised at.
   * @return bool Whether the error was handled.
   * @throws \ErrorException When an error occurred.
   */
  public function handleError($severity, $message, $file = __FILE__, $line = __LINE__) {
    if(error_reporting() & $severity) throw new \ErrorException($message, 0, $severity, $file, $line);
    return false;
  }

  /**
   * Runs the application.
   * @param array $args The request parameters.
   */
  public function run(array $args = []) {
    set_error_handler([$this, 'handleError']);
    try { $this->sendResponse($this->processRequest($args)); }
    catch(\Exception $e) { $this->sendResponse($e->getMessage(), $e->getCode()); }
  }

  /**
   * Processes the specified request body.
   * @param array $args The request sent by a client.
   * @return string The stripped source code corresponding to the provided file.
   * @throws \Exception The requirements are not met, or an error occurred.
   */
  public function processRequest(array $args) {
    if(!isset($args['file']) || !mb_strlen($args['file'])) throw new \LogicException('Bad Request', 400);
    if(!is_file($args['file'])) throw new \RuntimeException('Not Found', 404);

    $output = php_strip_whitespace($args['file']);
    if(!mb_strlen($output)) throw new \RuntimeException('Internal Server Error', 500);
    return $output;
  }

  /**
   * Sends the specified response body.
   * @param string $body The response body to send to the client.
   * @param int $status
   */
  public function sendResponse($body, $status = 200) {
    http_response_code($status);
    header('Content-Length: ' . strlen($body));
    header('Content-Type: ' . ($status >= 400 ? 'text/plain' : 'application/x-httpd-php'));
    echo $body;
  }
}

// Start the application.
(new Application())->run($_POST);<commit_msg>Improved compatibility with `superagent` module<commit_after><?php
/**
 * Implementation of the `gulp\smartling\Application` class.
 */
namespace gulp\smartling;

/**
 * An HTTP server that strip comments and whitespace from the files specified in client requests.
 */
class Application {

  /**
   * Handles the PHP execution errors such as warnings and notices.
   * @param int $severity The level of the error raised.
   * @param string $message The error message.
   * @param string $file The filename that the error was raised in.
   * @param int $line The line number the error was raised at.
   * @return bool Whether the error was handled.
   * @throws \ErrorException When an error occurred.
   */
  public function handleError($severity, $message, $file = __FILE__, $line = __LINE__) {
    if(error_reporting() & $severity) throw new \ErrorException($message, 0, $severity, $file, $line);
    return false;
  }

  /**
   * Runs the application.
   * @param array $args The request parameters.
   */
  public function run(array $args = []) {
    set_error_handler([$this, 'handleError']);
    try { $this->sendResponse($this->processRequest($args)); }
    catch(\Exception $e) { $this->sendResponse($e->getMessage(), $e->getCode()); }
  }

  /**
   * Processes the specified request body.
   * @param array $args The request sent by a client.
   * @return string The stripped source code corresponding to the provided file.
   * @throws \Exception The requirements are not met, or an error occurred.
   */
  public function processRequest(array $args) {
    if(!isset($args['file']) || !mb_strlen($args['file'])) throw new \LogicException('Bad Request', 400);
    if(!is_file($args['file'])) throw new \RuntimeException('Not Found', 404);

    $output = php_strip_whitespace($args['file']);
    if(!mb_strlen($output)) throw new \RuntimeException('Internal Server Error', 500);
    return $output;
  }

  /**
   * Sends the specified response body.
   * @param string $body The response body to send to the client.
   * @param int $status
   */
  public function sendResponse($body, $status = 200) {
    http_response_code($status);
    header('Content-Length: ' . strlen($body));
    header('Content-Type: text/plain');
    echo $body;
  }
}

// Start the application.
(new Application())->run($_GET);
{'fraction_non_alphanumeric': 0.13596207713854772, 'fraction_numerical': 0.006248653307476837, 'mean_word_length': 3.73190621814475, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 16, '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': '6148717', 'n_tokens_mistral': 1366, 'n_tokens_neox': 1317, 'n_words': 456}