<commit_before><?php

class Recipes
{
  private static $database;

  public static function get($id)
  {
    if(isset(static::$database[$id])) 
      return new Recipe(static::$database[$id]);
  }

  public static function setup()
  {
    static::$database = static::getRecipes();
    static::linkItems();
  }

  private static function getRecipes()
  {
    if(Cache::has('recipes'))
      return Cache::get('recipes');
    error_log("Building recipes database...");

    $recipes = [];

    $path = Config::get("cataclysm.dataPath")."/recipes";
    foreach(scandir($path) as $file)
    {
      if($file[0]==".") continue;
      $json = (array) json_decode(file_get_contents("$path/$file"));
      foreach($json as $recipe)
      {
        $recipe->id = $id++;
        $recipes[] = $recipe;
      }
    }
    Cache::add('recipes', $recipes, 60);
    return $recipes;
  }

  private static function linkItems()
  {
    foreach(static::$database as $recipe_id=>$recipe)
    {
      if(isset($recipe->result))
      {
        Items::link("result", $recipe->result, $recipe_id);
      }
      if(isset($recipe->tools))
      {
        foreach($recipe->tools as $group)
        {
          foreach($group as $tool)
          {
            list($id, $amount) = $tool;
            Items::link("tool", $id, $recipe_id);
          }
        }
      }
      if(isset($recipe->components)) 
      {
        foreach($recipe->components as $group)
        {
          foreach($group as $component)
          {
            list($id, $amount) = $component;
            Items::link("component", $id, $recipe_id);
          }
        }
      }
    }
  }
}
<commit_msg>Dangling variable.<commit_after><?php

class Recipes
{
  private static $database;

  public static function get($id)
  {
    if(isset(static::$database[$id])) 
      return new Recipe(static::$database[$id]);
  }

  public static function setup()
  {
    static::$database = static::getRecipes();
    static::linkItems();
  }

  private static function getRecipes()
  {
    if(Cache::has('recipes'))
      return Cache::get('recipes');
    error_log("Building recipes database...");

    $recipes = [];

    $path = Config::get("cataclysm.dataPath")."/recipes";
    foreach(scandir($path) as $file)
    {
      if($file[0]==".") continue;
      $json = (array) json_decode(file_get_contents("$path/$file"));
      foreach($json as $recipe)
      {
        $recipes[] = $recipe;
      }
    }
    Cache::add('recipes', $recipes, 60);
    return $recipes;
  }

  private static function linkItems()
  {
    foreach(static::$database as $recipe_id=>$recipe)
    {
      if(isset($recipe->result))
      {
        Items::link("result", $recipe->result, $recipe_id);
      }
      if(isset($recipe->tools))
      {
        foreach($recipe->tools as $group)
        {
          foreach($group as $tool)
          {
            list($id, $amount) = $tool;
            Items::link("tool", $id, $recipe_id);
          }
        }
      }
      if(isset($recipe->components)) 
      {
        foreach($recipe->components as $group)
        {
          foreach($group as $component)
          {
            list($id, $amount) = $component;
            Items::link("component", $id, $recipe_id);
          }
        }
      }
    }
  }
}

{'fraction_non_alphanumeric': 0.1705308114704088, 'fraction_numerical': 0.0018303843807199512, 'mean_word_length': 2.2052785923753664, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 18, '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': '3476513', 'n_tokens_mistral': 1071, 'n_tokens_neox': 1051, 'n_words': 181}