Passed
Push — master ( 137960...4d87d9 )
by Sys
11:11
created

Encoder::toJson()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 6
rs 10
cc 2
nc 2
nop 3
1
<?php
2
3
namespace TgScraper\Common;
4
5
use Symfony\Component\Yaml\Yaml;
6
7
class Encoder
8
{
9
    /**
10
     * @param mixed $data
11
     * @param int $options
12
     * @param bool $readable
13
     * @return string
14
     */
15
    public static function toJson(mixed $data, int $options = 0, bool $readable = false): string
16
    {
17
        if ($readable) {
18
            $options |= JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE;
19
        }
20
        return json_encode($data, $options);
21
    }
22
23
    /**
24
     * @param mixed $data
25
     * @param int $inline
26
     * @param int $indent
27
     * @param int $flags
28
     * @return string
29
     */
30
    public static function toYaml(mixed $data, int $inline = 12, int $indent = 4, int $flags = 0): string
31
    {
32
        return Yaml::dump($data, $inline, $indent, $flags);
33
    }
34
}