Passed
Push — master ( e27a9b...67f2c8 )
by Amin
01:53
created

round_to_even()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 1
nc 2
nop 1
dl 0
loc 3
rs 10
c 1
b 0
f 0
1
<?php
2
3
/**
4
 * Copyright 2019 Amin Yazdanpanah<http://www.aminyazdanpanah.com>.
5
 *
6
 * Licensed under the MIT License;
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 *      https://opensource.org/licenses/MIT
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
use AYazdanpanah\FFMpegStreaming\FFMpeg;
20
use FFMpeg\Exception\ExceptionInterface;
21
use AYazdanpanah\FFMpegStreaming\Format\HEVC;
22
use AYazdanpanah\FFMpegStreaming\Format\X264;
23
24
if (! function_exists('dash')) {
25
    /**
26
     * Auto generate dash MPD file
27
     *
28
     * @param string $input_path
29
     * @param callable $listener
30
     * @param string|null $save_path
31
     * @return string
32
     */
33
    function dash(string $input_path, string $save_path = null, callable $listener = null)
34
    {
35
        $format = new HEVC();
36
37
        if (is_callable($listener)) {
38
            $format->on('progress', $listener);
0 ignored issues
show
Bug introduced by
It seems like $listener can also be of type null; however, parameter $listener of Evenement\EventEmitter::on() does only seem to accept callable, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

38
            $format->on('progress', /** @scrutinizer ignore-type */ $listener);
Loading history...
39
        }
40
41
        try {
42
            return FFMpeg::create()
0 ignored issues
show
Bug Best Practice introduced by
The expression return AYazdanpanah\FFMp...s=a')->save($save_path) returns the type AYazdanpanah\FFMpegStreaming\DASH which is incompatible with the documented return type string.
Loading history...
43
                ->open($input_path)
44
                ->DASH()
45
                ->setFormat($format)
46
                ->autoGenerateRepresentations()
47
                ->setAdaption('id=0,streams=v id=1,streams=a')
48
                ->save($save_path);
49
        } catch (ExceptionInterface $e) {
50
            return "Failed: error: " . $e->getMessage();
0 ignored issues
show
Bug introduced by
The method getMessage() does not exist on FFMpeg\Exception\ExceptionInterface. It seems like you code against a sub-type of said class. However, the method does not exist in AYazdanpanah\FFMpegStrea...FMpegExceptionInterface. Are you sure you never get one of those? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

50
            return "Failed: error: " . $e->/** @scrutinizer ignore-call */ getMessage();
Loading history...
51
        }
52
    }
53
}
54
55
if (! function_exists('hls')) {
56
    /**
57
     * Auto generate HLS M3U8 file
58
     *
59
     * @param string $input_path
60
     * @param callable|null $listener
61
     * @param string|null $save_path
62
     * @return string
63
     */
64
    function hls(string $input_path,  string $save_path = null, callable $listener = null)
65
    {
66
        $format = new X264();
67
68
        if (is_callable($listener)) {
69
            $format->on('progress', $listener);
0 ignored issues
show
Bug introduced by
It seems like $listener can also be of type null; however, parameter $listener of Evenement\EventEmitter::on() does only seem to accept callable, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

69
            $format->on('progress', /** @scrutinizer ignore-type */ $listener);
Loading history...
70
        }
71
72
        try {
73
            return FFMpeg::create()
0 ignored issues
show
Bug Best Practice introduced by
The expression return AYazdanpanah\FFMp...ons()->save($save_path) returns the type AYazdanpanah\FFMpegStreaming\HLS which is incompatible with the documented return type string.
Loading history...
74
                ->open($input_path)
75
                ->HLS()
76
                ->setFormat($format)
77
                ->autoGenerateRepresentations()
78
                ->save($save_path);
79
        } catch (ExceptionInterface $e) {
80
            return "Failed: error: " . $e->getMessage();
81
        }
82
    }
83
}