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

ExportStoredFile   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
dl 0
loc 37
c 1
b 0
f 0
ccs 0
cts 13
cp 0
rs 10
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getTable() 0 3 1
A newFactory() 0 3 1
A downloadLink() 0 3 1
A boot() 0 8 2
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