Passed
Pull Request — 2.x (#586)
by Bekzat
05:24 queued 25s
created

File   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 34
ccs 0
cts 12
cp 0
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A canDeleteSafely() 0 3 1
A toCmsArray() 0 8 1
A getSizeAttribute() 0 3 1
A getTable() 0 3 1
1
<?php
2
3
namespace A17\Twill\Models;
4
5
use FileService;
0 ignored issues
show
Bug introduced by
The type FileService was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Illuminate\Support\Facades\DB;
7
8
class File extends Model
9
{
10
    public $timestamps = true;
11
12
    protected $fillable = [
13
        'uuid',
14
        'filename',
15
        'size',
16
    ];
17
18
    public function getSizeAttribute($value)
19
    {
20
        return bytesToHuman($value);
21
    }
22
23
    public function canDeleteSafely()
24
    {
25
        return DB::table(config('twill.fileables_table', 'twill_fileables'))->where('file_id', $this->id)->count() === 0;
26
    }
27
28
    public function toCmsArray()
29
    {
30
        return [
31
            'id' => $this->id,
32
            'name' => $this->filename,
0 ignored issues
show
Bug Best Practice introduced by
The property filename does not exist on A17\Twill\Models\File. Since you implemented __get, consider adding a @property annotation.
Loading history...
33
            'src' => FileService::getUrl($this->uuid),
0 ignored issues
show
Bug Best Practice introduced by
The property uuid does not exist on A17\Twill\Models\File. Since you implemented __get, consider adding a @property annotation.
Loading history...
34
            'original' => FileService::getUrl($this->uuid),
35
            'size' => $this->size,
0 ignored issues
show
Bug Best Practice introduced by
The property size does not exist on A17\Twill\Models\File. Since you implemented __get, consider adding a @property annotation.
Loading history...
36
        ];
37
    }
38
39
    public function getTable()
40
    {
41
        return config('twill.files_table', 'twill_files');
42
    }
43
}
44