AttachmentEvents::saved()   A
last analyzed

Complexity

Conditions 5
Paths 5

Size

Total Lines 30
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 18
c 0
b 0
f 0
nc 5
nop 1
dl 0
loc 30
rs 9.3554
1
<?php
2
3
namespace Mostafaznv\Larupload\Concerns\Storage\Attachment;
4
5
6
use Illuminate\Database\Eloquent\Model;
7
use Illuminate\Support\Facades\Storage;
8
use Mostafaznv\Larupload\Actions\GenerateFileIdAction;
9
10
trait AttachmentEvents
11
{
12
    public function saved(Model $model): Model
13
    {
14
        $this->id = GenerateFileIdAction::make($model, $this->secureIdsMethod, $this->mode, $this->name)->run();
0 ignored issues
show
Bug Best Practice introduced by
The property id does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
15
        $this->uploaded = true;
0 ignored issues
show
Bug Best Practice introduced by
The property uploaded does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
16
17
        if (isset($this->file)) {
18
            if ($this->file == LARUPLOAD_NULL) {
19
                $this->clean($this->id);
0 ignored issues
show
Bug introduced by
It seems like clean() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

19
                $this->/** @scrutinizer ignore-call */ 
20
                       clean($this->id);
Loading history...
20
            }
21
            else {
22
                if (!$this->keepOldFiles) {
23
                    $this->clean($this->id);
24
                }
25
26
                $this->setBasicDetails();
0 ignored issues
show
Bug introduced by
It seems like setBasicDetails() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

26
                $this->/** @scrutinizer ignore-call */ 
27
                       setBasicDetails();
Loading history...
27
                $this->setMediaDetails();
0 ignored issues
show
Bug introduced by
It seems like setMediaDetails() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

27
                $this->/** @scrutinizer ignore-call */ 
28
                       setMediaDetails();
Loading history...
28
                $this->uploadOriginalFile($this->id);
0 ignored issues
show
Bug introduced by
It seems like uploadOriginalFile() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

28
                $this->/** @scrutinizer ignore-call */ 
29
                       uploadOriginalFile($this->id);
Loading history...
29
                $this->setCover($this->id);
0 ignored issues
show
Bug introduced by
It seems like setCover() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

29
                $this->/** @scrutinizer ignore-call */ 
30
                       setCover($this->id);
Loading history...
30
                $this->handleStyles($this->id, $model);
0 ignored issues
show
Bug introduced by
It seems like handleStyles() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

30
                $this->/** @scrutinizer ignore-call */ 
31
                       handleStyles($this->id, $model);
Loading history...
31
            }
32
33
            $model = $this->setAttributes($model);
0 ignored issues
show
Bug introduced by
It seems like setAttributes() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

33
            /** @scrutinizer ignore-call */ 
34
            $model = $this->setAttributes($model);
Loading history...
34
        }
35
        else if (isset($this->cover)) {
36
            $this->setCover($this->id);
37
38
            $model = $this->setAttributes($model);
39
        }
40
41
        return $model;
42
    }
43
44
    public function deleted(): void
45
    {
46
        if (!$this->preserveFiles) {
47
            Storage::disk($this->disk)->deleteDirectory("$this->folder/$this->id");
48
        }
49
    }
50
}
51