CoverAttachment::detachCover()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
c 0
b 0
f 0
nc 2
nop 0
dl 0
loc 11
rs 10
1
<?php
2
3
namespace Mostafaznv\Larupload\Concerns\Storage\Attachment;
4
5
6
use Illuminate\Http\UploadedFile;
7
use Mostafaznv\Larupload\Actions\Cover\SetCoverAction;
8
use Mostafaznv\Larupload\DTOs\CoverActionData;
9
use Mostafaznv\Larupload\Enums\LaruploadFileType;
10
use Mostafaznv\Larupload\Larupload;
11
12
trait CoverAttachment
13
{
14
    public function updateCover(UploadedFile $file): bool
15
    {
16
        file_is_valid($file, $this->name, 'cover');
17
18
        if ($this->output['type']) {
19
            $this->uploaded = false;
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...
20
            $this->cover = $file;
0 ignored issues
show
Bug Best Practice introduced by
The property cover does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
21
            $this->type = LaruploadFileType::from($this->output['type']);
0 ignored issues
show
Bug Best Practice introduced by
The property type does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
22
23
            return true;
24
        }
25
26
        return false;
27
    }
28
29
    public function detachCover(): bool
30
    {
31
        if ($this->output['type']) {
32
            $this->uploaded = false;
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...
33
            $this->cover = LARUPLOAD_NULL;
0 ignored issues
show
Bug Best Practice introduced by
The property cover does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
34
            $this->type = LaruploadFileType::from($this->output['type']);
0 ignored issues
show
Bug Best Practice introduced by
The property type does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
35
36
            return true;
37
        }
38
39
        return false;
40
    }
41
42
43
    /**
44
     * Set cover photo
45
     * Generate cover photo automatically from photos and videos, if cover file was null
46
     *
47
     * @param $id
48
     */
49
    protected function setCover($id): void
50
    {
51
        $path = $this->getBasePath($id, Larupload::COVER_FOLDER);
0 ignored issues
show
Bug introduced by
It seems like getBasePath() 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

51
        /** @scrutinizer ignore-call */ 
52
        $path = $this->getBasePath($id, Larupload::COVER_FOLDER);
Loading history...
52
        $data = CoverActionData::make(
53
            disk: $this->disk,
54
            namingMethod: $this->namingMethod,
55
            lang: $this->lang,
56
            style: $this->coverStyle,
0 ignored issues
show
Bug introduced by
The property coverStyle does not exist on Mostafaznv\Larupload\Con...achment\CoverAttachment. Did you mean cover?
Loading history...
57
            type: $this->type,
58
            generateCover: $this->generateCover,
59
            withDominantColor: $this->dominantColor,
60
            dominantColorQuality: $this->dominantColorQuality,
61
            imageProcessingLibrary: $this->imageProcessingLibrary,
62
            output: $this->output
63
        );
64
65
        $this->output = SetCoverAction::make($this->file ?? null, $this->cover, $data)->run($path);
0 ignored issues
show
Bug Best Practice introduced by
The property output does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
66
    }
67
}
68