Test Failed
Branch master (df1c42)
by Mostafa
15:23
created

UploadEntityStyle::video()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 6
dl 0
loc 5
rs 10
1
<?php
2
3
namespace Mostafaznv\Larupload\Concerns\Storage\UploadEntity;
4
5
6
use FFMpeg\Format\Video\X264;
7
use Mostafaznv\Larupload\DTOs\Style\StreamStyle;
8
use Mostafaznv\Larupload\DTOs\Style\ImageStyle;
9
use Mostafaznv\Larupload\DTOs\Style\VideoStyle;
10
use Mostafaznv\Larupload\Enums\LaruploadFileType;
11
use Mostafaznv\Larupload\Enums\LaruploadMediaStyle;
12
use Mostafaznv\Larupload\Larupload;
13
use Mostafaznv\Larupload\UploadEntities;
14
15
trait UploadEntityStyle
16
{
17
    /**
18
     * Styles for image files
19
     *
20
     * @var ImageStyle[]
21
     */
22
    protected array $imageStyles = [];
23
24
    /**
25
     * Styles for video files
26
     *
27
     * @var VideoStyle[]
28
     */
29
    protected array $videoStyles = [];
30
31
    /**
32
     * Stream styles
33
     *
34
     * @var StreamStyle[]
35
     */
36
    protected array $streams = [];
37
38
    /**
39
     * Cover style
40
     *
41
     * @var ImageStyle
42
     */
43
    protected ImageStyle $coverStyle;
44
45
46
    public function image(string $name, ?int $width = null, ?int $height = null, LaruploadMediaStyle $mode = LaruploadMediaStyle::AUTO): UploadEntities
47
    {
48
        $this->imageStyles[$name] = ImageStyle::make($name, $width, $height, $mode);
49
50
        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...
51
    }
52
53
    public function video(string $name, ?int $width = null, ?int $height = null, LaruploadMediaStyle $mode = LaruploadMediaStyle::SCALE_HEIGHT, X264 $format = new X264, bool $padding = false): UploadEntities
54
    {
55
        $this->videoStyles[$name] = VideoStyle::make($name, $width, $height, $mode, $format, $padding);
56
57
        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...
58
    }
59
60
    public function stream(string $name, int $width, int $height, X264 $format, LaruploadMediaStyle $mode = LaruploadMediaStyle::SCALE_HEIGHT, bool $padding = false): UploadEntities
61
    {
62
        $this->streams[$name] = StreamStyle::make($name, $width, $height, $format, $mode, $padding);
63
64
        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...
65
    }
66
67
    public function coverStyle(string $name, ?int $width = null, ?int $height = null, LaruploadMediaStyle $mode = LaruploadMediaStyle::AUTO): UploadEntities
68
    {
69
        $this->coverStyle = ImageStyle::make($name, $width, $height, $mode);
70
71
        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...
72
    }
73
74
    protected function styleHasFile(string $style): bool
75
    {
76
        if (in_array($style, [Larupload::ORIGINAL_FOLDER, Larupload::COVER_FOLDER])) {
77
            return true;
78
        }
79
80
        $type = $this->output['type'];
81
        $types = [
82
            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...
83
            LaruploadFileType::IMAGE->name
84
        ];
85
86
        if (in_array($type, $types)) {
87
            $styles = $type === LaruploadFileType::IMAGE->name
88
                ? $this->imageStyles
89
                : $this->videoStyles;
90
91
            return array_key_exists($style, $styles);
92
        }
93
94
        return false;
95
    }
96
}
97