<commit_before><?php

namespace Sprocketeer;

use Exception;

class Parser
{
    protected $paths;
    protected $debug = true;

    public function __construct($paths)
    {
        $this->paths = $paths;
    }

    public function getPathInfoFromManifest($manifest)
    {
        list($search_path_name, $filename) = explode('/', $manifest, 2);
        $path_info = $this->getPathInfo($search_path_name, $filename);
        $absolute_path = $path_info['absolute_path'];
        // Get only the header, we don't want any requires after that
        preg_match(
            "/^(
                (\s*) (
                    \* .* |
                    \/\/ .* |
                    \# .*
                )
            )+/mx",
            file_get_contents($absolute_path),
            $header
        );

        if (!$header) {
            return array($path_info);
        }

        $lines = explode("\n", $header[0]);

        $files = array();
        $self_required = false;
        foreach ($lines as $line) {
            if (!preg_match("/^\W*=\s*(\w+)\s*(.*)$/", $line, $line_matches)) {
                continue;
            }
            $directive = $line_matches[1];
            $require_manifest = $line_matches[2];
            switch ($directive) {
                case 'require':
                    $sub_manifest = null;
                    if ('/' === substr($require_manifest, 0, 1)) {
                        $sub_manifest = substr($require_manifest, 1);
                    } else {
                        $sub_manifest = dirname($manifest) . '/' . $require_manifest;
                    }
                    $sub_files = $this->getPathInfoFromManifest($sub_manifest);
                    $files = array_merge($files, $sub_files);
                    break;
                case 'require_self':
                    $files[] = $path_info;
                    $self_required = true;
                    break;
            }
        }

        if (!$self_required) {
            $files[] = $path_info;
        }

        return $files;
    }

    public function getPathInfo($search_path_name, $filename)
    {
        if (!isset($this->paths[$search_path_name])) {
            throw new Exception("Unknown search path name: '{$search_path_name}'.");
        }

        $search_path = $this->paths[$search_path_name];
        $full_path   = "{$search_path}/{$filename}";
        if (!file_exists($full_path)) {
            throw new Exception("File could not be found: {$full_path}");
        }

        $real_absolute_path  = realpath($full_path);
        $real_search_path    = realpath($search_path);<commit_msg>Combine getPathInfo()'s params params into one param<commit_after><?php

namespace Sprocketeer;

use Exception;

class Parser
{
    protected $paths;
    protected $debug = true;

    public function __construct($paths)
    {
        $this->paths = $paths;
    }

    public function getPathInfoFromManifest($manifest)
    {
        $path_info     = $this->getPathInfo($manifest);
        $absolute_path = $path_info['absolute_path'];

        // Get only the header, we don't want any requires after that
        preg_match(
            "/^(
                (\s*) (
                    \* .* |
                    \/\/ .* |
                    \# .*
                )
            )+/mx",
            file_get_contents($absolute_path),
            $header
        );

        if (!$header) {
            return array($path_info);
        }

        $lines = explode("\n", $header[0]);

        $files = array();
        $self_required = false;
        foreach ($lines as $line) {
            if (!preg_match("/^\W*=\s*(\w+)\s*(.*)$/", $line, $line_matches)) {
                continue;
            }
            $directive = $line_matches[1];
            $require_manifest = $line_matches[2];
            switch ($directive) {
                case 'require':
                    $sub_manifest = null;
                    if ('/' === substr($require_manifest, 0, 1)) {
                        $sub_manifest = substr($require_manifest, 1);
                    } else {
                        $sub_manifest = dirname($manifest) . '/' . $require_manifest;
                    }
                    $sub_files = $this->getPathInfoFromManifest($sub_manifest);
                    $files = array_merge($files, $sub_files);
                    break;
                case 'require_self':
                    $files[] = $path_info;
                    $self_required = true;
                    break;
            }
        }

        if (!$self_required) {
            $files[] = $path_info;
        }

        return $files;
    }

    public function getPathInfo($manifest)
    {
        list($search_path_name, $filename) = explode('/', $manifest, 2);
        if (!isset($this->paths[$search_path_name])) {
            throw new Exception("Unknown search path name: '{$search_path_name}'.");
        }

        $search_path = $this->paths[$search_path_name];
        $full_path   = "{$search_path}/{$filename}";
        if (!file_exists($full_path)) {
            throw new Exception("File could not be found: {$full_path}");
        }

        $real_absolute_path  = realpath($full_path);
        $real_search_path    = realpath($search_path);
{'fraction_non_alphanumeric': 0.13632916192643155, 'fraction_numerical': 0.0026545316647705727, 'mean_word_length': 1.502371916508539, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, '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': '1652795', 'n_tokens_mistral': 1521, 'n_tokens_neox': 1429, 'n_words': 277}