<commit_before><?php namespace Gocompose\Foodbag\Models;

use Illuminate\Database\Eloquent\Model;

class Eat extends Model {

	public function food()
    {
        return $this->hasOne('Gocompose\Foodbag\Models\Food', 'id', 'food_id');
    }

    public function getUnit()
    {
        $unit = "";
        if($this["amount_type"] == "S") {
            $unit = "g";
        } else if($this["amount_type"] == "L") {
            $unit = "ml";
        }
        return $unit;
    }

    public function getCalories()
    {
        return $this->getScaledValue($this->food['calories']);
    }


    private function getScaledValue($value)
    {
        $out = null;
        if($this["amount_type"] == "S")
            $out = ( ($this["amount"]/$this->food["size"])*$value);
        else if($this["amount_type"] == "L")
            $out = ( ($this["amount"]/$this->food["size"])*$value);
        else
            $out = (($this["amount"]*$this->food["serving_size"])/$this->food["size"])*$value;

        return $out;
    }
}
<commit_msg>Fixed division by zero.<commit_after><?php namespace Gocompose\Foodbag\Models;

use Illuminate\Database\Eloquent\Model;

class Eat extends Model {

	public function food()
    {
        return $this->hasOne('Gocompose\Foodbag\Models\Food', 'id', 'food_id');
    }

    public function getUnit()
    {
        $unit = "";
        if($this["amount_type"] == "S") {
            $unit = "g";
        } else if($this["amount_type"] == "L") {
            $unit = "ml";
        }
        return $unit;
    }

    public function getCalories()
    {
        return $this->getScaledValue($this->food['calories']);
    }


    private function getScaledValue($value)
    {
        $out = null;

        $size = $this->food["size"];
        if($size <= 0) {
            return null;
        }
        
        if($this["amount_type"] == "S")
            $out = ( ($this["amount"]/$size)*$value);
        else if($this["amount_type"] == "L")
            $out = ( ($this["amount"]/$size)*$value);
        else
            $out = (($this["amount"]*$this->food["serving_size"])/$size)*$value;

        return $out;
    }
}

{'fraction_non_alphanumeric': 0.19196637085474078, 'fraction_numerical': 0.00046707146193367583, 'mean_word_length': 2.154639175257732, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 15, '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': '5478904', 'n_tokens_mistral': 704, 'n_tokens_neox': 685, 'n_words': 119}