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

ExportHLSPlaylist::savePlayList()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 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
}