Test Failed
Push — master ( ba03f2...dee2b3 )
by Mostafa
58s queued 15s
created

UploadEntityStyle::getAudioStyles()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Mostafaznv\Larupload\Concerns\Storage\UploadEntity;
4
5
6
use FFMpeg\Format\Audio\Aac;
7
use FFMpeg\Format\Audio\Flac;
8
use FFMpeg\Format\Audio\Mp3;
9
use FFMpeg\Format\Audio\Wav;
10
use FFMpeg\Format\Video\X264;
11
use Mostafaznv\Larupload\DTOs\Style\AudioStyle;
12
use Mostafaznv\Larupload\DTOs\Style\StreamStyle;
13
use Mostafaznv\Larupload\DTOs\Style\ImageStyle;
14
use Mostafaznv\Larupload\DTOs\Style\Style;
15
use Mostafaznv\Larupload\DTOs\Style\VideoStyle;
16
use Mostafaznv\Larupload\Enums\LaruploadFileType;
17
use Mostafaznv\Larupload\Enums\LaruploadMediaStyle;
18
use Mostafaznv\Larupload\Larupload;
19
use Mostafaznv\Larupload\UploadEntities;
20
21
trait UploadEntityStyle
22
{
23
    /**
24
     * Styles for image files
25
     *
26
     * @var ImageStyle[]
27
     */
28
    protected array $imageStyles = [];
29
30
    /**
31
     * Styles for video files
32
     *
33
     * @var VideoStyle[]
34
     */
35
    protected array $videoStyles = [];
36
37
    /**
38
     * Styles for audio files
39
     *
40
     * @var AudioStyle[]
41
     */
42
    protected array $audioStyles = [];
43
44
    /**
45
     * Stream styles
46
     *
47
     * @var StreamStyle[]
48
     */
49
    protected array $streams = [];
50
51
    /**
52
     * Cover style
53
     *
54
     * @var ImageStyle
55
     */
56
    protected ImageStyle $coverStyle;
57
58
59
    public function getImageStyles(): array
60
    {
61
        return $this->imageStyles;
62
    }
63
64
    public function getVideoStyles(): array
65
    {
66
        return $this->videoStyles;
67
    }
68
69
    public function getAudioStyles(): array
70
    {
71
        return $this->audioStyles;
72
    }
73
74
    public function image(string $name, ?int $width = null, ?int $height = null, LaruploadMediaStyle $mode = LaruploadMediaStyle::AUTO): UploadEntities
75
    {
76
        $this->imageStyles[$name] = ImageStyle::make($name, $width, $height, $mode);
77
78
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type Mostafaznv\Larupload\Con...ntity\UploadEntityStyle which includes types incompatible with the type-hinted return Mostafaznv\Larupload\UploadEntities.
Loading history...
79
    }
80
81
    public function video(string $name, ?int $width = null, ?int $height = null, LaruploadMediaStyle $mode = LaruploadMediaStyle::SCALE_HEIGHT, X264 $format = new X264, bool $padding = false): UploadEntities
82
    {
83
        $this->videoStyles[$name] = VideoStyle::make($name, $width, $height, $mode, $format, $padding);
84
85
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type Mostafaznv\Larupload\Con...ntity\UploadEntityStyle which includes types incompatible with the type-hinted return Mostafaznv\Larupload\UploadEntities.
Loading history...
86
    }
87
88
    public function audio(string $name, Mp3|Aac|Wav|Flac $format = new Mp3): UploadEntities
89
    {
90
        $this->audioStyles[$name] = AudioStyle::make($name, $format);
91
92
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type Mostafaznv\Larupload\Con...ntity\UploadEntityStyle which includes types incompatible with the type-hinted return Mostafaznv\Larupload\UploadEntities.
Loading history...
93
    }
94
95
    public function stream(string $name, int $width, int $height, X264 $format, LaruploadMediaStyle $mode = LaruploadMediaStyle::SCALE_HEIGHT, bool $padding = false): UploadEntities
96
    {
97
        $this->streams[$name] = StreamStyle::make($name, $width, $height, $format, $mode, $padding);
98
99
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type Mostafaznv\Larupload\Con...ntity\UploadEntityStyle which includes types incompatible with the type-hinted return Mostafaznv\Larupload\UploadEntities.
Loading history...
100
    }
101
102
    public function coverStyle(string $name, ?int $width = null, ?int $height = null, LaruploadMediaStyle $mode = LaruploadMediaStyle::AUTO): UploadEntities
103
    {
104
        $this->coverStyle = ImageStyle::make($name, $width, $height, $mode);
105
106
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type Mostafaznv\Larupload\Con...ntity\UploadEntityStyle which includes types incompatible with the type-hinted return Mostafaznv\Larupload\UploadEntities.
Loading history...
107
    }
108
109
    protected function getStyle(string $style): ?Style
110
    {
111
        $type = $this->output['type'];
112
        $types = [
113
            LaruploadFileType::VIDEO->name,
0 ignored issues
show
Bug introduced by
The property name does not seem to exist on Mostafaznv\Larupload\Enums\LaruploadFileType.
Loading history...
114
            LaruploadFileType::AUDIO->name,
115
            LaruploadFileType::IMAGE->name
116
        ];
117
118
        if (in_array($type, $types)) {
119
            $styles = match ($type) {
120
                LaruploadFileType::VIDEO->name => $this->videoStyles,
121
                LaruploadFileType::AUDIO->name => $this->audioStyles,
122
                LaruploadFileType::IMAGE->name => $this->imageStyles,
123
            };
124
125
            if (isset($styles[$style])) {
126
                return $styles[$style];
127
            }
128
        }
129
130
        return null;
131
    }
132
133
    protected function styleHasFile(string $style): bool
134
    {
135
        if (in_array($style, [Larupload::ORIGINAL_FOLDER, Larupload::COVER_FOLDER])) {
136
            return true;
137
        }
138
139
        return $this->getStyle($style) !== null;
140
    }
141
}
142