<commit_before><?php

namespace App;

use App\User;
use Illuminate\Database\Eloquent\Model;

class Bug extends Model
{
    protected $fillable = [
        'name',
        'description',
        'url',
        'images',
        'project_id',
        'author',
        'email',
        'guest',
        'private',
        'state',
    ];
    /**
     * Automatic (un)serialization for bug's images
     */
    protected $casts = [
        'images' => 'array',
    ];

    protected $guestID;

    /**
     * A bug may own many reported comments
     */
    public function comments()
    {
        return $this->hasMany('App\BugComment');
    }

    /**
     * Checking if the provided URL has the http prefix
     */
    protected function getUrlAttribute($value)
    {
        if(strpos($value, 'http') === false || strpos($value, 'http') != 0)
            return 'http://'.$value;
    }

    /**
     * Replaces the author value by the user's name if it's not "guest" bug
     */
    protected function getAuthorAttribute($value)
    {
        if($this->guest == 0){
            if($user = User::find($value)){
                // We keep the original value if needed
                $this->guestID = $value;
                $value =  $user->first_name . ' ' . $user->name;
            }else{
                $value = trans('global.undefined_username');
            }
        }
        return $value;
    }

    /**
     * Replaces the email value by the user's mail if it's not a "guest" bug
     */
    protected function getEmailAttribute($value)
    {
        if($this->guest == 0){
            if($user = User::find($this->guestID)){
                $value =  $user->email;
            }else{
                $value = trans('global.undefined_mail');
            }
        }
        return $value;
    }
}
<commit_msg>Bug reporting - Handle comments deletion on bug deletion<commit_after><?php

namespace App;

use App\User;
use Illuminate\Database\Eloquent\Model;

class Bug extends Model
{
    protected $fillable = [
        'name',
        'description',
        'url',
        'images',
        'project_id',
        'author',
        'email',
        'guest',
        'private',
        'state',
    ];
    /**
     * Automatic (un)serialization for bug's images
     */
    protected $casts = [
        'images' => 'array',
    ];

    protected $guestID;

    /**
     * A bug may own many reported comments
     */
    public function comments()
    {
        return $this->hasMany('App\BugComment');
    }

    /**
     * Checking if the provided URL has the http prefix
     */
    protected function getUrlAttribute($value)
    {
        if(strpos($value, 'http') === false || strpos($value, 'http') != 0)
            return 'http://'.$value;
    }

    /**
     * Replaces the author value by the user's name if it's not "guest" bug
     */
    protected function getAuthorAttribute($value)
    {
        if($this->guest == 0){
            if($user = User::find($value)){
                // We keep the original value if needed
                $this->guestID = $value;
                $value =  $user->first_name . ' ' . $user->name;
            }else{
                $value = trans('global.undefined_username');
            }
        }
        return $value;
    }

    /**
     * Replaces the email value by the user's mail if it's not a "guest" bug
     */
    protected function getEmailAttribute($value)
    {
        if($this->guest == 0){
            if($user = User::find($this->guestID)){
                $value =  $user->email;
            }else{
                $value = trans('global.undefined_mail');
            }
        }
        return $value;
    }

    /**
     * Handle children deletion on project removal
     */
    public static function boot()
    {
        parent::boot();    
        static::deleted(function($bug)
        {
            $bug->comments()->delete();
        });
    }
}

{'fraction_non_alphanumeric': 0.13842239185750635, 'fraction_numerical': 0.0015267175572519084, 'mean_word_length': 1.6189207195203197, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 23, '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': '702926', 'n_tokens_mistral': 1162, 'n_tokens_neox': 1121, 'n_words': 282}