Passed
Push — master ( 3ee3fe...b14545 )
by Amin
04:48
created

ExportHLSPlaylist   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 1
Bugs 1 Features 1
Metric Value
eloc 9
c 1
b 1
f 1
dl 0
loc 30
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A generateContents() 0 13 3
1
<?php
2
3
/**
4
 * This file is part of the PHP-FFmpeg-video-streaming package.
5
 *
6
 * (c) Amin Yazdanpanah <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Streaming;
13
14
15
class ExportHLSPlaylist
16
{
17
    /**
18
     * @param $filename
19
     * @param $representations
20
     * @param $basename
21
     */
22
    public static function savePlayList($filename, $representations, $basename)
23
    {
24
        file_put_contents($filename, static::generateContents($representations, $basename));
25
    }
26
27
    /**
28
     * @param $representations
29
     * @param $basename
30
     * @return string
31
     */
32
    private static function generateContents($representations, $basename)
33
    {
34
        $content[] = "#EXTM3U";
0 ignored issues
show
Comprehensibility Best Practice introduced by
$content was never initialized. Although not strictly required by PHP, it is generally a good practice to add $content = array(); before regardless.
Loading history...
35
        $content[] = "#EXT-X-VERSION:3";
36
37
        foreach ($representations as $representation) {
38
            if ($representation instanceof Representation) {
39
                $content[] = "#EXT-X-STREAM-INF:BANDWIDTH=" . $representation->getKiloBitrate() * 1024 . ",RESOLUTION=" . $representation->getResize();
40
                $content[] = $basename . "_" . $representation->getHeight() . "p.m3u8";
41
            }
42
        }
43
44
        return implode(PHP_EOL, $content);
45
    }
46
}