Passed
Push — master ( 220de3...37ea2e )
by Amin
13:48
created

HLSPlaylist::contents()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 2
dl 0
loc 9
rs 10
c 0
b 0
f 0
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 HLSPlaylist
16
{
17
    /**
18
     * @param string $filename
19
     * @param array $reps
20
     * @param string $manifests
21
     */
22
    public static function save(string $filename, array $reps, string $manifests): void
23
    {
24
        file_put_contents($filename, static::contents($reps, $manifests));
25
    }
26
27
    /**
28
     * @param array $reps
29
     * @param string $manifests
30
     * @return string
31
     */
32
    private static function contents(array $reps, string $manifests): string
33
    {
34
        $content = ["#EXTM3U", "#EXT-X-VERSION:3"];
35
        foreach ($reps as $rep) {
36
            $content[] = "#EXT-X-STREAM-INF:BANDWIDTH=" . $rep->getKiloBitrate() * 1024 . ",RESOLUTION=" . $rep->getResize();
37
            $content[] = $manifests . "_" . $rep->getHeight() . "p.m3u8";
38
        }
39
40
        return implode(PHP_EOL, $content);
41
    }
42
}