File   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 0
cbo 3
dl 0
loc 36
ccs 0
cts 6
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A scopeOfType() 0 8 2
A uploaders() 0 4 1
1
<?php namespace App\Models;
2
3
use Illuminate\Database\Eloquent\Model;
4
5
/**
6
 * \App\Models\File
7
 *
8
 * @mixin \Eloquent
9
 * @property string $hash
10
 * @property string $disk
11
 * @property string $path
12
 * @property string $mime
13
 * @property integer $size
14
 * @property string $metadata
15
 * @property \Carbon\Carbon $created_at
16
 * @property \Carbon\Carbon $updated_at
17
 * @property-read \Illuminate\Database\Eloquent\Collection|User[] $uploaders
18
 * @method static \Illuminate\Database\Query\Builder|\App\Models\File whereHash($value)
19
 * @method static \Illuminate\Database\Query\Builder|\App\Models\File whereDisk($value)
20
 * @method static \Illuminate\Database\Query\Builder|\App\Models\File wherePath($value)
21
 * @method static \Illuminate\Database\Query\Builder|\App\Models\File whereMime($value)
22
 * @method static \Illuminate\Database\Query\Builder|\App\Models\File whereSize($value)
23
 * @method static \Illuminate\Database\Query\Builder|\App\Models\File whereMetadata($value)
24
 * @method static \Illuminate\Database\Query\Builder|\App\Models\File whereCreatedAt($value)
25
 * @method static \Illuminate\Database\Query\Builder|\App\Models\File whereUpdatedAt($value)
26
 * @method static \Illuminate\Database\Query\Builder|\App\Models\File ofType($type = 'image')
27
 */
28
class File extends Model
29
{
30
    protected $table = 'files';
31
32
    protected $primaryKey = 'hash';
33
34
    public $incrementing = false;
35
36
    protected $guarded = ['*'];
37
38
    protected $dates = ['deleted_at'];
39
40
    /**
41
     * @param \Illuminate\Database\Query\Builder $query
42
     * @param string                             $type
43
     *
44
     * @return \Illuminate\Database\Query\Builder
45
     * @throws \Exception
46
     */
47
    public function scopeOfType($query, $type = 'image')
48
    {
49
        if (!in_array($type, ['plain', 'image', 'audio', 'video', 'application'])) {
50
            throw new \Exception();
51
        }
52
53
        return $query->where('mime', 'like', $type . '/%');
54
    }
55
56
    /**
57
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
58
     */
59
    public function uploaders()
60
    {
61
        return $this->belongsToMany(User::class, 'files_users', 'file_hash', 'user_id')->withTimestamps()->withPivot(['uuid', 'original_client_name']);
62
    }
63
}
64