Passed
Push — main ( 302427...b5b644 )
by Yaroslav
14:44
created

ExportStoredFile::downloadLink()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
nc 1
nop 0
dl 0
loc 3
c 0
b 0
f 0
cc 1
ccs 0
cts 2
cp 0
crap 2
rs 10
1
<?php
2
3
namespace NovaExportConfiguration\Models;
4
5
use Illuminate\Database\Eloquent\Casts\Attribute;
6
use Illuminate\Database\Eloquent\Factories\HasFactory;
7
use Illuminate\Database\Eloquent\Model;
8
use Illuminate\Support\Facades\Storage;
9
use JsonFieldCast\Casts\SimpleJsonField;
10
11
/**
12
 * @property $meta \JsonFieldCast\Json\SimpleJsonField
13
 */
0 ignored issues
show
Documentation Bug introduced by
The doc comment $meta at position 0 could not be parsed: Unknown type name '$meta' at position 0 in $meta.
Loading history...
14
class ExportStoredFile extends Model
15
{
16
    use HasFactory;
17
18
    protected $guarded = [];
19
20
    public $withoutActionEvents = true;
21
22
    protected $casts = [
23
        'meta' => SimpleJsonField::class,
24
    ];
25
26
    public function getTable(): string
27
    {
28
        return config('nova-export-configuration.tables.export_config_stored_files');
29
    }
30
31
    protected static function newFactory()
32
    {
33
        return \NovaExportConfiguration\Database\Factories\ExportStoredFileFactory::new();
34
    }
35
36
    protected static function boot()
37
    {
38
        parent::boot();
39
40
        self::deleting(function (self $model) {
41
            $storage = Storage::disk($model->disk);
0 ignored issues
show
Bug introduced by
The property disk does not seem to exist on NovaExportConfiguration\Models\ExportStoredFile. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
42
            if ($storage->exists($model->path)) {
0 ignored issues
show
Bug introduced by
The property path does not seem to exist on NovaExportConfiguration\Models\ExportStoredFile. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
43
                $storage->delete($model->path);
44
            }
45
        });
46
    }
47
48
    public function downloadLink(): Attribute
49
    {
50
        return Attribute::get(fn () => route(config('nova-export-configuration.defaults.download_route'), $this->path));
0 ignored issues
show
Bug introduced by
The property path does not seem to exist on NovaExportConfiguration\Models\ExportStoredFile. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
51
    }
52
}
53