<commit_before><?php
namespace Repositories;

class LocalReader implements RepositoryReaderInterface
{
  private $id;
  private $database;
  private $index;
  private $version;

  private function newObject($object)
  {
    $object->repo_id = $this->id++;

    \Event::fire("cataclysm.newObject", array($this, $object));

    $this->database[$object->repo_id] = $object;
  }

  private function modDirectory($path, $id)
  {
    $mods = array_filter(glob("$path/data/mods/*"), "is_dir");
    foreach ($mods as $mod) {
      $modinfo = json_decode(file_get_contents("$mod/modinfo.json"));
      if ($modinfo->ident == $id)
        return $mod;
    }
  }

  private function dataPaths($path)
  {
    $default_mods_data = json_decode(file_get_contents("$path/data/mods/dev-default-mods.json"));
    $paths = array("$path/data/json");

    foreach ($default_mods_data->dependencies as $mod) {
      $paths[] = $this->modDirectory($path, $mod);
    }
    return $paths;
  }

  public function read($path=null)
  {
    \Log::info("Reading data files...");
    if(!$path)
      $path = \Config::get('cataclysm.dataPath');

    $this->database = array();
    $this->id = 0;
    $this->index = array();

    $paths = $this->dataPaths($path);

    foreach ($paths as $path) {
      $it = new \RecursiveDirectoryIterator($path);
      foreach(new \RecursiveIteratorIterator($it) as $file) {
        $data = (array) json_decode(file_get_contents($file));

        if(substr($file, -12)!="modinfo.json") {        
          array_walk($data, array($this, 'newObject'));
        }
      }
    }

    if (!$this->get("item", "toolset")) {
      $this->newObject(json_decode('{
        "id":"toolset",
        "name":"integrated toolset",
        "type":"_SPECIAL",
        "description":"A fake item. If you are reading this it\'s a bug!"
      }'));
    }
    $this->newObject(json_decode('{
      "id":"fire",
      "name":"nearby fire",<commit_msg>The new path array was clobbering the $path variable which was used to get the version.<commit_after><?php
namespace Repositories;

class LocalReader implements RepositoryReaderInterface
{
  private $id;
  private $database;
  private $index;
  private $version;

  private function newObject($object)
  {
    $object->repo_id = $this->id++;

    \Event::fire("cataclysm.newObject", array($this, $object));

    $this->database[$object->repo_id] = $object;
  }

  private function modDirectory($path, $id)
  {
    $mods = array_filter(glob("$path/data/mods/*"), "is_dir");
    foreach ($mods as $mod) {
      $modinfo = json_decode(file_get_contents("$mod/modinfo.json"));
      if ($modinfo->ident == $id)
        return $mod;
    }
  }

  private function dataPaths($path)
  {
    $default_mods_data = json_decode(file_get_contents("$path/data/mods/dev-default-mods.json"));
    $paths = array("$path/data/json");

    foreach ($default_mods_data->dependencies as $mod) {
      $paths[] = $this->modDirectory($path, $mod);
    }
    return $paths;
  }

  public function read($path=null)
  {
    \Log::info("Reading data files...");
    if(!$path)
      $path = \Config::get('cataclysm.dataPath');

    $this->database = array();
    $this->id = 0;
    $this->index = array();

    $paths = $this->dataPaths($path);

    foreach ($paths as $currPath) {
      $it = new \RecursiveDirectoryIterator($currPath);
      foreach(new \RecursiveIteratorIterator($it) as $file) {
        $data = (array) json_decode(file_get_contents($file));

        if(substr($file, -12)!="modinfo.json") {        
          array_walk($data, array($this, 'newObject'));
        }
      }
    }

    if (!$this->get("item", "toolset")) {
      $this->newObject(json_decode('{
        "id":"toolset",
        "name":"integrated toolset",
        "type":"_SPECIAL",
        "description":"A fake item. If you are reading this it\'s a bug!"
      }'));
    }
    $this->newObject(json_decode('{
      "id":"fire",
      "name":"nearby fire",
{'fraction_non_alphanumeric': 0.17813765182186234, 'fraction_numerical': 0.0015182186234817814, 'mean_word_length': 3.1048805815160954, 'pattern_counts': {'":': 12, '<': 5, '<?xml version=': 0, '>': 31, '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': '517536', 'n_tokens_mistral': 1332, 'n_tokens_neox': 1297, 'n_words': 250}