<commit_before><?php

/**
 * @file Pygmentize.php
 * @brief This file contains the Pygmentize class.
 * @details
 * @author <NAME>
 */


/*
 * @brief Global namespace for the Pygmentize class.
 */
namespace Pygmentize;


/**
 * @brief Pygments is a wrapper to 'pygmentize', the command line interface provided by Pygments, a python syntax
 * highlighter.
 */
class Pygmentize {

  // Binary name.
  const PIGMENTS_BINARY = "pygmentize";


  /**
   * @brief Formats the provided source code using the specified formatter and style.
   * @param[in] string $source The source code.
   * @param[in] string $language The programming language name of the source code.
   * @param[in] string $encoding The file input and output encodings.
   * @param[in] string $formatter The output will be created using the provided formatter.
   * @param[in] string $style The style used by the formatter.
   * @return string The highlighted source code.
   */
  public static function highlight($source, $language, $encoding = "utf-8", $formatter = "html", $style = "borland") {

    // Try to create a temporary physical file. The function 'proc_open' doesn't allow to use a memory file.
    if ($fd = fopen("php://temp", "r+")) {
      fputs($fd, $source); // We don't need to flush because we call rewind.
      rewind($fd); // Sets the pointer to the beginning of the file stream.

      $dspec = array(
        $fd,
        1 => array('pipe', 'w'), // stdout
        2 => array('pipe', 'w'), // stderr
      );

      if (!empty($language))
        $args = sprintf(" -f %s -l %s -O encoding=%s,style=%s,lineos=1,startinline=true", $formatter, $language, $encoding, $style);
      else
        $args = sprintf(" -f %s -g -O encoding=%s,style=%s,lineos=1", $formatter, $encoding, $style);

      $proc = proc_open(self::PIGMENTS_BINARY.$args, $dspec, $pipes);

      if (is_resource($proc)) {
        // Reads the stdout output.
        $output = "";
        while (!feof($pipes[1])) {
          $output .= fgets($pipes[1]);
        }

        // Reads the stderr output.
        $error = "";
        while (!feof($pipes[2])) {
          $error .= fgets($pipes[2]);
        }

        // Free all resources.
        fclose($fd);
        fclose($pipes[1]);
        fclose($pipes[2]);
        $exitCode = proc_close($proc);

        if ($exitCode != 0)
          throw new \RuntimeException($error);

        return $output;
      }
      else
        throw new \RuntimeException("Cannot execute the `pygmentize` command.");
    }
    else
      throw new \RuntimeException("Cannot create the temporary file with the source code.");

  }

}<commit_msg>fixed the namespace documentation style<commit_after><?php

/**
 * @file Pygmentize.php
 * @brief This file contains the Pygmentize class.
 * @details
 * @author <NAME>
 */



//! Global namespace for the Pygmentize class.
namespace Pygmentize;


/**
 * @brief Pygments is a wrapper to 'pygmentize', the command line interface provided by Pygments, a python syntax
 * highlighter.
 */
class Pygmentize {

  // Binary name.
  const PIGMENTS_BINARY = "pygmentize";


  /**
   * @brief Formats the provided source code using the specified formatter and style.
   * @param[in] string $source The source code.
   * @param[in] string $language The programming language name of the source code.
   * @param[in] string $encoding The file input and output encodings.
   * @param[in] string $formatter The output will be created using the provided formatter.
   * @param[in] string $style The style used by the formatter.
   * @return string The highlighted source code.
   */
  public static function highlight($source, $language, $encoding = "utf-8", $formatter = "html", $style = "borland") {

    // Try to create a temporary physical file. The function 'proc_open' doesn't allow to use a memory file.
    if ($fd = fopen("php://temp", "r+")) {
      fputs($fd, $source); // We don't need to flush because we call rewind.
      rewind($fd); // Sets the pointer to the beginning of the file stream.

      $dspec = array(
        $fd,
        1 => array('pipe', 'w'), // stdout
        2 => array('pipe', 'w'), // stderr
      );

      if (!empty($language))
        $args = sprintf(" -f %s -l %s -O encoding=%s,style=%s,lineos=1,startinline=true", $formatter, $language, $encoding, $style);
      else
        $args = sprintf(" -f %s -g -O encoding=%s,style=%s,lineos=1", $formatter, $encoding, $style);

      $proc = proc_open(self::PIGMENTS_BINARY.$args, $dspec, $pipes);

      if (is_resource($proc)) {
        // Reads the stdout output.
        $output = "";
        while (!feof($pipes[1])) {
          $output .= fgets($pipes[1]);
        }

        // Reads the stderr output.
        $error = "";
        while (!feof($pipes[2])) {
          $error .= fgets($pipes[2]);
        }

        // Free all resources.
        fclose($fd);
        fclose($pipes[1]);
        fclose($pipes[2]);
        $exitCode = proc_close($proc);

        if ($exitCode != 0)
          throw new \RuntimeException($error);

        return $output;
      }
      else
        throw new \RuntimeException("Cannot execute the `pygmentize` command.");
    }
    else
      throw new \RuntimeException("Cannot create the temporary file with the source code.");

  }

}
{'fraction_non_alphanumeric': 0.1410450586898902, 'fraction_numerical': 0.004543733434305188, 'mean_word_length': 2.620973269362577, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '640984', 'n_tokens_mistral': 1637, 'n_tokens_neox': 1569, 'n_words': 527}