Test Failed
Push — master ( dee2b3...df9921 )
by Mostafa
01:00 queued 15s
created

FFMpegUploadEntity::ffmpeg()   B

Complexity

Conditions 10
Paths 10

Size

Total Lines 25
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 10
eloc 10
nc 10
nop 2
dl 0
loc 25
rs 7.6666
c 1
b 0
f 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Mostafaznv\Larupload\Concerns\Storage\UploadEntity;
4
5
6
use FFMpeg\Media\Audio;
7
use FFMpeg\Media\Video;
8
use Illuminate\Http\UploadedFile;
9
use Mostafaznv\Larupload\DTOs\Style\AudioStyle;
10
use Mostafaznv\Larupload\DTOs\Style\Style;
11
use Mostafaznv\Larupload\DTOs\Style\VideoStyle;
12
use Mostafaznv\Larupload\Storage\FFMpeg\FFMpeg;
13
14
trait FFMpegUploadEntity
15
{
16
    /**
17
     * FFMpeg instance
18
     */
19
    protected FFMpeg $ffmpeg;
20
21
    /**
22
     * Specify whether the FFMPEG process should run through the queue or not.
23
     */
24
    protected bool $ffmpegQueue;
25
26
    /**
27
     * Specify max FFMPEG processes should run at the same time.
28
     */
29
    protected int $ffmpegMaxQueueNum;
30
31
32
    protected function ffmpeg(UploadedFile $file = null, AudioStyle|VideoStyle|null $style = null): FFMpeg
33
    {
34
        $force = false;
35
36
        if ($style and isset($this->ffmpeg)) {
37
            $media = $this->ffmpeg->getMedia();
38
39
            // @codeCoverageIgnoreStart
40
            // it's an unlikely scenario, however, we must consider it
41
            if ($style instanceof AudioStyle and $media instanceof Video) {
42
                $force = true;
43
            }
44
            // @codeCoverageIgnoreEnd
45
46
            if ($style instanceof VideoStyle and $media instanceof Audio) {
47
                $force = true;
48
            }
49
        }
50
51
52
        if (!isset($this->ffmpeg) or $file or $force) {
53
            $this->ffmpeg = new FFMpeg($this->file, $this->disk, $this->dominantColorQuality);
54
        }
55
56
        return $this->ffmpeg;
57
    }
58
}
59