StreamStyle   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 17
c 0
b 0
f 0
dl 0
loc 57
rs 10
wmc 9

5 Methods

Rating   Name   Duplication   Size   Complexity  
A make() 0 9 1
A validateName() 0 11 3
A __construct() 0 9 1
A validateDimension() 0 11 3
A validate() 0 4 1
1
<?php
2
3
namespace Mostafaznv\Larupload\DTOs\Style;
4
5
use Exception;
6
use FFMpeg\Format\Video\X264;
7
use Mostafaznv\Larupload\Enums\LaruploadMediaStyle;
8
9
class StreamStyle
10
{
11
    public function __construct(
12
        public readonly string              $name,
13
        public readonly int                 $width,
14
        public readonly int                 $height,
15
        public readonly X264                $format,
16
        public readonly LaruploadMediaStyle $mode = LaruploadMediaStyle::SCALE_HEIGHT,
17
        public readonly bool                $padding = false
18
    ) {
19
        $this->validate();
20
    }
21
22
    public static function make(
23
        string              $name,
24
        int                 $width,
25
        int                 $height,
26
        X264                $format,
27
        LaruploadMediaStyle $mode = LaruploadMediaStyle::SCALE_HEIGHT,
28
        bool                $padding = false
29
    ): self {
30
        return new self($name, $width, $height, $format, $mode, $padding);
31
    }
32
33
34
    private function validate(): void
35
    {
36
        $this->validateName();
37
        $this->validateDimension();
38
    }
39
40
    private function validateName(): void
41
    {
42
        if (is_numeric($this->name)) {
43
            throw new Exception(
44
                "Style name [$this->name] is numeric. please use string name for your style"
45
            );
46
        }
47
48
        if (ctype_alnum($this->name) === false) {
49
            throw new Exception(
50
                "stream name [$this->name] should be an alpha numeric string"
51
            );
52
        }
53
    }
54
55
    private function validateDimension(): void
56
    {
57
        if ($this->width <= 0) {
58
            throw new Exception(
59
                "width [$this->width] should be a positive number"
60
            );
61
        }
62
63
        if ($this->height <= 0) {
64
            throw new Exception(
65
                "height [$this->height] should be a positive number"
66
            );
67
        }
68
    }
69
}
70